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, \
224 thumbnail_path, title, album_id, album, artist, album_artist, genre, composer, year, recorded_date, copyright, track_num, description, \
225 category, keyword, location_tag, content_name, age_rating, author, provider, last_played_time, played_count, favourite, \
226 bitrate, bitpersample, samplerate, channel, duration, longitude, latitude, altitude, exposure_time, fnumber, iso, model, width, height, datetaken, orientation, \
227 rating, is_drm, storage_type, burst_id, timeline, weather, sync_status, \
228 file_name_pinyin, title_pinyin, album_pinyin, artist_pinyin, album_artist_pinyin, genre_pinyin, composer_pinyin, copyright_pinyin, description_pinyin, storage_uuid, is_360";
230 /* This sql is due to sqlite3_mprintf's wrong operation when using floating point in the text format */
231 /* This code will be removed when sqlite3_mprintf works clearly */
232 char *test_sql = sqlite3_mprintf("%f, %f, %f", content_info->media_meta.longitude, content_info->media_meta.latitude, content_info->media_meta.altitude);
233 sqlite3_free(test_sql);
236 int burst_id_int = 0;
237 ret = _media_svc_get_burst_id(handle, storage_id, &burst_id_int);
238 if (ret != MS_MEDIA_ERR_NONE)
241 if (burst_id_int > 0) {
242 media_svc_debug("Burst id : %d", burst_id_int);
243 burst_id = sqlite3_mprintf("%d", burst_id_int);
246 /* Get thumbnail for burst shot */
247 char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, };
251 ret = _media_svc_request_thumbnail_with_origin_size(content_info->path, thumb_path, sizeof(thumb_path), &width, &height, uid);
252 if (ret == MS_MEDIA_ERR_NONE) {
253 ret = __media_svc_malloc_and_strncpy(&(content_info->thumbnail_path), thumb_path);
254 if (ret != MS_MEDIA_ERR_NONE)
255 content_info->thumbnail_path = NULL;
258 if (content_info->media_meta.width <= 0)
259 content_info->media_meta.width = width;
261 if (content_info->media_meta.height <= 0)
262 content_info->media_meta.height = height;
265 /*Update Pinyin If Support Pinyin*/
266 if (_media_svc_check_pinyin_support()) {
267 if (STRING_VALID(content_info->file_name))
268 _media_svc_get_pinyin_str(content_info->file_name, &content_info->file_name_pinyin);
269 if (STRING_VALID(content_info->media_meta.title))
270 _media_svc_get_pinyin_str(content_info->media_meta.title, &content_info->media_meta.title_pinyin);
271 if (STRING_VALID(content_info->media_meta.album))
272 _media_svc_get_pinyin_str(content_info->media_meta.album, &content_info->media_meta.album_pinyin);
273 if (STRING_VALID(content_info->media_meta.artist))
274 _media_svc_get_pinyin_str(content_info->media_meta.artist, &content_info->media_meta.artist_pinyin);
275 if (STRING_VALID(content_info->media_meta.album_artist))
276 _media_svc_get_pinyin_str(content_info->media_meta.album_artist, &content_info->media_meta.album_artist_pinyin);
277 if (STRING_VALID(content_info->media_meta.genre))
278 _media_svc_get_pinyin_str(content_info->media_meta.genre, &content_info->media_meta.genre_pinyin);
279 if (STRING_VALID(content_info->media_meta.composer))
280 _media_svc_get_pinyin_str(content_info->media_meta.composer, &content_info->media_meta.composer_pinyin);
281 if (STRING_VALID(content_info->media_meta.copyright))
282 _media_svc_get_pinyin_str(content_info->media_meta.copyright, &content_info->media_meta.copyright_pinyin);
283 if (STRING_VALID(content_info->media_meta.description))
284 _media_svc_get_pinyin_str(content_info->media_meta.description, &content_info->media_meta.description_pinyin);
287 char *sql = sqlite3_mprintf("INSERT INTO '%s' (%s) VALUES (%Q, %Q, %Q, %d, %Q, %lld, %d, %d, %Q, \
288 %Q, %Q, %d, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, \
289 %Q, %Q, %Q, %Q, %Q, %Q, %Q, %d, %d, %d, \
290 %d, %d, %d, %d, %d, %.6f, %.6f, %.6f, %Q, %.6f, %d, %Q, %d, %d, %Q, %d, \
291 %d, %d, %d, %Q, %d, %Q, %d, \
292 %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, /**/
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, /**/
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,
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
363 sqlite3_free(burst_id);
368 ret = _media_svc_sql_query(sql, uid);
370 if (ret != MS_MEDIA_ERR_NONE) {
371 media_svc_error("failed to insert item");
375 media_svc_debug("query : %s", sql);
376 _media_svc_sql_query_add(&g_media_svc_insert_item_query_list, &sql);
379 return MS_MEDIA_ERR_NONE;
382 int _media_svc_update_meta_with_data(media_svc_content_info_s *content_info)
384 int ret = MS_MEDIA_ERR_NONE;
386 /* This sql is due to sqlite3_mprintf's wrong operation when using floating point in the text format */
387 /* This code will be removed when sqlite3_mprintf works clearly */
388 char *test_sql = sqlite3_mprintf("%f, %f, %f", content_info->media_meta.longitude, content_info->media_meta.latitude, content_info->media_meta.altitude);
389 sqlite3_free(test_sql);
391 /*Update Pinyin If Support Pinyin*/
392 if (_media_svc_check_pinyin_support()) {
393 if (STRING_VALID(content_info->file_name))
394 _media_svc_get_pinyin_str(content_info->file_name, &content_info->file_name_pinyin);
395 if (STRING_VALID(content_info->media_meta.title))
396 _media_svc_get_pinyin_str(content_info->media_meta.title, &content_info->media_meta.title_pinyin);
397 if (STRING_VALID(content_info->media_meta.album))
398 _media_svc_get_pinyin_str(content_info->media_meta.album, &content_info->media_meta.album_pinyin);
399 if (STRING_VALID(content_info->media_meta.artist))
400 _media_svc_get_pinyin_str(content_info->media_meta.artist, &content_info->media_meta.artist_pinyin);
401 if (STRING_VALID(content_info->media_meta.album_artist))
402 _media_svc_get_pinyin_str(content_info->media_meta.album_artist, &content_info->media_meta.album_artist_pinyin);
403 if (STRING_VALID(content_info->media_meta.genre))
404 _media_svc_get_pinyin_str(content_info->media_meta.genre, &content_info->media_meta.genre_pinyin);
405 if (STRING_VALID(content_info->media_meta.composer))
406 _media_svc_get_pinyin_str(content_info->media_meta.composer, &content_info->media_meta.composer_pinyin);
407 if (STRING_VALID(content_info->media_meta.copyright))
408 _media_svc_get_pinyin_str(content_info->media_meta.copyright, &content_info->media_meta.copyright_pinyin);
409 if (STRING_VALID(content_info->media_meta.description))
410 _media_svc_get_pinyin_str(content_info->media_meta.description, &content_info->media_meta.description_pinyin);
413 char *sql = sqlite3_mprintf("UPDATE %s SET title=%Q, album=%Q, artist=%Q, album_artist=%Q, genre=%Q, composer=%Q, copyright=%Q, description=%Q, \
414 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 \
416 MEDIA_SVC_DB_TABLE_MEDIA,
417 content_info->media_meta.title,
418 content_info->media_meta.album,
419 content_info->media_meta.artist,
420 content_info->media_meta.album_artist,
421 content_info->media_meta.genre,
422 content_info->media_meta.composer,
423 content_info->media_meta.copyright,
424 content_info->media_meta.description,
425 content_info->file_name_pinyin,
426 content_info->media_meta.title_pinyin,
427 content_info->media_meta.album_pinyin,
428 content_info->media_meta.artist_pinyin,
429 content_info->media_meta.album_artist_pinyin,
430 content_info->media_meta.genre_pinyin,
431 content_info->media_meta.composer_pinyin,
432 content_info->media_meta.copyright_pinyin,
433 content_info->media_meta.description_pinyin,
438 media_svc_debug("query : %s", sql);
439 _media_svc_sql_query_add(&g_media_svc_update_item_query_list, &sql);
441 media_svc_error("sqlite3_mprintf failed");
442 ret = MS_MEDIA_ERR_OUT_OF_MEMORY;
448 int _media_svc_update_item_with_data(const char *storage_id, media_svc_content_info_s *content_info, uid_t uid)
450 int ret = MS_MEDIA_ERR_NONE;
452 /* This sql is due to sqlite3_mprintf's wrong operation when using floating point in the text format */
453 /* This code will be removed when sqlite3_mprintf works clearly */
454 char *test_sql = sqlite3_mprintf("%f, %f, %f", content_info->media_meta.longitude, content_info->media_meta.latitude, content_info->media_meta.altitude);
455 sqlite3_free(test_sql);
457 /*Update Pinyin If Support Pinyin*/
458 if (_media_svc_check_pinyin_support()) {
459 if (STRING_VALID(content_info->file_name))
460 _media_svc_get_pinyin_str(content_info->file_name, &content_info->file_name_pinyin);
461 if (STRING_VALID(content_info->media_meta.title))
462 _media_svc_get_pinyin_str(content_info->media_meta.title, &content_info->media_meta.title_pinyin);
463 if (STRING_VALID(content_info->media_meta.album))
464 _media_svc_get_pinyin_str(content_info->media_meta.album, &content_info->media_meta.album_pinyin);
465 if (STRING_VALID(content_info->media_meta.artist))
466 _media_svc_get_pinyin_str(content_info->media_meta.artist, &content_info->media_meta.artist_pinyin);
467 if (STRING_VALID(content_info->media_meta.album_artist))
468 _media_svc_get_pinyin_str(content_info->media_meta.album_artist, &content_info->media_meta.album_artist_pinyin);
469 if (STRING_VALID(content_info->media_meta.genre))
470 _media_svc_get_pinyin_str(content_info->media_meta.genre, &content_info->media_meta.genre_pinyin);
471 if (STRING_VALID(content_info->media_meta.composer))
472 _media_svc_get_pinyin_str(content_info->media_meta.composer, &content_info->media_meta.composer_pinyin);
473 if (STRING_VALID(content_info->media_meta.copyright))
474 _media_svc_get_pinyin_str(content_info->media_meta.copyright, &content_info->media_meta.copyright_pinyin);
475 if (STRING_VALID(content_info->media_meta.description))
476 _media_svc_get_pinyin_str(content_info->media_meta.description, &content_info->media_meta.description_pinyin);
479 char *sql = sqlite3_mprintf("UPDATE '%s' SET \
480 size=%lld, modified_time=%d, thumbnail_path=%Q, title=%Q, album_id=%d, album=%Q, artist=%Q, album_artist=%Q, genre=%Q, \
481 composer=%Q, year=%Q, recorded_date=%Q, copyright=%Q, track_num=%Q, description=%Q, \
482 bitrate=%d, bitpersample=%d, samplerate=%d, channel=%d, duration=%d, longitude=%f, latitude=%f, altitude=%f, exposure_time=%Q, fnumber=%f, iso=%d, model=%Q, width=%d, height=%d, datetaken=%Q, \
483 orientation=%d WHERE path=%Q;",
486 content_info->modified_time,
487 content_info->thumbnail_path,
488 content_info->media_meta.title,
489 content_info->album_id,
490 content_info->media_meta.album,
491 content_info->media_meta.artist,
492 content_info->media_meta.album_artist,
493 content_info->media_meta.genre,
494 content_info->media_meta.composer,
495 content_info->media_meta.year,
496 content_info->media_meta.recorded_date,
497 content_info->media_meta.copyright,
498 content_info->media_meta.track_num,
499 content_info->media_meta.description,
500 content_info->media_meta.bitrate,
501 content_info->media_meta.bitpersample,
502 content_info->media_meta.samplerate,
503 content_info->media_meta.channel,
504 content_info->media_meta.duration,
505 content_info->media_meta.longitude,
506 content_info->media_meta.latitude,
507 content_info->media_meta.altitude,
508 content_info->media_meta.exposure_time,
509 content_info->media_meta.fnumber,
510 content_info->media_meta.iso,
511 content_info->media_meta.model,
512 content_info->media_meta.width,
513 content_info->media_meta.height,
514 content_info->media_meta.datetaken,
515 content_info->media_meta.orientation,
519 ret = _media_svc_sql_query(sql, uid);
524 int _media_svc_get_thumbnail_path_by_path(sqlite3 *handle, const char *storage_id, const char *path, char *thumbnail_path)
526 int ret = MS_MEDIA_ERR_NONE;
527 sqlite3_stmt *sql_stmt = NULL;
529 char *sql = sqlite3_mprintf("SELECT thumbnail_path FROM '%s' WHERE path='%q'", storage_id, path);
531 ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
533 if (ret != MS_MEDIA_ERR_NONE) {
534 if (ret == MS_MEDIA_ERR_DB_NO_RECORD)
535 media_svc_debug("there is no thumbnail.");
537 media_svc_error("error when _media_svc_get_thumbnail_path_by_path. err = [%d]", ret);
542 _strncpy_safe(thumbnail_path, (const char *)sqlite3_column_text(sql_stmt, 0), MEDIA_SVC_PATHNAME_SIZE);
544 SQLITE3_FINALIZE(sql_stmt);
546 return MS_MEDIA_ERR_NONE;
549 int _media_svc_get_media_type_by_path(sqlite3 *handle, const char *storage_id, const char *path, int *media_type)
551 int ret = MS_MEDIA_ERR_NONE;
552 sqlite3_stmt *sql_stmt = NULL;
554 char *sql = sqlite3_mprintf("SELECT media_type FROM '%s' WHERE path='%q'", storage_id, path);
556 ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
558 if (ret != MS_MEDIA_ERR_NONE) {
559 media_svc_error("error when _media_svc_get_media_type_by_path. err = [%d]", ret);
563 *media_type = sqlite3_column_int(sql_stmt, 0);
565 SQLITE3_FINALIZE(sql_stmt);
567 return MS_MEDIA_ERR_NONE;
570 int _media_svc_delete_item_by_path(const char *storage_id, const char *path, bool stack_query, uid_t uid)
572 int ret = MS_MEDIA_ERR_NONE;
573 char *sql = sqlite3_mprintf("DELETE FROM '%s' WHERE path='%q';", storage_id, path);
576 ret = _media_svc_sql_query(sql, uid);
578 if (ret != MS_MEDIA_ERR_NONE) {
579 media_svc_error("failed to delete item");
583 media_svc_debug("query : %s", sql);
584 _media_svc_sql_query_add(&g_media_svc_insert_item_query_list, &sql);
590 int _media_svc_truncate_table(const char *storage_id, media_svc_storage_type_e storage_type, uid_t uid)
592 int ret = MS_MEDIA_ERR_NONE;
594 char *sql = sqlite3_mprintf("DELETE FROM '%s' where storage_type=%d;", storage_id, storage_type);
596 ret = _media_svc_sql_query(sql, uid);
602 int _media_svc_delete_invalid_items(sqlite3 *handle, const char *storage_id, media_svc_storage_type_e storage_type, uid_t uid)
605 media_svc_thumbnailpath_s *thumbpath_record = NULL;
606 int invalid_count = 0;
607 int ret = MS_MEDIA_ERR_NONE;
609 ret = __media_svc_count_invalid_records_with_thumbnail(handle, storage_id, storage_type, &invalid_count);
610 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
612 media_svc_debug("invalid count: %d", invalid_count);
614 if (invalid_count > 0) {
615 thumbpath_record = (media_svc_thumbnailpath_s *)calloc(invalid_count, sizeof(media_svc_thumbnailpath_s));
616 if (thumbpath_record == NULL) {
617 media_svc_error("fail to memory allocation");
618 return MS_MEDIA_ERR_OUT_OF_MEMORY;
621 ret = __media_svc_get_invalid_records_with_thumbnail(handle, storage_id, storage_type, invalid_count, thumbpath_record);
622 if (ret != MS_MEDIA_ERR_NONE) {
623 media_svc_error("error when get thumbnail record");
624 SAFE_FREE(thumbpath_record);
628 media_svc_debug("There is no item with thumbnail");
631 char *sql = sqlite3_mprintf("DELETE FROM '%s' WHERE validity = 0;", storage_id);
633 ret = _media_svc_sql_query(sql, uid);
635 if (ret != MS_MEDIA_ERR_NONE) {
636 SAFE_FREE(thumbpath_record);
640 /*Delete thumbnails*/
641 char *default_thumbnail_path = _media_svc_get_thumb_default_path(uid);
642 for (idx = 0; idx < invalid_count; idx++) {
643 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)) {
644 ret = _media_svc_remove_file(thumbpath_record[idx].thumbnail_path);
645 if (ret != MS_MEDIA_ERR_NONE)
646 media_svc_error("fail to remove thumbnail file.");
650 SAFE_FREE(thumbpath_record);
651 SAFE_FREE(default_thumbnail_path);
653 return MS_MEDIA_ERR_NONE;
656 int _media_svc_delete_invalid_folder_items(sqlite3 *handle, const char *storage_id, const char *folder_path, bool is_recursive, uid_t uid)
659 media_svc_thumbnailpath_s *thumbpath_record = NULL;
660 int invalid_count = 0;
661 int ret = MS_MEDIA_ERR_NONE;
662 char folder_uuid[MEDIA_SVC_UUID_SIZE+1] = {0,};
665 /*get folder uuid from DB*/
666 ret = _media_svc_get_folder_id_by_foldername(handle, storage_id, folder_path, folder_uuid, uid);
667 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
669 ret = __media_svc_count_invalid_folder_records_with_thumbnail(handle, storage_id, folder_path, folder_uuid, is_recursive, &invalid_count);
670 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
672 media_svc_debug("invalid count: %d", invalid_count);
674 if (invalid_count > 0) {
675 thumbpath_record = (media_svc_thumbnailpath_s *)calloc(invalid_count, sizeof(media_svc_thumbnailpath_s));
676 if (thumbpath_record == NULL) {
677 media_svc_error("fail to memory allocation");
678 return MS_MEDIA_ERR_OUT_OF_MEMORY;
681 ret = __media_svc_get_invalid_folder_records_with_thumbnail(handle, storage_id, folder_path, folder_uuid, is_recursive, invalid_count, thumbpath_record);
682 if (ret != MS_MEDIA_ERR_NONE) {
683 media_svc_error("error when get thumbnail record");
684 SAFE_FREE(thumbpath_record);
688 media_svc_debug("There is no item with thumbnail");
692 sql = sqlite3_mprintf("DELETE FROM '%s' WHERE validity = 0 AND path LIKE '%q/%%';", storage_id, folder_path);
694 sql = sqlite3_mprintf("DELETE FROM '%s' WHERE validity = 0 AND folder_uuid='%q';", storage_id, folder_uuid);
696 ret = _media_svc_sql_query(sql, uid);
698 if (ret != MS_MEDIA_ERR_NONE) {
699 SAFE_FREE(thumbpath_record);
703 /*Delete thumbnails*/
704 if (thumbpath_record != NULL) {
705 char *default_thumbnail_path = _media_svc_get_thumb_default_path(uid);
706 if (STRING_VALID(default_thumbnail_path)) {
707 for (idx = 0; idx < invalid_count; idx++) {
708 if ((strlen(thumbpath_record[idx].thumbnail_path) > 0) && (strncmp(thumbpath_record[idx].thumbnail_path, default_thumbnail_path, strlen(default_thumbnail_path)) != 0)) {
709 ret = _media_svc_remove_file(thumbpath_record[idx].thumbnail_path);
710 if (ret != MS_MEDIA_ERR_NONE)
711 media_svc_error("fail to remove thumbnail file.");
716 SAFE_FREE(thumbpath_record);
717 SAFE_FREE(default_thumbnail_path);
720 return MS_MEDIA_ERR_NONE;
723 int _media_svc_update_item_validity(const char *storage_id, const char *path, int validity, bool stack_query, uid_t uid)
725 int ret = MS_MEDIA_ERR_NONE;
727 char *sql = sqlite3_mprintf("UPDATE '%s' SET validity=%d WHERE path= '%q';", storage_id, validity, path);
730 ret = _media_svc_sql_query(sql, uid);
733 _media_svc_sql_query_add(&g_media_svc_item_validity_query_list, &sql);
739 int _media_svc_update_thumbnail_path(const char *storage_id, const char *path, const char *thumb_path, uid_t uid)
741 int ret = MS_MEDIA_ERR_NONE;
743 char *sql = sqlite3_mprintf("UPDATE '%s' SET thumbnail_path=%Q WHERE path= %Q;", storage_id, thumb_path, path);
745 ret = _media_svc_sql_query(sql, uid);
751 int _media_svc_update_storage_item_validity(const char *storage_id, media_svc_storage_type_e storage_type, int validity, uid_t uid)
753 int ret = MS_MEDIA_ERR_NONE;
755 char *sql = sqlite3_mprintf("UPDATE '%s' SET validity=%d WHERE storage_type=%d;", storage_id, validity, storage_type);
757 ret = _media_svc_sql_query(sql, uid);
763 int _media_svc_update_folder_item_validity(sqlite3 *handle, const char *storage_id, const char *folder_path, int validity, uid_t uid)
765 int ret = MS_MEDIA_ERR_NONE;
767 char folder_uuid[MEDIA_SVC_UUID_SIZE + 1] = {0, };
768 sqlite3_stmt *sql_stmt = NULL;
771 sql = sqlite3_mprintf("SELECT folder_uuid FROM '%s' WHERE path='%q' AND storage_uuid='%q'", MEDIA_SVC_DB_TABLE_FOLDER, folder_path, storage_id);
773 ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
774 if (ret != MS_MEDIA_ERR_NONE) {
775 if (ret == MS_MEDIA_ERR_DB_NO_RECORD)
776 media_svc_debug("folder not exist");
778 media_svc_error("error when get folder_id. err = [%d]", ret);
783 _strncpy_safe(folder_uuid, (const char *)sqlite3_column_text(sql_stmt, 0), MEDIA_SVC_UUID_SIZE + 1);
784 SQLITE3_FINALIZE(sql_stmt);
786 /*Update folder item validity*/
787 sql = sqlite3_mprintf("UPDATE '%s' SET validity=%d WHERE folder_uuid='%q';", storage_id, validity, folder_uuid);
789 ret = _media_svc_sql_query(sql, uid);
795 int _media_svc_update_recursive_folder_item_validity(const char *storage_id, const char *folder_path, int validity, uid_t uid)
797 int ret = MS_MEDIA_ERR_NONE;
799 /*Update folder item validity*/
800 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);
802 ret = _media_svc_sql_query(sql, uid);
808 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,
809 const char *file_name, int modified_time, const char *folder_uuid, const char *thumb_path, bool stack_query, uid_t uid)
811 /* update path, filename, modified_time, folder_uuid, thumbnail_path, */
812 /* played_count, last_played_time, last_played_position, favourite, storaget_type*/
814 int ret = MS_MEDIA_ERR_NONE;
817 if (thumb_path != NULL) {
818 sql = sqlite3_mprintf("UPDATE '%s' SET \
819 path=%Q, file_name=%Q, modified_time=%d, folder_uuid=%Q, thumbnail_path=%Q, storage_type=%d, \
820 played_count=0, last_played_time=0, last_played_position=0 \
822 storage_id, dest_path, file_name, modified_time, folder_uuid, thumb_path, dest_storage, src_path);
824 sql = sqlite3_mprintf("UPDATE '%s' SET \
825 path=%Q, file_name=%Q, modified_time=%d, folder_uuid=%Q, storage_type=%d, \
826 played_count=0, last_played_time=0, last_played_position=0 \
828 storage_id, dest_path, file_name, modified_time, folder_uuid, dest_storage, src_path);
832 ret = _media_svc_sql_query(sql, uid);
835 _media_svc_sql_query_add(&g_media_svc_move_item_query_list, &sql);
841 int _media_svc_list_query_do(media_svc_query_type_e query_type, uid_t uid)
843 int ret = MS_MEDIA_ERR_NONE;
845 ret = _media_svc_sql_begin_trans(uid);
846 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
848 if (query_type == MEDIA_SVC_QUERY_SET_ITEM_VALIDITY)
849 ret = _media_svc_sql_query_list(&g_media_svc_item_validity_query_list, uid);
850 else if (query_type == MEDIA_SVC_QUERY_MOVE_ITEM)
851 ret = _media_svc_sql_query_list(&g_media_svc_move_item_query_list, uid);
852 else if (query_type == MEDIA_SVC_QUERY_INSERT_ITEM)
853 ret = _media_svc_sql_query_list(&g_media_svc_insert_item_query_list, uid);
854 else if (query_type == MEDIA_SVC_QUERY_UPDATE_ITEM)
855 ret = _media_svc_sql_query_list(&g_media_svc_update_item_query_list, uid);
856 else if (query_type == MEDIA_SVC_QUERY_INSERT_FOLDER)
857 ret = _media_svc_sql_query_list(_media_svc_get_folder_list_ptr(), uid);
858 else if (query_type == MEDIA_SVC_QUERY_UPDATE_COMMON)
859 ret = _media_svc_sql_query_list(&g_media_svc_update_list, uid);
861 ret = MS_MEDIA_ERR_INVALID_PARAMETER;
863 if (ret != MS_MEDIA_ERR_NONE) {
864 media_svc_error("_media_svc_list_query_do failed. start rollback");
865 _media_svc_sql_rollback_trans(uid);
869 ret = _media_svc_sql_end_trans(uid);
870 if (ret != MS_MEDIA_ERR_NONE) {
871 media_svc_error("mb_svc_sqlite3_commit_trans failed.. Now start to rollback");
872 _media_svc_sql_rollback_trans(uid);
876 return MS_MEDIA_ERR_NONE;
879 int _media_svc_append_query_list(const char *query, uid_t uid)
881 int ret = MS_MEDIA_ERR_NONE;
883 g_media_svc_update_list = g_list_append(g_media_svc_update_list, (gpointer)query);
885 g_media_svc_update_list_count++;
887 if (g_media_svc_update_list_count >= MEDIA_SVC_MAX_COMMIT_SIZE) {
888 ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_UPDATE_COMMON, uid);
889 g_media_svc_update_list_count = 0;
895 int _media_svc_get_burst_id(sqlite3 *handle, const char *storage_id, int *id)
897 int ret = MS_MEDIA_ERR_NONE;
899 sqlite3_stmt *sql_stmt = NULL;
900 char *sql = sqlite3_mprintf("SELECT max(CAST(burst_id AS INTEGER)) FROM '%s'", storage_id);
902 ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
904 if (ret != MS_MEDIA_ERR_NONE) {
905 media_svc_error("error when _media_svc_get_burst_id. err = [%d]", ret);
909 cur_id = sqlite3_column_int(sql_stmt, 0);
911 SQLITE3_FINALIZE(sql_stmt);
913 return MS_MEDIA_ERR_NONE;
916 int _media_svc_get_noti_info(sqlite3 *handle, const char *storage_id, const char *path, int update_item, media_svc_noti_item **item)
918 int ret = MS_MEDIA_ERR_NONE;
919 sqlite3_stmt *sql_stmt = NULL;
921 int is_root_dir = FALSE;
924 media_svc_error("invalid parameter");
925 return MS_MEDIA_ERR_INVALID_PARAMETER;
928 if (update_item == MS_MEDIA_ITEM_FILE)
929 sql = sqlite3_mprintf("SELECT media_uuid, media_type, mime_type FROM '%s' WHERE path=%Q", storage_id, path);
930 else if (update_item == MS_MEDIA_ITEM_DIRECTORY)
931 sql = sqlite3_mprintf("SELECT folder_uuid FROM '%s' WHERE path=%Q AND storage_uuid='%s'", MEDIA_SVC_DB_TABLE_FOLDER, path, storage_id);
933 media_svc_error("_media_svc_get_noti_info failed : update item");
934 return MS_MEDIA_ERR_INVALID_PARAMETER;
937 ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
939 if (ret != MS_MEDIA_ERR_NONE) {
940 if (ret == MS_MEDIA_ERR_DB_NO_RECORD && update_item == MS_MEDIA_ITEM_DIRECTORY) {
941 media_svc_debug("This is root directory of media");
945 media_svc_error("error when _media_svc_get_noti_info. err = [%d]", ret);
950 *item = calloc(1, sizeof(media_svc_noti_item));
952 media_svc_error("_media_svc_get_noti_info failed : calloc");
953 return MS_MEDIA_ERR_OUT_OF_MEMORY;
956 if (update_item == MS_MEDIA_ITEM_FILE) {
957 (*item)->media_uuid = g_strdup((const char *)sqlite3_column_text(sql_stmt, 0));
958 (*item)->media_type = sqlite3_column_int(sql_stmt, 1);
959 (*item)->mime_type = g_strdup((const char *)sqlite3_column_text(sql_stmt, 2));
960 } else if (update_item == MS_MEDIA_ITEM_DIRECTORY) {
962 (*item)->media_uuid = NULL;
964 (*item)->media_uuid = g_strdup((const char *)sqlite3_column_text(sql_stmt, 0));
967 SQLITE3_FINALIZE(sql_stmt);
969 return MS_MEDIA_ERR_NONE;
972 int _media_svc_count_invalid_folder_items(sqlite3 *handle, const char *storage_id, const char *folder_path, int *count)
974 int ret = MS_MEDIA_ERR_NONE;
975 sqlite3_stmt *sql_stmt = NULL;
977 char *sql = sqlite3_mprintf("SELECT count(*) FROM '%s' WHERE validity=0 AND path LIKE '%q/%%'", storage_id, folder_path);
979 ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
981 if (ret != MS_MEDIA_ERR_NONE) {
982 media_svc_error("error when _media_svc_count_invalid_folder_items. err = [%d]", ret);
986 *count = sqlite3_column_int(sql_stmt, 0);
988 SQLITE3_FINALIZE(sql_stmt);
990 return MS_MEDIA_ERR_NONE;
993 int _media_svc_get_thumbnail_count(sqlite3 *handle, const char *storage_id, const char *thumb_path, int *count)
995 int ret = MS_MEDIA_ERR_NONE;
996 sqlite3_stmt *sql_stmt = NULL;
997 char *sql = sqlite3_mprintf("SELECT count(*) FROM '%s' WHERE thumbnail_path=%Q", storage_id, thumb_path);
999 ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
1001 if (ret != MS_MEDIA_ERR_NONE) {
1002 media_svc_error("error when _media_svc_get_thumbnail_count. err = [%d]", ret);
1006 *count = sqlite3_column_int(sql_stmt, 0);
1008 SQLITE3_FINALIZE(sql_stmt);
1010 return MS_MEDIA_ERR_NONE;
1013 int _media_svc_get_fileinfo_by_path(sqlite3 *handle, const char *storage_id, const char *path, time_t *modified_time, unsigned long long *size)
1015 int ret = MS_MEDIA_ERR_NONE;
1016 sqlite3_stmt *sql_stmt = NULL;
1017 char *sql = sqlite3_mprintf("SELECT modified_time, size FROM '%s' WHERE path='%q'", storage_id, path);
1019 ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
1021 if (ret != MS_MEDIA_ERR_NONE) {
1022 media_svc_error("error when _media_svc_get_fileinfo_by_path. err = [%d]", ret);
1026 *modified_time = (int)sqlite3_column_int(sql_stmt, 0);
1027 *size = (unsigned long long)sqlite3_column_int64(sql_stmt, 1);
1029 SQLITE3_FINALIZE(sql_stmt);
1031 return MS_MEDIA_ERR_NONE;
1034 int _media_svc_change_validity_item_batch(const char *storage_id, const char *path, int des_validity, int src_validity, uid_t uid)
1036 int ret = MS_MEDIA_ERR_NONE;
1038 char *sql = sqlite3_mprintf("UPDATE '%s' SET validity=%d WHERE validity=%d AND path LIKE '%q%%'", storage_id, des_validity, src_validity, path);
1040 ret = _media_svc_sql_query(sql, uid);
1046 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)
1048 int ret = MS_MEDIA_ERR_NONE;
1049 char *burst_id = NULL;
1051 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";
1053 char *sql = sqlite3_mprintf("INSERT INTO '%s' (%s) VALUES (%Q, %Q, %Q, %Q, %d, %Q, %lld, \
1054 %d, %d, %d, %d, %d, %Q, %Q);",
1055 storage_id, db_fields,
1056 content_info->media_uuid,
1057 content_info->folder_uuid,
1059 content_info->file_name,
1060 content_info->media_type,
1061 content_info->mime_type,
1063 content_info->added_time,
1064 content_info->modified_time,
1065 content_info->is_drm,
1066 content_info->storage_type,
1067 content_info->timeline,
1073 sqlite3_free(burst_id);
1077 media_svc_debug("MAKE PASS 1 QUERY END");
1080 ret = _media_svc_sql_query(sql, uid);
1082 if (ret != MS_MEDIA_ERR_NONE) {
1083 media_svc_error("failed to insert item");
1087 media_svc_debug("query : %s", sql);
1088 _media_svc_sql_query_add(&g_media_svc_insert_item_query_list, &sql);
1090 media_svc_debug("END");
1091 return MS_MEDIA_ERR_NONE;
1094 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)
1096 int ret = MS_MEDIA_ERR_NONE;
1098 media_svc_debug_fenter();
1100 /*Update Pinyin If Support Pinyin*/
1101 if (_media_svc_check_pinyin_support()) {
1102 if (STRING_VALID(content_info->file_name))
1103 _media_svc_get_pinyin_str(content_info->file_name, &content_info->file_name_pinyin);
1104 if (STRING_VALID(content_info->media_meta.title))
1105 _media_svc_get_pinyin_str(content_info->media_meta.title, &content_info->media_meta.title_pinyin);
1106 if (STRING_VALID(content_info->media_meta.album))
1107 _media_svc_get_pinyin_str(content_info->media_meta.album, &content_info->media_meta.album_pinyin);
1108 if (STRING_VALID(content_info->media_meta.artist))
1109 _media_svc_get_pinyin_str(content_info->media_meta.artist, &content_info->media_meta.artist_pinyin);
1110 if (STRING_VALID(content_info->media_meta.album_artist))
1111 _media_svc_get_pinyin_str(content_info->media_meta.album_artist, &content_info->media_meta.album_artist_pinyin);
1112 if (STRING_VALID(content_info->media_meta.genre))
1113 _media_svc_get_pinyin_str(content_info->media_meta.genre, &content_info->media_meta.genre_pinyin);
1114 if (STRING_VALID(content_info->media_meta.composer))
1115 _media_svc_get_pinyin_str(content_info->media_meta.composer, &content_info->media_meta.composer_pinyin);
1116 if (STRING_VALID(content_info->media_meta.copyright))
1117 _media_svc_get_pinyin_str(content_info->media_meta.copyright, &content_info->media_meta.copyright_pinyin);
1118 if (STRING_VALID(content_info->media_meta.description))
1119 _media_svc_get_pinyin_str(content_info->media_meta.description, &content_info->media_meta.description_pinyin);
1122 char *sql = sqlite3_mprintf("UPDATE '%s' SET \
1123 thumbnail_path=%Q, title=%Q, album_id=%d, album=%Q, artist=%Q, album_artist=%Q, genre=%Q, composer=%Q, year=%Q, \
1124 recorded_date=%Q, copyright=%Q, track_num=%Q, description=%Q, bitrate=%d, bitpersample=%d, samplerate=%d, channel=%d, \
1125 duration=%d, longitude=%.6f, latitude=%.6f, altitude=%.6f, width=%d, height=%d, datetaken=%Q, orientation=%d, exposure_time=%Q,\
1126 fnumber=%.6f, iso=%d, model=%Q, rating=%d, weather=%Q, file_name_pinyin=%Q, title_pinyin=%Q, album_pinyin=%Q, \
1127 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;",
1129 /* content_info->folder_uuid, */
1130 content_info->thumbnail_path,
1131 content_info->media_meta.title,
1132 content_info->album_id,
1133 content_info->media_meta.album,
1134 content_info->media_meta.artist,
1135 content_info->media_meta.album_artist,
1136 content_info->media_meta.genre,
1137 content_info->media_meta.composer,
1138 content_info->media_meta.year,
1139 content_info->media_meta.recorded_date,
1140 content_info->media_meta.copyright,
1141 content_info->media_meta.track_num,
1142 content_info->media_meta.description,
1143 content_info->media_meta.bitrate,
1144 content_info->media_meta.bitpersample,
1145 content_info->media_meta.samplerate,
1146 content_info->media_meta.channel,
1147 content_info->media_meta.duration,
1148 content_info->media_meta.longitude,
1149 content_info->media_meta.latitude,
1150 content_info->media_meta.altitude,
1151 content_info->media_meta.width,
1152 content_info->media_meta.height,
1153 content_info->media_meta.datetaken,
1154 content_info->media_meta.orientation,
1155 content_info->media_meta.exposure_time,
1156 content_info->media_meta.fnumber,
1157 content_info->media_meta.iso,
1158 content_info->media_meta.model,
1159 content_info->media_meta.rating,
1160 content_info->media_meta.weather,
1161 content_info->file_name_pinyin,
1162 content_info->media_meta.title_pinyin,
1163 content_info->media_meta.album_pinyin,
1164 content_info->media_meta.artist_pinyin,
1165 content_info->media_meta.album_artist_pinyin,
1166 content_info->media_meta.genre_pinyin,
1167 content_info->media_meta.composer_pinyin,
1168 content_info->media_meta.copyright_pinyin,
1169 content_info->media_meta.description_pinyin,
1170 content_info->media_meta.is_360,
1175 ret = _media_svc_sql_query(sql, uid);
1177 if (ret != MS_MEDIA_ERR_NONE) {
1179 media_svc_error("failed to insert item");
1183 /*media_svc_debug("query : %s", sql);*/
1184 _media_svc_sql_query_add(&g_media_svc_update_item_query_list, &sql);
1187 media_svc_debug_fleave();
1189 return MS_MEDIA_ERR_NONE;