4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Hyunjun Ko <zzoon.ko@samsung.com>, Haejeong Kim <backto.kim@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
24 #include <sys/types.h>
27 #include <media-util-err.h>
28 #include "media-svc-media.h"
29 #include "media-svc-media-folder.h"
30 #include "media-svc-debug.h"
31 #include "media-svc-util.h"
32 #include "media-svc-db-utils.h"
33 #include "media-svc-noti.h"
35 #define MEDIA_SVC_MAX_COMMIT_SIZE 200
38 char thumbnail_path[MEDIA_SVC_PATHNAME_SIZE];
39 } media_svc_thumbnailpath_s;
41 static __thread GList *g_media_svc_item_validity_query_list = NULL;
42 static __thread GList *g_media_svc_insert_item_query_list = NULL;
43 __thread GList *g_media_svc_move_item_query_list = NULL;
44 static __thread GList *g_media_svc_update_item_query_list = NULL;
45 static __thread GList *g_media_svc_update_list = NULL;
46 static __thread int g_media_svc_update_list_count = 0;
48 static int __media_svc_count_invalid_records_with_thumbnail(sqlite3 *handle, const char *storage_id, media_svc_storage_type_e storage_type, int *count);
49 static int __media_svc_get_invalid_records_with_thumbnail(sqlite3 *handle, const char *storage_id, media_svc_storage_type_e storage_type, int count, media_svc_thumbnailpath_s *thumb_path);
50 static int __media_svc_count_invalid_folder_records_with_thumbnail(sqlite3 *handle, const char *storage_id, const char *folder_path, const char *folder_uuid, bool is_recursive, int *count);
51 static int __media_svc_get_invalid_folder_records_with_thumbnail(sqlite3 *handle, const char *storage_id, const char *folder_path, const char *folder_uuid, bool is_recursive, int count, media_svc_thumbnailpath_s *thumb_path);
53 static int __media_svc_count_invalid_records_with_thumbnail(sqlite3 *handle, const char *storage_id, media_svc_storage_type_e storage_type, int *count)
55 int ret = MS_MEDIA_ERR_NONE;
56 sqlite3_stmt *sql_stmt = NULL;
57 char *sql = sqlite3_mprintf("SELECT count(*) FROM '%s' WHERE validity=0 AND storage_type=%d AND thumbnail_path IS NOT NULL",
58 storage_id, storage_type);
60 ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
62 if (ret != MS_MEDIA_ERR_NONE) {
63 media_svc_error("error when __media_svc_count_invalid_records_with_thumbnail. err = [%d]", ret);
67 *count = sqlite3_column_int(sql_stmt, 0);
69 SQLITE3_FINALIZE(sql_stmt);
71 return MS_MEDIA_ERR_NONE;
75 static int __media_svc_get_invalid_records_with_thumbnail(sqlite3 *handle, const char *storage_id, media_svc_storage_type_e storage_type,
76 int count, media_svc_thumbnailpath_s * thumb_path)
78 int ret = MS_MEDIA_ERR_NONE;
79 sqlite3_stmt *sql_stmt = NULL;
82 char *sql = sqlite3_mprintf("SELECT thumbnail_path from (select thumbnail_path, validity from '%s' WHERE storage_type=%d AND thumbnail_path IS NOT NULL GROUP BY thumbnail_path HAVING count() = 1) WHERE validity=0",
83 MEDIA_SVC_DB_TABLE_MEDIA, storage_type);
85 media_svc_debug("[SQL query] : %s", sql);
87 ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
88 if (ret != MS_MEDIA_ERR_NONE) {
89 media_svc_error("error when __media_svc_get_invalid_records_with_thumbnail. err = [%d]", ret);
93 while (sqlite3_step(sql_stmt) == SQLITE_ROW) {
94 _strncpy_safe(thumb_path[idx].thumbnail_path, (const char *)sqlite3_column_text(sql_stmt, 0), sizeof(thumb_path[idx]));
95 /*media_svc_debug("thumb_path[%d]=[%s]", idx, thumb_path[idx].thumbnail_path); */
99 SQLITE3_FINALIZE(sql_stmt);
101 return MS_MEDIA_ERR_NONE;
104 static int __media_svc_count_invalid_folder_records_with_thumbnail(sqlite3 *handle, const char *storage_id, const char *folder_path, const char *folder_uuid, bool is_recursive, int *count)
106 int ret = MS_MEDIA_ERR_NONE;
107 sqlite3_stmt *sql_stmt = NULL;
111 sql = sqlite3_mprintf("SELECT count(*) FROM '%s' WHERE validity=0 AND path LIKE '%q/%%' AND thumbnail_path IS NOT NULL", storage_id, folder_path);
113 sql = sqlite3_mprintf("SELECT count(*) FROM '%s' WHERE validity=0 AND folder_uuid = '%q' AND thumbnail_path IS NOT NULL", storage_id, folder_uuid);
115 ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
117 if (ret != MS_MEDIA_ERR_NONE) {
118 media_svc_error("error when __media_svc_count_invalid_folder_records_with_thumbnail. err = [%d]", ret);
122 *count = sqlite3_column_int(sql_stmt, 0);
124 SQLITE3_FINALIZE(sql_stmt);
126 return MS_MEDIA_ERR_NONE;
130 static int __media_svc_get_invalid_folder_records_with_thumbnail(sqlite3 *handle, const char *storage_id, const char *folder_path, const char *folder_uuid, bool is_recursive,
131 int count, media_svc_thumbnailpath_s * thumb_path)
133 int ret = MS_MEDIA_ERR_NONE;
134 sqlite3_stmt *sql_stmt = NULL;
139 sql = sqlite3_mprintf("SELECT thumbnail_path from (select thumbnail_path, validity from '%s' WHERE path LIKE '%q/%%' AND thumbnail_path IS NOT NULL GROUP BY thumbnail_path HAVING count() = 1) WHERE validity=0", storage_id, folder_path);
141 sql = sqlite3_mprintf("SELECT thumbnail_path from (select thumbnail_path, validity from '%s' WHERE folder_uuid = '%q' AND thumbnail_path IS NOT NULL GROUP BY thumbnail_path HAVING count() = 1) WHERE validity=0", storage_id, folder_uuid);
143 media_svc_debug("[SQL query] : %s", sql);
145 ret = _media_svc_sql_prepare_to_step_simple(handle, sql, &sql_stmt);
146 if (ret != MS_MEDIA_ERR_NONE) {
147 media_svc_error("error when __media_svc_get_invalid_folder_records_with_thumbnail. err = [%d]", ret);
151 while (sqlite3_step(sql_stmt) == SQLITE_ROW) {
152 _strncpy_safe(thumb_path[idx].thumbnail_path, (const char *)sqlite3_column_text(sql_stmt, 0), sizeof(thumb_path[idx]));
156 SQLITE3_FINALIZE(sql_stmt);
158 return MS_MEDIA_ERR_NONE;
161 int _media_svc_count_record_with_path(sqlite3 *handle, const char *storage_id, const char *path, int *count)
163 int ret = MS_MEDIA_ERR_NONE;
164 sqlite3_stmt *sql_stmt = NULL;
166 char *sql = sqlite3_mprintf("SELECT count(*) FROM '%s' WHERE path='%q'", storage_id, path);
168 ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
170 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
172 *count = sqlite3_column_int(sql_stmt, 0);
174 SQLITE3_FINALIZE(sql_stmt);
176 return MS_MEDIA_ERR_NONE;
179 char *_media_svc_get_thumb_default_path(uid_t uid)
182 char *result_passwd = NULL;
183 struct group *grpinfo = NULL;
184 if (uid == getuid()) {
185 grpinfo = getgrnam("users");
186 if (grpinfo == NULL) {
187 media_svc_error("getgrnam(users) returns NULL !");
190 len = strlen(MEDIA_SVC_THUMB_DEFAULT_PATH);
192 result_passwd = strndup(MEDIA_SVC_THUMB_DEFAULT_PATH, len);
194 char passwd_str[MEDIA_SVC_PATHNAME_SIZE] = {0, };
195 struct passwd *userinfo = getpwuid(uid);
196 if (userinfo == NULL) {
197 media_svc_error("getpwuid(%d) returns NULL !", uid);
200 grpinfo = getgrnam("users");
201 if (grpinfo == NULL) {
202 media_svc_error("getgrnam(users) returns NULL !");
205 /* Compare git_t type and not group name */
206 if (grpinfo->gr_gid != userinfo->pw_gid) {
207 media_svc_error("UID [%d] does not belong to 'users' group!", uid);
210 len = snprintf(passwd_str, sizeof(passwd_str), "%s/share/media/.thumb/thumb_default.png", userinfo->pw_dir);
212 result_passwd = strndup(passwd_str, len);
215 return result_passwd;
218 int _media_svc_insert_item_with_data(sqlite3 *handle, const char *storage_id, media_svc_content_info_s *content_info, int is_burst, bool stack_query, uid_t uid)
220 int ret = MS_MEDIA_ERR_NONE;
221 char *burst_id = NULL;
223 const char *db_fields = "media_uuid, path, file_name, media_type, mime_type, size, added_time, modified_time, folder_uuid, thumbnail_path, \
224 title, album_id, album, artist, album_artist, genre, composer, year, recorded_date, copyright, track_num, description, category, keyword, location_tag, \
225 content_name, age_rating, author, provider, last_played_time, played_count, favourite, bitrate, bitpersample, samplerate, channel, duration, \
226 longitude, latitude, altitude, exposure_time, fnumber, iso, model, width, height, datetaken, orientation, rating, is_drm, storage_type, burst_id, timeline, weather, sync_status, \
227 file_name_pinyin, title_pinyin, album_pinyin, artist_pinyin, album_artist_pinyin, genre_pinyin, composer_pinyin, copyright_pinyin, description_pinyin, storage_uuid, is_360";
229 const char *db_fields_basic = "media_uuid, path, file_name, media_type, mime_type, size, added_time, modified_time, folder_uuid, thumbnail_path, \
230 album_id, last_played_time, played_count, favourite, is_drm, storage_type, burst_id, timeline, sync_status, file_name_pinyin, storage_uuid, is_360";
232 /* This sql is due to sqlite3_mprintf's wrong operation when using floating point in the text format */
233 /* This code will be removed when sqlite3_mprintf works clearly */
234 char *test_sql = sqlite3_mprintf("%f, %f, %f", content_info->media_meta.longitude, content_info->media_meta.latitude, content_info->media_meta.altitude);
235 sqlite3_free(test_sql);
238 int burst_id_int = 0;
239 ret = _media_svc_get_burst_id(handle, storage_id, &burst_id_int);
240 if (ret != MS_MEDIA_ERR_NONE)
243 if (burst_id_int > 0) {
244 media_svc_debug("Burst id : %d", burst_id_int);
245 burst_id = sqlite3_mprintf("%d", burst_id_int);
248 /* Get thumbnail for burst shot */
249 char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, };
253 ret = _media_svc_request_thumbnail_with_origin_size(content_info->path, thumb_path, sizeof(thumb_path), &width, &height, uid);
254 if (ret == MS_MEDIA_ERR_NONE) {
255 ret = __media_svc_malloc_and_strncpy(&(content_info->thumbnail_path), thumb_path);
256 if (ret != MS_MEDIA_ERR_NONE)
257 content_info->thumbnail_path = NULL;
260 if (content_info->media_meta.width <= 0)
261 content_info->media_meta.width = width;
263 if (content_info->media_meta.height <= 0)
264 content_info->media_meta.height = height;
267 /*Update Pinyin If Support Pinyin*/
268 if (_media_svc_check_pinyin_support()) {
269 if (STRING_VALID(content_info->file_name))
270 _media_svc_get_pinyin_str(content_info->file_name, &content_info->file_name_pinyin);
271 if (STRING_VALID(content_info->media_meta.title))
272 _media_svc_get_pinyin_str(content_info->media_meta.title, &content_info->media_meta.title_pinyin);
273 if (STRING_VALID(content_info->media_meta.album))
274 _media_svc_get_pinyin_str(content_info->media_meta.album, &content_info->media_meta.album_pinyin);
275 if (STRING_VALID(content_info->media_meta.artist))
276 _media_svc_get_pinyin_str(content_info->media_meta.artist, &content_info->media_meta.artist_pinyin);
277 if (STRING_VALID(content_info->media_meta.album_artist))
278 _media_svc_get_pinyin_str(content_info->media_meta.album_artist, &content_info->media_meta.album_artist_pinyin);
279 if (STRING_VALID(content_info->media_meta.genre))
280 _media_svc_get_pinyin_str(content_info->media_meta.genre, &content_info->media_meta.genre_pinyin);
281 if (STRING_VALID(content_info->media_meta.composer))
282 _media_svc_get_pinyin_str(content_info->media_meta.composer, &content_info->media_meta.composer_pinyin);
283 if (STRING_VALID(content_info->media_meta.copyright))
284 _media_svc_get_pinyin_str(content_info->media_meta.copyright, &content_info->media_meta.copyright_pinyin);
285 if (STRING_VALID(content_info->media_meta.description))
286 _media_svc_get_pinyin_str(content_info->media_meta.description, &content_info->media_meta.description_pinyin);
289 char *sql = sqlite3_mprintf("INSERT INTO '%s' (%s) VALUES (%Q, %Q, %Q, %d, %Q, %lld, %d, %d, %Q, \
290 %Q, %Q, %d, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %d, %d, %d, \
291 %d, %d, %d, %d, %d, %.6f, %.6f, %.6f, %Q, %.6f, %d, %Q, %d, %d, %Q, %d, \
292 %d, %d, %d, %Q, %d, %Q, %d, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %d);",
293 content_info->storage_uuid, db_fields,
294 content_info->media_uuid,
296 content_info->file_name,
297 content_info->media_type,
298 content_info->mime_type,
300 content_info->added_time,
301 content_info->modified_time,
302 content_info->folder_uuid, /* 1st line */
303 content_info->thumbnail_path,
304 content_info->media_meta.title,
305 content_info->album_id,
306 content_info->media_meta.album,
307 content_info->media_meta.artist,
308 content_info->media_meta.album_artist,
309 content_info->media_meta.genre,
310 content_info->media_meta.composer,
311 content_info->media_meta.year,
312 content_info->media_meta.recorded_date,
313 content_info->media_meta.copyright,
314 content_info->media_meta.track_num,
315 content_info->media_meta.description,
316 content_info->media_meta.category,
317 content_info->media_meta.keyword,
318 content_info->media_meta.location_tag,
319 content_info->media_meta.content_name,
320 content_info->media_meta.age_rating,
321 content_info->media_meta.author,
322 content_info->media_meta.provider,
323 content_info->last_played_time,
324 content_info->played_count,
325 content_info->favourate, /* 2nd line */
326 content_info->media_meta.bitrate,
327 content_info->media_meta.bitpersample,
328 content_info->media_meta.samplerate,
329 content_info->media_meta.channel,
330 content_info->media_meta.duration,
331 content_info->media_meta.longitude,
332 content_info->media_meta.latitude,
333 content_info->media_meta.altitude,
334 content_info->media_meta.exposure_time,
335 content_info->media_meta.fnumber,
336 content_info->media_meta.iso,
337 content_info->media_meta.model,
338 content_info->media_meta.width,
339 content_info->media_meta.height,
340 content_info->media_meta.datetaken,
341 content_info->media_meta.orientation, /* 3rd line */
342 content_info->media_meta.rating,
343 content_info->is_drm,
344 content_info->storage_type,
346 content_info->timeline,
347 content_info->media_meta.weather,
348 content_info->sync_status,
349 content_info->file_name_pinyin,
350 content_info->media_meta.title_pinyin,
351 content_info->media_meta.album_pinyin,
352 content_info->media_meta.artist_pinyin,
353 content_info->media_meta.album_artist_pinyin,
354 content_info->media_meta.genre_pinyin,
355 content_info->media_meta.composer_pinyin,
356 content_info->media_meta.copyright_pinyin,
357 content_info->media_meta.description_pinyin,
358 content_info->storage_uuid,
359 content_info->media_meta.is_360 /* 4th line */
362 /* Check query length */
363 if (sql != NULL && strlen(sql) >= SQLITE3_QUERY_MAX_LEN) {
364 media_svc_debug("Query length is over %d byte.. So, remake query using only basic information..", SQLITE3_QUERY_MAX_LEN);
365 SQLITE3_SAFE_FREE(sql);
367 sql = sqlite3_mprintf("INSERT INTO '%s' (%s) VALUES (%Q, %Q, %Q, %d, %Q, %lld, %d, %d, %Q, %Q, %d, %d, %d, %d, %d, %d, %Q, %d, %d, %Q, %Q, %d);",
368 content_info->storage_uuid, db_fields_basic,
369 content_info->media_uuid,
371 content_info->file_name,
372 content_info->media_type,
373 content_info->mime_type,
375 content_info->added_time,
376 content_info->modified_time,
377 content_info->folder_uuid,
378 content_info->thumbnail_path,
379 content_info->album_id,
380 content_info->last_played_time,
381 content_info->played_count,
382 content_info->favourate,
383 content_info->is_drm,
384 content_info->storage_type,
386 content_info->timeline,
387 content_info->sync_status,
388 content_info->file_name_pinyin,
389 content_info->storage_uuid,
390 content_info->media_meta.is_360 /* 1st line */
395 sqlite3_free(burst_id);
400 ret = _media_svc_sql_query(sql, uid);
402 if (ret != MS_MEDIA_ERR_NONE) {
403 media_svc_error("failed to insert item");
407 media_svc_debug("query : %s", sql);
408 _media_svc_sql_query_add(&g_media_svc_insert_item_query_list, &sql);
411 return MS_MEDIA_ERR_NONE;
414 int _media_svc_update_meta_with_data(media_svc_content_info_s *content_info)
416 int ret = MS_MEDIA_ERR_NONE;
418 /* This sql is due to sqlite3_mprintf's wrong operation when using floating point in the text format */
419 /* This code will be removed when sqlite3_mprintf works clearly */
420 char *test_sql = sqlite3_mprintf("%f, %f, %f", content_info->media_meta.longitude, content_info->media_meta.latitude, content_info->media_meta.altitude);
421 sqlite3_free(test_sql);
423 /*Update Pinyin If Support Pinyin*/
424 if (_media_svc_check_pinyin_support()) {
425 if (STRING_VALID(content_info->file_name))
426 _media_svc_get_pinyin_str(content_info->file_name, &content_info->file_name_pinyin);
427 if (STRING_VALID(content_info->media_meta.title))
428 _media_svc_get_pinyin_str(content_info->media_meta.title, &content_info->media_meta.title_pinyin);
429 if (STRING_VALID(content_info->media_meta.album))
430 _media_svc_get_pinyin_str(content_info->media_meta.album, &content_info->media_meta.album_pinyin);
431 if (STRING_VALID(content_info->media_meta.artist))
432 _media_svc_get_pinyin_str(content_info->media_meta.artist, &content_info->media_meta.artist_pinyin);
433 if (STRING_VALID(content_info->media_meta.album_artist))
434 _media_svc_get_pinyin_str(content_info->media_meta.album_artist, &content_info->media_meta.album_artist_pinyin);
435 if (STRING_VALID(content_info->media_meta.genre))
436 _media_svc_get_pinyin_str(content_info->media_meta.genre, &content_info->media_meta.genre_pinyin);
437 if (STRING_VALID(content_info->media_meta.composer))
438 _media_svc_get_pinyin_str(content_info->media_meta.composer, &content_info->media_meta.composer_pinyin);
439 if (STRING_VALID(content_info->media_meta.copyright))
440 _media_svc_get_pinyin_str(content_info->media_meta.copyright, &content_info->media_meta.copyright_pinyin);
441 if (STRING_VALID(content_info->media_meta.description))
442 _media_svc_get_pinyin_str(content_info->media_meta.description, &content_info->media_meta.description_pinyin);
445 char *sql = sqlite3_mprintf("UPDATE %s SET title=%Q, album=%Q, artist=%Q, album_artist=%Q, genre=%Q, composer=%Q, copyright=%Q, description=%Q, \
446 file_name_pinyin=%Q, title_pinyin=%Q, album_pinyin=%Q, artist_pinyin=%Q, album_artist_pinyin=%Q, genre_pinyin=%Q, composer_pinyin=%Q, copyright_pinyin=%Q, description_pinyin=%Q \
448 MEDIA_SVC_DB_TABLE_MEDIA,
449 content_info->media_meta.title,
450 content_info->media_meta.album,
451 content_info->media_meta.artist,
452 content_info->media_meta.album_artist,
453 content_info->media_meta.genre,
454 content_info->media_meta.composer,
455 content_info->media_meta.copyright,
456 content_info->media_meta.description,
457 content_info->file_name_pinyin,
458 content_info->media_meta.title_pinyin,
459 content_info->media_meta.album_pinyin,
460 content_info->media_meta.artist_pinyin,
461 content_info->media_meta.album_artist_pinyin,
462 content_info->media_meta.genre_pinyin,
463 content_info->media_meta.composer_pinyin,
464 content_info->media_meta.copyright_pinyin,
465 content_info->media_meta.description_pinyin,
470 media_svc_debug("query : %s", sql);
471 _media_svc_sql_query_add(&g_media_svc_update_item_query_list, &sql);
473 media_svc_error("sqlite3_mprintf failed");
474 ret = MS_MEDIA_ERR_OUT_OF_MEMORY;
480 int _media_svc_update_item_with_data(const char *storage_id, media_svc_content_info_s *content_info, uid_t uid)
482 int ret = MS_MEDIA_ERR_NONE;
484 /* This sql is due to sqlite3_mprintf's wrong operation when using floating point in the text format */
485 /* This code will be removed when sqlite3_mprintf works clearly */
486 char *test_sql = sqlite3_mprintf("%f, %f, %f", content_info->media_meta.longitude, content_info->media_meta.latitude, content_info->media_meta.altitude);
487 sqlite3_free(test_sql);
489 /*Update Pinyin If Support Pinyin*/
490 if (_media_svc_check_pinyin_support()) {
491 if (STRING_VALID(content_info->file_name))
492 _media_svc_get_pinyin_str(content_info->file_name, &content_info->file_name_pinyin);
493 if (STRING_VALID(content_info->media_meta.title))
494 _media_svc_get_pinyin_str(content_info->media_meta.title, &content_info->media_meta.title_pinyin);
495 if (STRING_VALID(content_info->media_meta.album))
496 _media_svc_get_pinyin_str(content_info->media_meta.album, &content_info->media_meta.album_pinyin);
497 if (STRING_VALID(content_info->media_meta.artist))
498 _media_svc_get_pinyin_str(content_info->media_meta.artist, &content_info->media_meta.artist_pinyin);
499 if (STRING_VALID(content_info->media_meta.album_artist))
500 _media_svc_get_pinyin_str(content_info->media_meta.album_artist, &content_info->media_meta.album_artist_pinyin);
501 if (STRING_VALID(content_info->media_meta.genre))
502 _media_svc_get_pinyin_str(content_info->media_meta.genre, &content_info->media_meta.genre_pinyin);
503 if (STRING_VALID(content_info->media_meta.composer))
504 _media_svc_get_pinyin_str(content_info->media_meta.composer, &content_info->media_meta.composer_pinyin);
505 if (STRING_VALID(content_info->media_meta.copyright))
506 _media_svc_get_pinyin_str(content_info->media_meta.copyright, &content_info->media_meta.copyright_pinyin);
507 if (STRING_VALID(content_info->media_meta.description))
508 _media_svc_get_pinyin_str(content_info->media_meta.description, &content_info->media_meta.description_pinyin);
511 char *sql = sqlite3_mprintf("UPDATE '%s' SET size=%lld, modified_time=%d, thumbnail_path=%Q, title=%Q, album_id=%d, album=%Q, artist=%Q, album_artist=%Q, genre=%Q, \
512 composer=%Q, year=%Q, recorded_date=%Q, copyright=%Q, track_num=%Q, description=%Q, bitrate=%d, bitpersample=%d, samplerate=%d, channel=%d, duration=%d, \
513 longitude=%f, latitude=%f, altitude=%f, exposure_time=%Q, fnumber=%f, iso=%d, model=%Q, width=%d, height=%d, datetaken=%Q, orientation=%d WHERE path=%Q;",
516 content_info->modified_time,
517 content_info->thumbnail_path,
518 content_info->media_meta.title,
519 content_info->album_id,
520 content_info->media_meta.album,
521 content_info->media_meta.artist,
522 content_info->media_meta.album_artist,
523 content_info->media_meta.genre,
524 content_info->media_meta.composer,
525 content_info->media_meta.year,
526 content_info->media_meta.recorded_date,
527 content_info->media_meta.copyright,
528 content_info->media_meta.track_num,
529 content_info->media_meta.description,
530 content_info->media_meta.bitrate,
531 content_info->media_meta.bitpersample,
532 content_info->media_meta.samplerate,
533 content_info->media_meta.channel,
534 content_info->media_meta.duration,
535 content_info->media_meta.longitude,
536 content_info->media_meta.latitude,
537 content_info->media_meta.altitude,
538 content_info->media_meta.exposure_time,
539 content_info->media_meta.fnumber,
540 content_info->media_meta.iso,
541 content_info->media_meta.model,
542 content_info->media_meta.width,
543 content_info->media_meta.height,
544 content_info->media_meta.datetaken,
545 content_info->media_meta.orientation,
549 ret = _media_svc_sql_query(sql, uid);
554 int _media_svc_get_thumbnail_path_by_path(sqlite3 *handle, const char *storage_id, const char *path, char *thumbnail_path)
556 int ret = MS_MEDIA_ERR_NONE;
557 sqlite3_stmt *sql_stmt = NULL;
559 char *sql = sqlite3_mprintf("SELECT thumbnail_path FROM '%s' WHERE path='%q'", storage_id, path);
561 ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
563 if (ret != MS_MEDIA_ERR_NONE) {
564 if (ret == MS_MEDIA_ERR_DB_NO_RECORD)
565 media_svc_debug("there is no thumbnail.");
567 media_svc_error("error when _media_svc_get_thumbnail_path_by_path. err = [%d]", ret);
572 _strncpy_safe(thumbnail_path, (const char *)sqlite3_column_text(sql_stmt, 0), MEDIA_SVC_PATHNAME_SIZE);
574 SQLITE3_FINALIZE(sql_stmt);
576 return MS_MEDIA_ERR_NONE;
579 int _media_svc_get_media_type_by_path(sqlite3 *handle, const char *storage_id, const char *path, int *media_type)
581 int ret = MS_MEDIA_ERR_NONE;
582 sqlite3_stmt *sql_stmt = NULL;
584 char *sql = sqlite3_mprintf("SELECT media_type FROM '%s' WHERE path='%q'", storage_id, path);
586 ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
588 if (ret != MS_MEDIA_ERR_NONE) {
589 media_svc_error("error when _media_svc_get_media_type_by_path. err = [%d]", ret);
593 *media_type = sqlite3_column_int(sql_stmt, 0);
595 SQLITE3_FINALIZE(sql_stmt);
597 return MS_MEDIA_ERR_NONE;
600 int _media_svc_delete_item_by_path(const char *storage_id, const char *path, bool stack_query, uid_t uid)
602 int ret = MS_MEDIA_ERR_NONE;
603 char *sql = sqlite3_mprintf("DELETE FROM '%s' WHERE path='%q';", storage_id, path);
606 ret = _media_svc_sql_query(sql, uid);
608 if (ret != MS_MEDIA_ERR_NONE) {
609 media_svc_error("failed to delete item");
613 media_svc_debug("query : %s", sql);
614 _media_svc_sql_query_add(&g_media_svc_insert_item_query_list, &sql);
620 int _media_svc_truncate_table(const char *storage_id, media_svc_storage_type_e storage_type, uid_t uid)
622 int ret = MS_MEDIA_ERR_NONE;
624 char *sql = sqlite3_mprintf("DELETE FROM '%s' where storage_type=%d;", storage_id, storage_type);
626 ret = _media_svc_sql_query(sql, uid);
632 int _media_svc_delete_invalid_items(sqlite3 *handle, const char *storage_id, media_svc_storage_type_e storage_type, uid_t uid)
635 media_svc_thumbnailpath_s *thumbpath_record = NULL;
636 int invalid_count = 0;
637 int ret = MS_MEDIA_ERR_NONE;
639 ret = __media_svc_count_invalid_records_with_thumbnail(handle, storage_id, storage_type, &invalid_count);
640 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
642 media_svc_debug("invalid count: %d", invalid_count);
644 if (invalid_count > 0) {
645 thumbpath_record = (media_svc_thumbnailpath_s *)calloc(invalid_count, sizeof(media_svc_thumbnailpath_s));
646 if (thumbpath_record == NULL) {
647 media_svc_error("fail to memory allocation");
648 return MS_MEDIA_ERR_OUT_OF_MEMORY;
651 ret = __media_svc_get_invalid_records_with_thumbnail(handle, storage_id, storage_type, invalid_count, thumbpath_record);
652 if (ret != MS_MEDIA_ERR_NONE) {
653 media_svc_error("error when get thumbnail record");
654 SAFE_FREE(thumbpath_record);
658 media_svc_debug("There is no item with thumbnail");
661 char *sql = sqlite3_mprintf("DELETE FROM '%s' WHERE validity = 0;", storage_id);
663 ret = _media_svc_sql_query(sql, uid);
665 if (ret != MS_MEDIA_ERR_NONE) {
666 SAFE_FREE(thumbpath_record);
670 /*Delete thumbnails*/
671 char *default_thumbnail_path = _media_svc_get_thumb_default_path(uid);
672 for (idx = 0; idx < invalid_count; idx++) {
673 if ((strlen(thumbpath_record[idx].thumbnail_path) > 0) && (STRING_VALID(default_thumbnail_path)) && (strncmp(thumbpath_record[idx].thumbnail_path, default_thumbnail_path, strlen(default_thumbnail_path)) != 0)) {
674 ret = _media_svc_remove_file(thumbpath_record[idx].thumbnail_path);
675 if (ret != MS_MEDIA_ERR_NONE)
676 media_svc_error("fail to remove thumbnail file.");
680 SAFE_FREE(thumbpath_record);
681 SAFE_FREE(default_thumbnail_path);
683 return MS_MEDIA_ERR_NONE;
686 int _media_svc_delete_invalid_folder_items(sqlite3 *handle, const char *storage_id, const char *folder_path, bool is_recursive, uid_t uid)
689 media_svc_thumbnailpath_s *thumbpath_record = NULL;
690 int invalid_count = 0;
691 int ret = MS_MEDIA_ERR_NONE;
692 char folder_uuid[MEDIA_SVC_UUID_SIZE+1] = {0,};
695 /*get folder uuid from DB*/
696 ret = _media_svc_get_folder_id_by_foldername(handle, storage_id, folder_path, folder_uuid, uid);
697 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
699 ret = __media_svc_count_invalid_folder_records_with_thumbnail(handle, storage_id, folder_path, folder_uuid, is_recursive, &invalid_count);
700 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
702 media_svc_debug("invalid count: %d", invalid_count);
704 if (invalid_count > 0) {
705 thumbpath_record = (media_svc_thumbnailpath_s *)calloc(invalid_count, sizeof(media_svc_thumbnailpath_s));
706 if (thumbpath_record == NULL) {
707 media_svc_error("fail to memory allocation");
708 return MS_MEDIA_ERR_OUT_OF_MEMORY;
711 ret = __media_svc_get_invalid_folder_records_with_thumbnail(handle, storage_id, folder_path, folder_uuid, is_recursive, invalid_count, thumbpath_record);
712 if (ret != MS_MEDIA_ERR_NONE) {
713 media_svc_error("error when get thumbnail record");
714 SAFE_FREE(thumbpath_record);
718 media_svc_debug("There is no item with thumbnail");
722 sql = sqlite3_mprintf("DELETE FROM '%s' WHERE validity = 0 AND path LIKE '%q/%%';", storage_id, folder_path);
724 sql = sqlite3_mprintf("DELETE FROM '%s' WHERE validity = 0 AND folder_uuid='%q';", storage_id, folder_uuid);
726 ret = _media_svc_sql_query(sql, uid);
728 if (ret != MS_MEDIA_ERR_NONE) {
729 SAFE_FREE(thumbpath_record);
733 /*Delete thumbnails*/
734 if (thumbpath_record != NULL) {
735 char *default_thumbnail_path = _media_svc_get_thumb_default_path(uid);
736 if (STRING_VALID(default_thumbnail_path)) {
737 for (idx = 0; idx < invalid_count; idx++) {
738 if ((strlen(thumbpath_record[idx].thumbnail_path) > 0) && (strncmp(thumbpath_record[idx].thumbnail_path, default_thumbnail_path, strlen(default_thumbnail_path)) != 0)) {
739 ret = _media_svc_remove_file(thumbpath_record[idx].thumbnail_path);
740 if (ret != MS_MEDIA_ERR_NONE)
741 media_svc_error("fail to remove thumbnail file.");
746 SAFE_FREE(thumbpath_record);
747 SAFE_FREE(default_thumbnail_path);
750 return MS_MEDIA_ERR_NONE;
753 int _media_svc_update_item_validity(const char *storage_id, const char *path, int validity, bool stack_query, uid_t uid)
755 int ret = MS_MEDIA_ERR_NONE;
757 char *sql = sqlite3_mprintf("UPDATE '%s' SET validity=%d WHERE path= '%q';", storage_id, validity, path);
760 ret = _media_svc_sql_query(sql, uid);
763 _media_svc_sql_query_add(&g_media_svc_item_validity_query_list, &sql);
769 int _media_svc_update_thumbnail_path(const char *storage_id, const char *path, const char *thumb_path, uid_t uid)
771 int ret = MS_MEDIA_ERR_NONE;
773 char *sql = sqlite3_mprintf("UPDATE '%s' SET thumbnail_path=%Q WHERE path= %Q;", storage_id, thumb_path, path);
775 ret = _media_svc_sql_query(sql, uid);
781 int _media_svc_update_storage_item_validity(const char *storage_id, media_svc_storage_type_e storage_type, int validity, uid_t uid)
783 int ret = MS_MEDIA_ERR_NONE;
785 char *sql = sqlite3_mprintf("UPDATE '%s' SET validity=%d WHERE storage_type=%d;", storage_id, validity, storage_type);
787 ret = _media_svc_sql_query(sql, uid);
793 int _media_svc_update_folder_item_validity(sqlite3 *handle, const char *storage_id, const char *folder_path, int validity, uid_t uid)
795 int ret = MS_MEDIA_ERR_NONE;
797 char folder_uuid[MEDIA_SVC_UUID_SIZE + 1] = {0, };
798 sqlite3_stmt *sql_stmt = NULL;
801 sql = sqlite3_mprintf("SELECT folder_uuid FROM '%s' WHERE path='%q' AND storage_uuid='%q'", MEDIA_SVC_DB_TABLE_FOLDER, folder_path, storage_id);
803 ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
804 if (ret != MS_MEDIA_ERR_NONE) {
805 if (ret == MS_MEDIA_ERR_DB_NO_RECORD)
806 media_svc_debug("folder not exist");
808 media_svc_error("error when get folder_id. err = [%d]", ret);
813 _strncpy_safe(folder_uuid, (const char *)sqlite3_column_text(sql_stmt, 0), MEDIA_SVC_UUID_SIZE + 1);
814 SQLITE3_FINALIZE(sql_stmt);
816 /*Update folder item validity*/
817 sql = sqlite3_mprintf("UPDATE '%s' SET validity=%d WHERE folder_uuid='%q';", storage_id, validity, folder_uuid);
819 ret = _media_svc_sql_query(sql, uid);
825 int _media_svc_update_recursive_folder_item_validity(const char *storage_id, const char *folder_path, int validity, uid_t uid)
827 int ret = MS_MEDIA_ERR_NONE;
829 /*Update folder item validity*/
830 char *sql = sqlite3_mprintf("UPDATE '%s' SET validity=%d WHERE (storage_type = 0 OR storage_type = 1) AND path LIKE '%q/%%';", storage_id, validity, folder_path);
832 ret = _media_svc_sql_query(sql, uid);
838 int _media_svc_update_item_by_path(const char *storage_id, const char *src_path, media_svc_storage_type_e dest_storage, const char *dest_path,
839 const char *file_name, int modified_time, const char *folder_uuid, const char *thumb_path, bool stack_query, uid_t uid)
841 /* update path, filename, modified_time, folder_uuid, thumbnail_path, */
842 /* played_count, last_played_time, last_played_position, favourite, storaget_type*/
844 int ret = MS_MEDIA_ERR_NONE;
847 if (thumb_path != NULL) {
848 sql = sqlite3_mprintf("UPDATE '%s' SET path=%Q, file_name=%Q, modified_time=%d, folder_uuid=%Q, thumbnail_path=%Q, storage_type=%d, \
849 played_count=0, last_played_time=0, last_played_position=0 WHERE path=%Q;",
850 storage_id, dest_path, file_name, modified_time, folder_uuid, thumb_path, dest_storage, src_path);
852 sql = sqlite3_mprintf("UPDATE '%s' SET path=%Q, file_name=%Q, modified_time=%d, folder_uuid=%Q, storage_type=%d, \
853 played_count=0, last_played_time=0, last_played_position=0 WHERE path=%Q;",
854 storage_id, dest_path, file_name, modified_time, folder_uuid, dest_storage, src_path);
858 ret = _media_svc_sql_query(sql, uid);
861 _media_svc_sql_query_add(&g_media_svc_move_item_query_list, &sql);
867 int _media_svc_list_query_do(media_svc_query_type_e query_type, uid_t uid)
869 int ret = MS_MEDIA_ERR_NONE;
871 ret = _media_svc_sql_begin_trans(uid);
872 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
874 if (query_type == MEDIA_SVC_QUERY_SET_ITEM_VALIDITY)
875 ret = _media_svc_sql_query_list(&g_media_svc_item_validity_query_list, uid);
876 else if (query_type == MEDIA_SVC_QUERY_MOVE_ITEM)
877 ret = _media_svc_sql_query_list(&g_media_svc_move_item_query_list, uid);
878 else if (query_type == MEDIA_SVC_QUERY_INSERT_ITEM)
879 ret = _media_svc_sql_query_list(&g_media_svc_insert_item_query_list, uid);
880 else if (query_type == MEDIA_SVC_QUERY_UPDATE_ITEM)
881 ret = _media_svc_sql_query_list(&g_media_svc_update_item_query_list, uid);
882 else if (query_type == MEDIA_SVC_QUERY_INSERT_FOLDER)
883 ret = _media_svc_sql_query_list(_media_svc_get_folder_list_ptr(), uid);
884 else if (query_type == MEDIA_SVC_QUERY_UPDATE_COMMON)
885 ret = _media_svc_sql_query_list(&g_media_svc_update_list, uid);
887 ret = MS_MEDIA_ERR_INVALID_PARAMETER;
889 if (ret != MS_MEDIA_ERR_NONE) {
890 media_svc_error("_media_svc_list_query_do failed. start rollback");
891 _media_svc_sql_rollback_trans(uid);
895 ret = _media_svc_sql_end_trans(uid);
896 if (ret != MS_MEDIA_ERR_NONE) {
897 media_svc_error("mb_svc_sqlite3_commit_trans failed.. Now start to rollback");
898 _media_svc_sql_rollback_trans(uid);
902 return MS_MEDIA_ERR_NONE;
905 int _media_svc_append_query_list(const char *query, uid_t uid)
907 int ret = MS_MEDIA_ERR_NONE;
909 g_media_svc_update_list = g_list_append(g_media_svc_update_list, (gpointer)query);
911 g_media_svc_update_list_count++;
913 if (g_media_svc_update_list_count >= MEDIA_SVC_MAX_COMMIT_SIZE) {
914 ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_UPDATE_COMMON, uid);
915 g_media_svc_update_list_count = 0;
921 int _media_svc_get_burst_id(sqlite3 *handle, const char *storage_id, int *id)
923 int ret = MS_MEDIA_ERR_NONE;
925 sqlite3_stmt *sql_stmt = NULL;
926 char *sql = sqlite3_mprintf("SELECT max(CAST(burst_id AS INTEGER)) FROM '%s'", storage_id);
928 ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
930 if (ret != MS_MEDIA_ERR_NONE) {
931 media_svc_error("error when _media_svc_get_burst_id. err = [%d]", ret);
935 cur_id = sqlite3_column_int(sql_stmt, 0);
937 SQLITE3_FINALIZE(sql_stmt);
939 return MS_MEDIA_ERR_NONE;
942 int _media_svc_get_noti_info(sqlite3 *handle, const char *storage_id, const char *path, int update_item, media_svc_noti_item **item)
944 int ret = MS_MEDIA_ERR_NONE;
945 sqlite3_stmt *sql_stmt = NULL;
947 int is_root_dir = FALSE;
950 media_svc_error("invalid parameter");
951 return MS_MEDIA_ERR_INVALID_PARAMETER;
954 if (update_item == MS_MEDIA_ITEM_FILE)
955 sql = sqlite3_mprintf("SELECT media_uuid, media_type, mime_type FROM '%s' WHERE path=%Q", storage_id, path);
956 else if (update_item == MS_MEDIA_ITEM_DIRECTORY)
957 sql = sqlite3_mprintf("SELECT folder_uuid FROM '%s' WHERE path=%Q AND storage_uuid='%s'", MEDIA_SVC_DB_TABLE_FOLDER, path, storage_id);
959 media_svc_error("_media_svc_get_noti_info failed : update item");
960 return MS_MEDIA_ERR_INVALID_PARAMETER;
963 ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
965 if (ret != MS_MEDIA_ERR_NONE) {
966 if (ret == MS_MEDIA_ERR_DB_NO_RECORD && update_item == MS_MEDIA_ITEM_DIRECTORY) {
967 media_svc_debug("This is root directory of media");
971 media_svc_error("error when _media_svc_get_noti_info. err = [%d]", ret);
976 *item = calloc(1, sizeof(media_svc_noti_item));
978 media_svc_error("_media_svc_get_noti_info failed : calloc");
979 return MS_MEDIA_ERR_OUT_OF_MEMORY;
982 if (update_item == MS_MEDIA_ITEM_FILE) {
983 (*item)->media_uuid = g_strdup((const char *)sqlite3_column_text(sql_stmt, 0));
984 (*item)->media_type = sqlite3_column_int(sql_stmt, 1);
985 (*item)->mime_type = g_strdup((const char *)sqlite3_column_text(sql_stmt, 2));
986 } else if (update_item == MS_MEDIA_ITEM_DIRECTORY) {
988 (*item)->media_uuid = NULL;
990 (*item)->media_uuid = g_strdup((const char *)sqlite3_column_text(sql_stmt, 0));
993 SQLITE3_FINALIZE(sql_stmt);
995 return MS_MEDIA_ERR_NONE;
998 int _media_svc_count_invalid_folder_items(sqlite3 *handle, const char *storage_id, const char *folder_path, int *count)
1000 int ret = MS_MEDIA_ERR_NONE;
1001 sqlite3_stmt *sql_stmt = NULL;
1003 char *sql = sqlite3_mprintf("SELECT count(*) FROM '%s' WHERE validity=0 AND path LIKE '%q/%%'", storage_id, folder_path);
1005 ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
1007 if (ret != MS_MEDIA_ERR_NONE) {
1008 media_svc_error("error when _media_svc_count_invalid_folder_items. err = [%d]", ret);
1012 *count = sqlite3_column_int(sql_stmt, 0);
1014 SQLITE3_FINALIZE(sql_stmt);
1016 return MS_MEDIA_ERR_NONE;
1019 int _media_svc_get_thumbnail_count(sqlite3 *handle, const char *storage_id, const char *thumb_path, int *count)
1021 int ret = MS_MEDIA_ERR_NONE;
1022 sqlite3_stmt *sql_stmt = NULL;
1023 char *sql = sqlite3_mprintf("SELECT count(*) FROM '%s' WHERE thumbnail_path=%Q", storage_id, thumb_path);
1025 ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
1027 if (ret != MS_MEDIA_ERR_NONE) {
1028 media_svc_error("error when _media_svc_get_thumbnail_count. err = [%d]", ret);
1032 *count = sqlite3_column_int(sql_stmt, 0);
1034 SQLITE3_FINALIZE(sql_stmt);
1036 return MS_MEDIA_ERR_NONE;
1039 int _media_svc_get_fileinfo_by_path(sqlite3 *handle, const char *storage_id, const char *path, time_t *modified_time, unsigned long long *size)
1041 int ret = MS_MEDIA_ERR_NONE;
1042 sqlite3_stmt *sql_stmt = NULL;
1043 char *sql = sqlite3_mprintf("SELECT modified_time, size FROM '%s' WHERE path='%q'", storage_id, path);
1045 ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
1047 if (ret != MS_MEDIA_ERR_NONE) {
1048 media_svc_error("error when _media_svc_get_fileinfo_by_path. err = [%d]", ret);
1052 *modified_time = (int)sqlite3_column_int(sql_stmt, 0);
1053 *size = (unsigned long long)sqlite3_column_int64(sql_stmt, 1);
1055 SQLITE3_FINALIZE(sql_stmt);
1057 return MS_MEDIA_ERR_NONE;
1060 int _media_svc_change_validity_item_batch(const char *storage_id, const char *path, int des_validity, int src_validity, uid_t uid)
1062 int ret = MS_MEDIA_ERR_NONE;
1064 char *sql = sqlite3_mprintf("UPDATE '%s' SET validity=%d WHERE validity=%d AND path LIKE '%q%%'", storage_id, des_validity, src_validity, path);
1066 ret = _media_svc_sql_query(sql, uid);
1072 int _media_svc_insert_item_pass1(sqlite3 *handle, const char *storage_id, media_svc_content_info_s *content_info, int is_burst, bool stack_query, uid_t uid)
1074 int ret = MS_MEDIA_ERR_NONE;
1075 char *burst_id = NULL;
1077 char * db_fields = (char *)"media_uuid, folder_uuid, path, file_name, media_type, mime_type, size, added_time, modified_time, is_drm, storage_type, timeline, burst_id, storage_uuid";
1079 char *sql = sqlite3_mprintf("INSERT INTO '%s' (%s) VALUES (%Q, %Q, %Q, %Q, %d, %Q, %lld, %d, %d, %d, %d, %d, %Q, %Q);",
1080 storage_id, db_fields,
1081 content_info->media_uuid,
1082 content_info->folder_uuid,
1084 content_info->file_name,
1085 content_info->media_type,
1086 content_info->mime_type,
1088 content_info->added_time,
1089 content_info->modified_time,
1090 content_info->is_drm,
1091 content_info->storage_type,
1092 content_info->timeline,
1098 sqlite3_free(burst_id);
1102 media_svc_debug("MAKE PASS 1 QUERY END");
1105 ret = _media_svc_sql_query(sql, uid);
1107 if (ret != MS_MEDIA_ERR_NONE) {
1108 media_svc_error("failed to insert item");
1112 media_svc_debug("query : %s", sql);
1113 _media_svc_sql_query_add(&g_media_svc_insert_item_query_list, &sql);
1115 media_svc_debug("END");
1116 return MS_MEDIA_ERR_NONE;
1119 int _media_svc_insert_item_pass2(const char *storage_id, media_svc_content_info_s *content_info, int is_burst, bool stack_query, uid_t uid)
1121 int ret = MS_MEDIA_ERR_NONE;
1123 media_svc_debug_fenter();
1125 /*Update Pinyin If Support Pinyin*/
1126 if (_media_svc_check_pinyin_support()) {
1127 if (STRING_VALID(content_info->file_name))
1128 _media_svc_get_pinyin_str(content_info->file_name, &content_info->file_name_pinyin);
1129 if (STRING_VALID(content_info->media_meta.title))
1130 _media_svc_get_pinyin_str(content_info->media_meta.title, &content_info->media_meta.title_pinyin);
1131 if (STRING_VALID(content_info->media_meta.album))
1132 _media_svc_get_pinyin_str(content_info->media_meta.album, &content_info->media_meta.album_pinyin);
1133 if (STRING_VALID(content_info->media_meta.artist))
1134 _media_svc_get_pinyin_str(content_info->media_meta.artist, &content_info->media_meta.artist_pinyin);
1135 if (STRING_VALID(content_info->media_meta.album_artist))
1136 _media_svc_get_pinyin_str(content_info->media_meta.album_artist, &content_info->media_meta.album_artist_pinyin);
1137 if (STRING_VALID(content_info->media_meta.genre))
1138 _media_svc_get_pinyin_str(content_info->media_meta.genre, &content_info->media_meta.genre_pinyin);
1139 if (STRING_VALID(content_info->media_meta.composer))
1140 _media_svc_get_pinyin_str(content_info->media_meta.composer, &content_info->media_meta.composer_pinyin);
1141 if (STRING_VALID(content_info->media_meta.copyright))
1142 _media_svc_get_pinyin_str(content_info->media_meta.copyright, &content_info->media_meta.copyright_pinyin);
1143 if (STRING_VALID(content_info->media_meta.description))
1144 _media_svc_get_pinyin_str(content_info->media_meta.description, &content_info->media_meta.description_pinyin);
1147 char *sql = sqlite3_mprintf("UPDATE '%s' SET \
1148 thumbnail_path=%Q, title=%Q, album_id=%d, album=%Q, artist=%Q, album_artist=%Q, genre=%Q, composer=%Q, year=%Q, \
1149 recorded_date=%Q, copyright=%Q, track_num=%Q, description=%Q, bitrate=%d, bitpersample=%d, samplerate=%d, channel=%d, \
1150 duration=%d, longitude=%.6f, latitude=%.6f, altitude=%.6f, width=%d, height=%d, datetaken=%Q, orientation=%d, exposure_time=%Q,\
1151 fnumber=%.6f, iso=%d, model=%Q, rating=%d, weather=%Q, file_name_pinyin=%Q, title_pinyin=%Q, album_pinyin=%Q, \
1152 artist_pinyin=%Q, album_artist_pinyin=%Q, genre_pinyin=%Q, composer_pinyin=%Q, copyright_pinyin=%Q, description_pinyin=%Q, is_360=%d WHERE path=%Q;",
1154 /* content_info->folder_uuid, */
1155 content_info->thumbnail_path,
1156 content_info->media_meta.title,
1157 content_info->album_id,
1158 content_info->media_meta.album,
1159 content_info->media_meta.artist,
1160 content_info->media_meta.album_artist,
1161 content_info->media_meta.genre,
1162 content_info->media_meta.composer,
1163 content_info->media_meta.year,
1164 content_info->media_meta.recorded_date,
1165 content_info->media_meta.copyright,
1166 content_info->media_meta.track_num,
1167 content_info->media_meta.description,
1168 content_info->media_meta.bitrate,
1169 content_info->media_meta.bitpersample,
1170 content_info->media_meta.samplerate,
1171 content_info->media_meta.channel,
1172 content_info->media_meta.duration,
1173 content_info->media_meta.longitude,
1174 content_info->media_meta.latitude,
1175 content_info->media_meta.altitude,
1176 content_info->media_meta.width,
1177 content_info->media_meta.height,
1178 content_info->media_meta.datetaken,
1179 content_info->media_meta.orientation,
1180 content_info->media_meta.exposure_time,
1181 content_info->media_meta.fnumber,
1182 content_info->media_meta.iso,
1183 content_info->media_meta.model,
1184 content_info->media_meta.rating,
1185 content_info->media_meta.weather,
1186 content_info->file_name_pinyin,
1187 content_info->media_meta.title_pinyin,
1188 content_info->media_meta.album_pinyin,
1189 content_info->media_meta.artist_pinyin,
1190 content_info->media_meta.album_artist_pinyin,
1191 content_info->media_meta.genre_pinyin,
1192 content_info->media_meta.composer_pinyin,
1193 content_info->media_meta.copyright_pinyin,
1194 content_info->media_meta.description_pinyin,
1195 content_info->media_meta.is_360,
1200 ret = _media_svc_sql_query(sql, uid);
1202 if (ret != MS_MEDIA_ERR_NONE) {
1204 media_svc_error("failed to insert item");
1208 /*media_svc_debug("query : %s", sql);*/
1209 _media_svc_sql_query_add(&g_media_svc_update_item_query_list, &sql);
1212 media_svc_debug_fleave();
1214 return MS_MEDIA_ERR_NONE;