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>
25 #include <media-util-err.h>
26 #include "media-svc-media.h"
27 #include "media-svc-media-folder.h"
28 #include "media-svc-debug.h"
29 #include "media-svc-util.h"
30 #include "media-svc-db-utils.h"
31 #include "media-svc-noti.h"
33 #define MEDIA_SVC_MAX_COMMIT_SIZE 200
36 char thumbnail_path[MEDIA_SVC_PATHNAME_SIZE];
37 } media_svc_thumbnailpath_s;
39 static __thread GList *g_media_svc_item_validity_query_list = NULL;
40 static __thread GList *g_media_svc_insert_item_query_list = NULL;
41 __thread GList *g_media_svc_move_item_query_list = NULL;
42 static __thread GList *g_media_svc_update_item_query_list = NULL;
43 static __thread GList *g_media_svc_update_list = NULL;
44 static __thread int g_media_svc_update_list_count = 0;
46 static int __media_svc_count_invalid_records_with_thumbnail(sqlite3 *handle, const char *storage_id, media_svc_storage_type_e storage_type, int *count);
47 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);
48 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);
49 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);
51 static int __media_svc_count_invalid_records_with_thumbnail(sqlite3 *handle, const char *storage_id, media_svc_storage_type_e storage_type, int *count)
53 int ret = MS_MEDIA_ERR_NONE;
54 sqlite3_stmt *sql_stmt = NULL;
55 char *sql = sqlite3_mprintf("SELECT count(*) FROM '%s' WHERE validity=0 AND storage_type=%d AND thumbnail_path IS NOT NULL",
56 storage_id, storage_type);
58 ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
60 if (ret != MS_MEDIA_ERR_NONE) {
61 media_svc_error("error when __media_svc_count_invalid_records_with_thumbnail. err = [%d]", ret);
65 *count = sqlite3_column_int(sql_stmt, 0);
67 SQLITE3_FINALIZE(sql_stmt);
69 return MS_MEDIA_ERR_NONE;
73 static int __media_svc_get_invalid_records_with_thumbnail(sqlite3 *handle, const char *storage_id, media_svc_storage_type_e storage_type,
74 int count, media_svc_thumbnailpath_s * thumb_path)
76 int ret = MS_MEDIA_ERR_NONE;
77 sqlite3_stmt *sql_stmt = NULL;
80 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",
81 MEDIA_SVC_DB_TABLE_MEDIA, storage_type);
83 media_svc_debug("[SQL query] : %s", sql);
85 ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
86 if (ret != MS_MEDIA_ERR_NONE) {
87 media_svc_error("error when __media_svc_get_invalid_records_with_thumbnail. err = [%d]", ret);
91 while (sqlite3_step(sql_stmt) == SQLITE_ROW) {
92 _strncpy_safe(thumb_path[idx].thumbnail_path, (const char *)sqlite3_column_text(sql_stmt, 0), sizeof(thumb_path[idx]));
93 /*media_svc_debug("thumb_path[%d]=[%s]", idx, thumb_path[idx].thumbnail_path); */
97 SQLITE3_FINALIZE(sql_stmt);
99 return MS_MEDIA_ERR_NONE;
102 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)
104 int ret = MS_MEDIA_ERR_NONE;
105 sqlite3_stmt *sql_stmt = NULL;
109 sql = sqlite3_mprintf("SELECT count(*) FROM '%s' WHERE validity=0 AND path LIKE '%q/%%' AND thumbnail_path IS NOT NULL", storage_id, folder_path);
111 sql = sqlite3_mprintf("SELECT count(*) FROM '%s' WHERE validity=0 AND folder_uuid = '%q' AND thumbnail_path IS NOT NULL", storage_id, folder_uuid);
113 ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
115 if (ret != MS_MEDIA_ERR_NONE) {
116 media_svc_error("error when __media_svc_count_invalid_folder_records_with_thumbnail. err = [%d]", ret);
120 *count = sqlite3_column_int(sql_stmt, 0);
122 SQLITE3_FINALIZE(sql_stmt);
124 return MS_MEDIA_ERR_NONE;
128 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,
129 int count, media_svc_thumbnailpath_s * thumb_path)
131 int ret = MS_MEDIA_ERR_NONE;
132 sqlite3_stmt *sql_stmt = NULL;
137 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);
139 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);
141 media_svc_debug("[SQL query] : %s", sql);
143 ret = _media_svc_sql_prepare_to_step_simple(handle, sql, &sql_stmt);
144 if (ret != MS_MEDIA_ERR_NONE) {
145 media_svc_error("error when __media_svc_get_invalid_folder_records_with_thumbnail. err = [%d]", ret);
149 while (sqlite3_step(sql_stmt) == SQLITE_ROW) {
150 _strncpy_safe(thumb_path[idx].thumbnail_path, (const char *)sqlite3_column_text(sql_stmt, 0), sizeof(thumb_path[idx]));
154 SQLITE3_FINALIZE(sql_stmt);
156 return MS_MEDIA_ERR_NONE;
159 int _media_svc_count_record_with_path(sqlite3 *handle, const char *storage_id, const char *path, int *count)
161 int ret = MS_MEDIA_ERR_NONE;
162 sqlite3_stmt *sql_stmt = NULL;
164 char *sql = sqlite3_mprintf("SELECT count(*) FROM '%s' WHERE path='%q'", storage_id, path);
166 ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
168 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
170 *count = sqlite3_column_int(sql_stmt, 0);
172 SQLITE3_FINALIZE(sql_stmt);
174 return MS_MEDIA_ERR_NONE;
177 char *_media_svc_get_thumb_default_path(uid_t uid)
180 char *result_path = NULL;
182 ret = tzplatform_set_user(uid);
184 media_svc_error("Invalid UID[%d]", uid);
187 const char *result = tzplatform_mkpath(TZ_USER_SHARE, "media/.thumb/thumb_default.png");
188 result_path = strndup(result, strlen(result));
189 tzplatform_reset_user();
195 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)
197 int ret = MS_MEDIA_ERR_NONE;
198 char *burst_id = NULL;
200 const char *db_fields = "media_uuid, path, file_name, media_type, mime_type, size, added_time, modified_time, folder_uuid, thumbnail_path, \
201 title, album_id, album, artist, album_artist, genre, composer, year, recorded_date, copyright, track_num, description, category, keyword, location_tag, \
202 content_name, age_rating, author, provider, last_played_time, played_count, favourite, bitrate, bitpersample, samplerate, channel, duration, \
203 longitude, latitude, altitude, exposure_time, fnumber, iso, model, width, height, datetaken, orientation, rating, is_drm, storage_type, burst_id, timeline, weather, sync_status, \
204 file_name_pinyin, title_pinyin, album_pinyin, artist_pinyin, album_artist_pinyin, genre_pinyin, composer_pinyin, copyright_pinyin, description_pinyin, storage_uuid, is_360";
206 const char *db_fields_basic = "media_uuid, path, file_name, media_type, mime_type, size, added_time, modified_time, folder_uuid, thumbnail_path, \
207 album_id, last_played_time, played_count, favourite, is_drm, storage_type, burst_id, timeline, sync_status, file_name_pinyin, storage_uuid, is_360";
209 /* This sql is due to sqlite3_mprintf's wrong operation when using floating point in the text format */
210 /* This code will be removed when sqlite3_mprintf works clearly */
211 char *test_sql = sqlite3_mprintf("%f, %f, %f", content_info->media_meta.longitude, content_info->media_meta.latitude, content_info->media_meta.altitude);
212 sqlite3_free(test_sql);
215 int burst_id_int = 0;
216 ret = _media_svc_get_burst_id(handle, storage_id, &burst_id_int);
217 if (ret != MS_MEDIA_ERR_NONE)
220 if (burst_id_int > 0) {
221 media_svc_debug("Burst id : %d", burst_id_int);
222 burst_id = sqlite3_mprintf("%d", burst_id_int);
225 /* Get thumbnail for burst shot */
226 char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, };
230 ret = _media_svc_request_thumbnail_with_origin_size(content_info->path, thumb_path, sizeof(thumb_path), &width, &height, uid);
231 if (ret == MS_MEDIA_ERR_NONE) {
232 ret = __media_svc_malloc_and_strncpy(&(content_info->thumbnail_path), thumb_path);
233 if (ret != MS_MEDIA_ERR_NONE)
234 content_info->thumbnail_path = NULL;
237 if (content_info->media_meta.width <= 0)
238 content_info->media_meta.width = width;
240 if (content_info->media_meta.height <= 0)
241 content_info->media_meta.height = height;
244 /*Update Pinyin If Support Pinyin*/
245 if (_media_svc_check_pinyin_support()) {
246 if (STRING_VALID(content_info->file_name))
247 _media_svc_get_pinyin_str(content_info->file_name, &content_info->file_name_pinyin);
248 if (STRING_VALID(content_info->media_meta.title))
249 _media_svc_get_pinyin_str(content_info->media_meta.title, &content_info->media_meta.title_pinyin);
250 if (STRING_VALID(content_info->media_meta.album))
251 _media_svc_get_pinyin_str(content_info->media_meta.album, &content_info->media_meta.album_pinyin);
252 if (STRING_VALID(content_info->media_meta.artist))
253 _media_svc_get_pinyin_str(content_info->media_meta.artist, &content_info->media_meta.artist_pinyin);
254 if (STRING_VALID(content_info->media_meta.album_artist))
255 _media_svc_get_pinyin_str(content_info->media_meta.album_artist, &content_info->media_meta.album_artist_pinyin);
256 if (STRING_VALID(content_info->media_meta.genre))
257 _media_svc_get_pinyin_str(content_info->media_meta.genre, &content_info->media_meta.genre_pinyin);
258 if (STRING_VALID(content_info->media_meta.composer))
259 _media_svc_get_pinyin_str(content_info->media_meta.composer, &content_info->media_meta.composer_pinyin);
260 if (STRING_VALID(content_info->media_meta.copyright))
261 _media_svc_get_pinyin_str(content_info->media_meta.copyright, &content_info->media_meta.copyright_pinyin);
262 if (STRING_VALID(content_info->media_meta.description))
263 _media_svc_get_pinyin_str(content_info->media_meta.description, &content_info->media_meta.description_pinyin);
266 char *sql = sqlite3_mprintf("INSERT INTO '%s' (%s) VALUES (%Q, %Q, %Q, %d, %Q, %lld, %d, %d, %Q, \
267 %Q, %Q, %d, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %d, %d, %d, \
268 %d, %d, %d, %d, %d, %.6f, %.6f, %.6f, %Q, %.6f, %d, %Q, %d, %d, %Q, %d, \
269 %d, %d, %d, %Q, %d, %Q, %d, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %d);",
270 content_info->storage_uuid, db_fields,
271 content_info->media_uuid,
273 content_info->file_name,
274 content_info->media_type,
275 content_info->mime_type,
277 content_info->added_time,
278 content_info->modified_time,
279 content_info->folder_uuid, /* 1st line */
280 content_info->thumbnail_path,
281 content_info->media_meta.title,
282 content_info->album_id,
283 content_info->media_meta.album,
284 content_info->media_meta.artist,
285 content_info->media_meta.album_artist,
286 content_info->media_meta.genre,
287 content_info->media_meta.composer,
288 content_info->media_meta.year,
289 content_info->media_meta.recorded_date,
290 content_info->media_meta.copyright,
291 content_info->media_meta.track_num,
292 content_info->media_meta.description,
293 content_info->media_meta.category,
294 content_info->media_meta.keyword,
295 content_info->media_meta.location_tag,
296 content_info->media_meta.content_name,
297 content_info->media_meta.age_rating,
298 content_info->media_meta.author,
299 content_info->media_meta.provider,
300 content_info->last_played_time,
301 content_info->played_count,
302 content_info->favourate, /* 2nd line */
303 content_info->media_meta.bitrate,
304 content_info->media_meta.bitpersample,
305 content_info->media_meta.samplerate,
306 content_info->media_meta.channel,
307 content_info->media_meta.duration,
308 content_info->media_meta.longitude,
309 content_info->media_meta.latitude,
310 content_info->media_meta.altitude,
311 content_info->media_meta.exposure_time,
312 content_info->media_meta.fnumber,
313 content_info->media_meta.iso,
314 content_info->media_meta.model,
315 content_info->media_meta.width,
316 content_info->media_meta.height,
317 content_info->media_meta.datetaken,
318 content_info->media_meta.orientation, /* 3rd line */
319 content_info->media_meta.rating,
320 content_info->is_drm,
321 content_info->storage_type,
323 content_info->timeline,
324 content_info->media_meta.weather,
325 content_info->sync_status,
326 content_info->file_name_pinyin,
327 content_info->media_meta.title_pinyin,
328 content_info->media_meta.album_pinyin,
329 content_info->media_meta.artist_pinyin,
330 content_info->media_meta.album_artist_pinyin,
331 content_info->media_meta.genre_pinyin,
332 content_info->media_meta.composer_pinyin,
333 content_info->media_meta.copyright_pinyin,
334 content_info->media_meta.description_pinyin,
335 content_info->storage_uuid,
336 content_info->media_meta.is_360 /* 4th line */
339 /* Check query length */
340 if (sql != NULL && strlen(sql) >= SQLITE3_QUERY_MAX_LEN) {
341 media_svc_debug("Query length is over %d byte.. So, remake query using only basic information..", SQLITE3_QUERY_MAX_LEN);
342 SQLITE3_SAFE_FREE(sql);
344 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);",
345 content_info->storage_uuid, db_fields_basic,
346 content_info->media_uuid,
348 content_info->file_name,
349 content_info->media_type,
350 content_info->mime_type,
352 content_info->added_time,
353 content_info->modified_time,
354 content_info->folder_uuid,
355 content_info->thumbnail_path,
356 content_info->album_id,
357 content_info->last_played_time,
358 content_info->played_count,
359 content_info->favourate,
360 content_info->is_drm,
361 content_info->storage_type,
363 content_info->timeline,
364 content_info->sync_status,
365 content_info->file_name_pinyin,
366 content_info->storage_uuid,
367 content_info->media_meta.is_360 /* 1st line */
372 sqlite3_free(burst_id);
377 ret = _media_svc_sql_query(sql, uid);
379 if (ret != MS_MEDIA_ERR_NONE) {
380 media_svc_error("failed to insert item");
384 media_svc_debug("query : %s", sql);
385 _media_svc_sql_query_add(&g_media_svc_insert_item_query_list, &sql);
388 return MS_MEDIA_ERR_NONE;
391 int _media_svc_update_meta_with_data(media_svc_content_info_s *content_info)
393 int ret = MS_MEDIA_ERR_NONE;
395 /* This sql is due to sqlite3_mprintf's wrong operation when using floating point in the text format */
396 /* This code will be removed when sqlite3_mprintf works clearly */
397 char *test_sql = sqlite3_mprintf("%f, %f, %f", content_info->media_meta.longitude, content_info->media_meta.latitude, content_info->media_meta.altitude);
398 sqlite3_free(test_sql);
400 /*Update Pinyin If Support Pinyin*/
401 if (_media_svc_check_pinyin_support()) {
402 if (STRING_VALID(content_info->file_name))
403 _media_svc_get_pinyin_str(content_info->file_name, &content_info->file_name_pinyin);
404 if (STRING_VALID(content_info->media_meta.title))
405 _media_svc_get_pinyin_str(content_info->media_meta.title, &content_info->media_meta.title_pinyin);
406 if (STRING_VALID(content_info->media_meta.album))
407 _media_svc_get_pinyin_str(content_info->media_meta.album, &content_info->media_meta.album_pinyin);
408 if (STRING_VALID(content_info->media_meta.artist))
409 _media_svc_get_pinyin_str(content_info->media_meta.artist, &content_info->media_meta.artist_pinyin);
410 if (STRING_VALID(content_info->media_meta.album_artist))
411 _media_svc_get_pinyin_str(content_info->media_meta.album_artist, &content_info->media_meta.album_artist_pinyin);
412 if (STRING_VALID(content_info->media_meta.genre))
413 _media_svc_get_pinyin_str(content_info->media_meta.genre, &content_info->media_meta.genre_pinyin);
414 if (STRING_VALID(content_info->media_meta.composer))
415 _media_svc_get_pinyin_str(content_info->media_meta.composer, &content_info->media_meta.composer_pinyin);
416 if (STRING_VALID(content_info->media_meta.copyright))
417 _media_svc_get_pinyin_str(content_info->media_meta.copyright, &content_info->media_meta.copyright_pinyin);
418 if (STRING_VALID(content_info->media_meta.description))
419 _media_svc_get_pinyin_str(content_info->media_meta.description, &content_info->media_meta.description_pinyin);
422 char *sql = sqlite3_mprintf("UPDATE %s SET title=%Q, album=%Q, artist=%Q, album_artist=%Q, genre=%Q, composer=%Q, copyright=%Q, description=%Q, \
423 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 \
425 MEDIA_SVC_DB_TABLE_MEDIA,
426 content_info->media_meta.title,
427 content_info->media_meta.album,
428 content_info->media_meta.artist,
429 content_info->media_meta.album_artist,
430 content_info->media_meta.genre,
431 content_info->media_meta.composer,
432 content_info->media_meta.copyright,
433 content_info->media_meta.description,
434 content_info->file_name_pinyin,
435 content_info->media_meta.title_pinyin,
436 content_info->media_meta.album_pinyin,
437 content_info->media_meta.artist_pinyin,
438 content_info->media_meta.album_artist_pinyin,
439 content_info->media_meta.genre_pinyin,
440 content_info->media_meta.composer_pinyin,
441 content_info->media_meta.copyright_pinyin,
442 content_info->media_meta.description_pinyin,
447 media_svc_debug("query : %s", sql);
448 _media_svc_sql_query_add(&g_media_svc_update_item_query_list, &sql);
450 media_svc_error("sqlite3_mprintf failed");
451 ret = MS_MEDIA_ERR_OUT_OF_MEMORY;
457 int _media_svc_update_item_with_data(const char *storage_id, media_svc_content_info_s *content_info, uid_t uid)
459 int ret = MS_MEDIA_ERR_NONE;
461 /* This sql is due to sqlite3_mprintf's wrong operation when using floating point in the text format */
462 /* This code will be removed when sqlite3_mprintf works clearly */
463 char *test_sql = sqlite3_mprintf("%f, %f, %f", content_info->media_meta.longitude, content_info->media_meta.latitude, content_info->media_meta.altitude);
464 sqlite3_free(test_sql);
466 /*Update Pinyin If Support Pinyin*/
467 if (_media_svc_check_pinyin_support()) {
468 if (STRING_VALID(content_info->file_name))
469 _media_svc_get_pinyin_str(content_info->file_name, &content_info->file_name_pinyin);
470 if (STRING_VALID(content_info->media_meta.title))
471 _media_svc_get_pinyin_str(content_info->media_meta.title, &content_info->media_meta.title_pinyin);
472 if (STRING_VALID(content_info->media_meta.album))
473 _media_svc_get_pinyin_str(content_info->media_meta.album, &content_info->media_meta.album_pinyin);
474 if (STRING_VALID(content_info->media_meta.artist))
475 _media_svc_get_pinyin_str(content_info->media_meta.artist, &content_info->media_meta.artist_pinyin);
476 if (STRING_VALID(content_info->media_meta.album_artist))
477 _media_svc_get_pinyin_str(content_info->media_meta.album_artist, &content_info->media_meta.album_artist_pinyin);
478 if (STRING_VALID(content_info->media_meta.genre))
479 _media_svc_get_pinyin_str(content_info->media_meta.genre, &content_info->media_meta.genre_pinyin);
480 if (STRING_VALID(content_info->media_meta.composer))
481 _media_svc_get_pinyin_str(content_info->media_meta.composer, &content_info->media_meta.composer_pinyin);
482 if (STRING_VALID(content_info->media_meta.copyright))
483 _media_svc_get_pinyin_str(content_info->media_meta.copyright, &content_info->media_meta.copyright_pinyin);
484 if (STRING_VALID(content_info->media_meta.description))
485 _media_svc_get_pinyin_str(content_info->media_meta.description, &content_info->media_meta.description_pinyin);
488 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, \
489 composer=%Q, year=%Q, recorded_date=%Q, copyright=%Q, track_num=%Q, description=%Q, bitrate=%d, bitpersample=%d, samplerate=%d, channel=%d, duration=%d, \
490 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;",
493 content_info->modified_time,
494 content_info->thumbnail_path,
495 content_info->media_meta.title,
496 content_info->album_id,
497 content_info->media_meta.album,
498 content_info->media_meta.artist,
499 content_info->media_meta.album_artist,
500 content_info->media_meta.genre,
501 content_info->media_meta.composer,
502 content_info->media_meta.year,
503 content_info->media_meta.recorded_date,
504 content_info->media_meta.copyright,
505 content_info->media_meta.track_num,
506 content_info->media_meta.description,
507 content_info->media_meta.bitrate,
508 content_info->media_meta.bitpersample,
509 content_info->media_meta.samplerate,
510 content_info->media_meta.channel,
511 content_info->media_meta.duration,
512 content_info->media_meta.longitude,
513 content_info->media_meta.latitude,
514 content_info->media_meta.altitude,
515 content_info->media_meta.exposure_time,
516 content_info->media_meta.fnumber,
517 content_info->media_meta.iso,
518 content_info->media_meta.model,
519 content_info->media_meta.width,
520 content_info->media_meta.height,
521 content_info->media_meta.datetaken,
522 content_info->media_meta.orientation,
526 ret = _media_svc_sql_query(sql, uid);
531 int _media_svc_get_thumbnail_path_by_path(sqlite3 *handle, const char *storage_id, const char *path, char *thumbnail_path)
533 int ret = MS_MEDIA_ERR_NONE;
534 sqlite3_stmt *sql_stmt = NULL;
536 char *sql = sqlite3_mprintf("SELECT thumbnail_path FROM '%s' WHERE path='%q'", storage_id, path);
538 ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
540 if (ret != MS_MEDIA_ERR_NONE) {
541 if (ret == MS_MEDIA_ERR_DB_NO_RECORD)
542 media_svc_debug("there is no thumbnail.");
544 media_svc_error("error when _media_svc_get_thumbnail_path_by_path. err = [%d]", ret);
549 _strncpy_safe(thumbnail_path, (const char *)sqlite3_column_text(sql_stmt, 0), MEDIA_SVC_PATHNAME_SIZE);
551 SQLITE3_FINALIZE(sql_stmt);
553 return MS_MEDIA_ERR_NONE;
556 int _media_svc_get_media_type_by_path(sqlite3 *handle, const char *storage_id, const char *path, int *media_type)
558 int ret = MS_MEDIA_ERR_NONE;
559 sqlite3_stmt *sql_stmt = NULL;
561 char *sql = sqlite3_mprintf("SELECT media_type FROM '%s' WHERE path='%q'", storage_id, path);
563 ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
565 if (ret != MS_MEDIA_ERR_NONE) {
566 media_svc_error("error when _media_svc_get_media_type_by_path. err = [%d]", ret);
570 *media_type = sqlite3_column_int(sql_stmt, 0);
572 SQLITE3_FINALIZE(sql_stmt);
574 return MS_MEDIA_ERR_NONE;
577 int _media_svc_delete_item_by_path(const char *storage_id, const char *path, bool stack_query, uid_t uid)
579 int ret = MS_MEDIA_ERR_NONE;
580 char *sql = sqlite3_mprintf("DELETE FROM '%s' WHERE path='%q';", storage_id, path);
583 ret = _media_svc_sql_query(sql, uid);
585 if (ret != MS_MEDIA_ERR_NONE) {
586 media_svc_error("failed to delete item");
590 media_svc_debug("query : %s", sql);
591 _media_svc_sql_query_add(&g_media_svc_insert_item_query_list, &sql);
597 int _media_svc_truncate_table(const char *storage_id, media_svc_storage_type_e storage_type, uid_t uid)
599 int ret = MS_MEDIA_ERR_NONE;
601 char *sql = sqlite3_mprintf("DELETE FROM '%s' where storage_type=%d;", storage_id, storage_type);
603 ret = _media_svc_sql_query(sql, uid);
609 int _media_svc_delete_invalid_items(sqlite3 *handle, const char *storage_id, media_svc_storage_type_e storage_type, uid_t uid)
612 media_svc_thumbnailpath_s *thumbpath_record = NULL;
613 int invalid_count = 0;
614 int ret = MS_MEDIA_ERR_NONE;
616 ret = __media_svc_count_invalid_records_with_thumbnail(handle, storage_id, storage_type, &invalid_count);
617 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
619 media_svc_debug("invalid count: %d", invalid_count);
621 if (invalid_count > 0) {
622 thumbpath_record = (media_svc_thumbnailpath_s *)calloc(invalid_count, sizeof(media_svc_thumbnailpath_s));
623 if (thumbpath_record == NULL) {
624 media_svc_error("fail to memory allocation");
625 return MS_MEDIA_ERR_OUT_OF_MEMORY;
628 ret = __media_svc_get_invalid_records_with_thumbnail(handle, storage_id, storage_type, invalid_count, thumbpath_record);
629 if (ret != MS_MEDIA_ERR_NONE) {
630 media_svc_error("error when get thumbnail record");
631 SAFE_FREE(thumbpath_record);
635 media_svc_debug("There is no item with thumbnail");
638 char *sql = sqlite3_mprintf("DELETE FROM '%s' WHERE validity = 0;", storage_id);
640 ret = _media_svc_sql_query(sql, uid);
642 if (ret != MS_MEDIA_ERR_NONE) {
643 SAFE_FREE(thumbpath_record);
647 /*Delete thumbnails*/
648 char *default_thumbnail_path = _media_svc_get_thumb_default_path(uid);
649 for (idx = 0; idx < invalid_count; idx++) {
650 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)) {
651 ret = _media_svc_remove_file(thumbpath_record[idx].thumbnail_path);
652 if (ret != MS_MEDIA_ERR_NONE)
653 media_svc_error("fail to remove thumbnail file.");
657 SAFE_FREE(thumbpath_record);
658 SAFE_FREE(default_thumbnail_path);
660 return MS_MEDIA_ERR_NONE;
663 int _media_svc_delete_invalid_folder_items(sqlite3 *handle, const char *storage_id, const char *folder_path, bool is_recursive, uid_t uid)
666 media_svc_thumbnailpath_s *thumbpath_record = NULL;
667 int invalid_count = 0;
668 int ret = MS_MEDIA_ERR_NONE;
669 char folder_uuid[MEDIA_SVC_UUID_SIZE+1] = {0,};
672 /*get folder uuid from DB*/
673 ret = _media_svc_get_folder_id_by_foldername(handle, storage_id, folder_path, folder_uuid, uid);
674 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
676 ret = __media_svc_count_invalid_folder_records_with_thumbnail(handle, storage_id, folder_path, folder_uuid, is_recursive, &invalid_count);
677 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
679 media_svc_debug("invalid count: %d", invalid_count);
681 if (invalid_count > 0) {
682 thumbpath_record = (media_svc_thumbnailpath_s *)calloc(invalid_count, sizeof(media_svc_thumbnailpath_s));
683 if (thumbpath_record == NULL) {
684 media_svc_error("fail to memory allocation");
685 return MS_MEDIA_ERR_OUT_OF_MEMORY;
688 ret = __media_svc_get_invalid_folder_records_with_thumbnail(handle, storage_id, folder_path, folder_uuid, is_recursive, invalid_count, thumbpath_record);
689 if (ret != MS_MEDIA_ERR_NONE) {
690 media_svc_error("error when get thumbnail record");
691 SAFE_FREE(thumbpath_record);
695 media_svc_debug("There is no item with thumbnail");
699 sql = sqlite3_mprintf("DELETE FROM '%s' WHERE validity = 0 AND path LIKE '%q/%%';", storage_id, folder_path);
701 sql = sqlite3_mprintf("DELETE FROM '%s' WHERE validity = 0 AND folder_uuid='%q';", storage_id, folder_uuid);
703 ret = _media_svc_sql_query(sql, uid);
705 if (ret != MS_MEDIA_ERR_NONE) {
706 SAFE_FREE(thumbpath_record);
710 /*Delete thumbnails*/
711 if (thumbpath_record != NULL) {
712 char *default_thumbnail_path = _media_svc_get_thumb_default_path(uid);
713 if (STRING_VALID(default_thumbnail_path)) {
714 for (idx = 0; idx < invalid_count; idx++) {
715 if ((strlen(thumbpath_record[idx].thumbnail_path) > 0) && (strncmp(thumbpath_record[idx].thumbnail_path, default_thumbnail_path, strlen(default_thumbnail_path)) != 0)) {
716 ret = _media_svc_remove_file(thumbpath_record[idx].thumbnail_path);
717 if (ret != MS_MEDIA_ERR_NONE)
718 media_svc_error("fail to remove thumbnail file.");
723 SAFE_FREE(thumbpath_record);
724 SAFE_FREE(default_thumbnail_path);
727 return MS_MEDIA_ERR_NONE;
730 int _media_svc_update_item_validity(const char *storage_id, const char *path, int validity, bool stack_query, uid_t uid)
732 int ret = MS_MEDIA_ERR_NONE;
734 char *sql = sqlite3_mprintf("UPDATE '%s' SET validity=%d WHERE path= '%q';", storage_id, validity, path);
737 ret = _media_svc_sql_query(sql, uid);
740 _media_svc_sql_query_add(&g_media_svc_item_validity_query_list, &sql);
746 int _media_svc_update_thumbnail_path(const char *storage_id, const char *path, const char *thumb_path, uid_t uid)
748 int ret = MS_MEDIA_ERR_NONE;
750 char *sql = sqlite3_mprintf("UPDATE '%s' SET thumbnail_path=%Q WHERE path= %Q;", storage_id, thumb_path, path);
752 ret = _media_svc_sql_query(sql, uid);
758 int _media_svc_update_storage_item_validity(const char *storage_id, media_svc_storage_type_e storage_type, int validity, uid_t uid)
760 int ret = MS_MEDIA_ERR_NONE;
762 char *sql = sqlite3_mprintf("UPDATE '%s' SET validity=%d WHERE storage_type=%d;", storage_id, validity, storage_type);
764 ret = _media_svc_sql_query(sql, uid);
770 int _media_svc_update_folder_item_validity(sqlite3 *handle, const char *storage_id, const char *folder_path, int validity, uid_t uid)
772 int ret = MS_MEDIA_ERR_NONE;
774 char folder_uuid[MEDIA_SVC_UUID_SIZE + 1] = {0, };
775 sqlite3_stmt *sql_stmt = NULL;
778 sql = sqlite3_mprintf("SELECT folder_uuid FROM '%s' WHERE path='%q' AND storage_uuid='%q'", MEDIA_SVC_DB_TABLE_FOLDER, folder_path, storage_id);
780 ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
781 if (ret != MS_MEDIA_ERR_NONE) {
782 if (ret == MS_MEDIA_ERR_DB_NO_RECORD)
783 media_svc_debug("folder not exist");
785 media_svc_error("error when get folder_id. err = [%d]", ret);
790 _strncpy_safe(folder_uuid, (const char *)sqlite3_column_text(sql_stmt, 0), MEDIA_SVC_UUID_SIZE + 1);
791 SQLITE3_FINALIZE(sql_stmt);
793 /*Update folder item validity*/
794 sql = sqlite3_mprintf("UPDATE '%s' SET validity=%d WHERE folder_uuid='%q';", storage_id, validity, folder_uuid);
796 ret = _media_svc_sql_query(sql, uid);
802 int _media_svc_update_recursive_folder_item_validity(const char *storage_id, const char *folder_path, int validity, uid_t uid)
804 int ret = MS_MEDIA_ERR_NONE;
806 /*Update folder item validity*/
807 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);
809 ret = _media_svc_sql_query(sql, uid);
815 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,
816 const char *file_name, int modified_time, const char *folder_uuid, const char *thumb_path, bool stack_query, uid_t uid)
818 /* update path, filename, modified_time, folder_uuid, thumbnail_path, */
819 /* played_count, last_played_time, last_played_position, favourite, storaget_type*/
821 int ret = MS_MEDIA_ERR_NONE;
824 if (thumb_path != NULL) {
825 sql = sqlite3_mprintf("UPDATE '%s' SET path=%Q, file_name=%Q, modified_time=%d, folder_uuid=%Q, thumbnail_path=%Q, storage_type=%d, \
826 played_count=0, last_played_time=0, last_played_position=0 WHERE path=%Q;",
827 storage_id, dest_path, file_name, modified_time, folder_uuid, thumb_path, dest_storage, src_path);
829 sql = sqlite3_mprintf("UPDATE '%s' SET path=%Q, file_name=%Q, modified_time=%d, folder_uuid=%Q, storage_type=%d, \
830 played_count=0, last_played_time=0, last_played_position=0 WHERE path=%Q;",
831 storage_id, dest_path, file_name, modified_time, folder_uuid, dest_storage, src_path);
835 ret = _media_svc_sql_query(sql, uid);
838 _media_svc_sql_query_add(&g_media_svc_move_item_query_list, &sql);
844 int _media_svc_list_query_do(media_svc_query_type_e query_type, uid_t uid)
846 int ret = MS_MEDIA_ERR_NONE;
848 ret = _media_svc_sql_begin_trans(uid);
849 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
851 if (query_type == MEDIA_SVC_QUERY_SET_ITEM_VALIDITY)
852 ret = _media_svc_sql_query_list(&g_media_svc_item_validity_query_list, uid);
853 else if (query_type == MEDIA_SVC_QUERY_MOVE_ITEM)
854 ret = _media_svc_sql_query_list(&g_media_svc_move_item_query_list, uid);
855 else if (query_type == MEDIA_SVC_QUERY_INSERT_ITEM)
856 ret = _media_svc_sql_query_list(&g_media_svc_insert_item_query_list, uid);
857 else if (query_type == MEDIA_SVC_QUERY_UPDATE_ITEM)
858 ret = _media_svc_sql_query_list(&g_media_svc_update_item_query_list, uid);
859 else if (query_type == MEDIA_SVC_QUERY_INSERT_FOLDER)
860 ret = _media_svc_sql_query_list(_media_svc_get_folder_list_ptr(), uid);
861 else if (query_type == MEDIA_SVC_QUERY_UPDATE_COMMON)
862 ret = _media_svc_sql_query_list(&g_media_svc_update_list, uid);
864 ret = MS_MEDIA_ERR_INVALID_PARAMETER;
866 if (ret != MS_MEDIA_ERR_NONE) {
867 media_svc_error("_media_svc_list_query_do failed. start rollback");
868 _media_svc_sql_rollback_trans(uid);
872 ret = _media_svc_sql_end_trans(uid);
873 if (ret != MS_MEDIA_ERR_NONE) {
874 media_svc_error("mb_svc_sqlite3_commit_trans failed.. Now start to rollback");
875 _media_svc_sql_rollback_trans(uid);
879 return MS_MEDIA_ERR_NONE;
882 int _media_svc_append_query_list(const char *query, uid_t uid)
884 int ret = MS_MEDIA_ERR_NONE;
886 g_media_svc_update_list = g_list_append(g_media_svc_update_list, (gpointer)query);
888 g_media_svc_update_list_count++;
890 if (g_media_svc_update_list_count >= MEDIA_SVC_MAX_COMMIT_SIZE) {
891 ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_UPDATE_COMMON, uid);
892 g_media_svc_update_list_count = 0;
898 int _media_svc_get_burst_id(sqlite3 *handle, const char *storage_id, int *id)
900 int ret = MS_MEDIA_ERR_NONE;
902 sqlite3_stmt *sql_stmt = NULL;
903 char *sql = sqlite3_mprintf("SELECT max(CAST(burst_id AS INTEGER)) FROM '%s'", storage_id);
905 ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
907 if (ret != MS_MEDIA_ERR_NONE) {
908 media_svc_error("error when _media_svc_get_burst_id. err = [%d]", ret);
912 cur_id = sqlite3_column_int(sql_stmt, 0);
914 SQLITE3_FINALIZE(sql_stmt);
916 return MS_MEDIA_ERR_NONE;
919 int _media_svc_get_noti_info(sqlite3 *handle, const char *storage_id, const char *path, int update_item, media_svc_noti_item **item)
921 int ret = MS_MEDIA_ERR_NONE;
922 sqlite3_stmt *sql_stmt = NULL;
924 int is_root_dir = FALSE;
927 media_svc_error("invalid parameter");
928 return MS_MEDIA_ERR_INVALID_PARAMETER;
931 if (update_item == MS_MEDIA_ITEM_FILE)
932 sql = sqlite3_mprintf("SELECT media_uuid, media_type, mime_type FROM '%s' WHERE path=%Q", storage_id, path);
933 else if (update_item == MS_MEDIA_ITEM_DIRECTORY)
934 sql = sqlite3_mprintf("SELECT folder_uuid FROM '%s' WHERE path=%Q AND storage_uuid='%s'", MEDIA_SVC_DB_TABLE_FOLDER, path, storage_id);
936 media_svc_error("_media_svc_get_noti_info failed : update item");
937 return MS_MEDIA_ERR_INVALID_PARAMETER;
940 ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
942 if (ret != MS_MEDIA_ERR_NONE) {
943 if (ret == MS_MEDIA_ERR_DB_NO_RECORD && update_item == MS_MEDIA_ITEM_DIRECTORY) {
944 media_svc_debug("This is root directory of media");
948 media_svc_error("error when _media_svc_get_noti_info. err = [%d]", ret);
953 *item = calloc(1, sizeof(media_svc_noti_item));
955 media_svc_error("_media_svc_get_noti_info failed : calloc");
956 return MS_MEDIA_ERR_OUT_OF_MEMORY;
959 if (update_item == MS_MEDIA_ITEM_FILE) {
960 (*item)->media_uuid = g_strdup((const char *)sqlite3_column_text(sql_stmt, 0));
961 (*item)->media_type = sqlite3_column_int(sql_stmt, 1);
962 (*item)->mime_type = g_strdup((const char *)sqlite3_column_text(sql_stmt, 2));
963 } else if (update_item == MS_MEDIA_ITEM_DIRECTORY) {
965 (*item)->media_uuid = NULL;
967 (*item)->media_uuid = g_strdup((const char *)sqlite3_column_text(sql_stmt, 0));
970 SQLITE3_FINALIZE(sql_stmt);
972 return MS_MEDIA_ERR_NONE;
975 int _media_svc_count_invalid_folder_items(sqlite3 *handle, const char *storage_id, const char *folder_path, int *count)
977 int ret = MS_MEDIA_ERR_NONE;
978 sqlite3_stmt *sql_stmt = NULL;
980 char *sql = sqlite3_mprintf("SELECT count(*) FROM '%s' WHERE validity=0 AND path LIKE '%q/%%'", storage_id, folder_path);
982 ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
984 if (ret != MS_MEDIA_ERR_NONE) {
985 media_svc_error("error when _media_svc_count_invalid_folder_items. err = [%d]", ret);
989 *count = sqlite3_column_int(sql_stmt, 0);
991 SQLITE3_FINALIZE(sql_stmt);
993 return MS_MEDIA_ERR_NONE;
996 int _media_svc_get_thumbnail_count(sqlite3 *handle, const char *storage_id, const char *thumb_path, int *count)
998 int ret = MS_MEDIA_ERR_NONE;
999 sqlite3_stmt *sql_stmt = NULL;
1000 char *sql = sqlite3_mprintf("SELECT count(*) FROM '%s' WHERE thumbnail_path=%Q", storage_id, thumb_path);
1002 ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
1004 if (ret != MS_MEDIA_ERR_NONE) {
1005 media_svc_error("error when _media_svc_get_thumbnail_count. err = [%d]", ret);
1009 *count = sqlite3_column_int(sql_stmt, 0);
1011 SQLITE3_FINALIZE(sql_stmt);
1013 return MS_MEDIA_ERR_NONE;
1016 int _media_svc_get_fileinfo_by_path(sqlite3 *handle, const char *storage_id, const char *path, time_t *modified_time, unsigned long long *size)
1018 int ret = MS_MEDIA_ERR_NONE;
1019 sqlite3_stmt *sql_stmt = NULL;
1020 char *sql = sqlite3_mprintf("SELECT modified_time, size FROM '%s' WHERE path='%q'", storage_id, path);
1022 ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
1024 if (ret != MS_MEDIA_ERR_NONE) {
1025 media_svc_error("error when _media_svc_get_fileinfo_by_path. err = [%d]", ret);
1029 *modified_time = (int)sqlite3_column_int(sql_stmt, 0);
1030 *size = (unsigned long long)sqlite3_column_int64(sql_stmt, 1);
1032 SQLITE3_FINALIZE(sql_stmt);
1034 return MS_MEDIA_ERR_NONE;
1037 int _media_svc_change_validity_item_batch(const char *storage_id, const char *path, int des_validity, int src_validity, uid_t uid)
1039 int ret = MS_MEDIA_ERR_NONE;
1041 char *sql = sqlite3_mprintf("UPDATE '%s' SET validity=%d WHERE validity=%d AND path LIKE '%q%%'", storage_id, des_validity, src_validity, path);
1043 ret = _media_svc_sql_query(sql, uid);
1049 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)
1051 int ret = MS_MEDIA_ERR_NONE;
1052 char *burst_id = NULL;
1054 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";
1056 char *sql = sqlite3_mprintf("INSERT INTO '%s' (%s) VALUES (%Q, %Q, %Q, %Q, %d, %Q, %lld, %d, %d, %d, %d, %d, %Q, %Q);",
1057 storage_id, db_fields,
1058 content_info->media_uuid,
1059 content_info->folder_uuid,
1061 content_info->file_name,
1062 content_info->media_type,
1063 content_info->mime_type,
1065 content_info->added_time,
1066 content_info->modified_time,
1067 content_info->is_drm,
1068 content_info->storage_type,
1069 content_info->timeline,
1075 sqlite3_free(burst_id);
1079 media_svc_debug("MAKE PASS 1 QUERY END");
1082 ret = _media_svc_sql_query(sql, uid);
1084 if (ret != MS_MEDIA_ERR_NONE) {
1085 media_svc_error("failed to insert item");
1089 media_svc_debug("query : %s", sql);
1090 _media_svc_sql_query_add(&g_media_svc_insert_item_query_list, &sql);
1092 media_svc_debug("END");
1093 return MS_MEDIA_ERR_NONE;
1096 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)
1098 int ret = MS_MEDIA_ERR_NONE;
1100 media_svc_debug_fenter();
1102 /*Update Pinyin If Support Pinyin*/
1103 if (_media_svc_check_pinyin_support()) {
1104 if (STRING_VALID(content_info->file_name))
1105 _media_svc_get_pinyin_str(content_info->file_name, &content_info->file_name_pinyin);
1106 if (STRING_VALID(content_info->media_meta.title))
1107 _media_svc_get_pinyin_str(content_info->media_meta.title, &content_info->media_meta.title_pinyin);
1108 if (STRING_VALID(content_info->media_meta.album))
1109 _media_svc_get_pinyin_str(content_info->media_meta.album, &content_info->media_meta.album_pinyin);
1110 if (STRING_VALID(content_info->media_meta.artist))
1111 _media_svc_get_pinyin_str(content_info->media_meta.artist, &content_info->media_meta.artist_pinyin);
1112 if (STRING_VALID(content_info->media_meta.album_artist))
1113 _media_svc_get_pinyin_str(content_info->media_meta.album_artist, &content_info->media_meta.album_artist_pinyin);
1114 if (STRING_VALID(content_info->media_meta.genre))
1115 _media_svc_get_pinyin_str(content_info->media_meta.genre, &content_info->media_meta.genre_pinyin);
1116 if (STRING_VALID(content_info->media_meta.composer))
1117 _media_svc_get_pinyin_str(content_info->media_meta.composer, &content_info->media_meta.composer_pinyin);
1118 if (STRING_VALID(content_info->media_meta.copyright))
1119 _media_svc_get_pinyin_str(content_info->media_meta.copyright, &content_info->media_meta.copyright_pinyin);
1120 if (STRING_VALID(content_info->media_meta.description))
1121 _media_svc_get_pinyin_str(content_info->media_meta.description, &content_info->media_meta.description_pinyin);
1124 char *sql = sqlite3_mprintf("UPDATE '%s' SET \
1125 thumbnail_path=%Q, title=%Q, album_id=%d, album=%Q, artist=%Q, album_artist=%Q, genre=%Q, composer=%Q, year=%Q, \
1126 recorded_date=%Q, copyright=%Q, track_num=%Q, description=%Q, bitrate=%d, bitpersample=%d, samplerate=%d, channel=%d, \
1127 duration=%d, longitude=%.6f, latitude=%.6f, altitude=%.6f, width=%d, height=%d, datetaken=%Q, orientation=%d, exposure_time=%Q,\
1128 fnumber=%.6f, iso=%d, model=%Q, rating=%d, weather=%Q, file_name_pinyin=%Q, title_pinyin=%Q, album_pinyin=%Q, \
1129 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;",
1131 /* content_info->folder_uuid, */
1132 content_info->thumbnail_path,
1133 content_info->media_meta.title,
1134 content_info->album_id,
1135 content_info->media_meta.album,
1136 content_info->media_meta.artist,
1137 content_info->media_meta.album_artist,
1138 content_info->media_meta.genre,
1139 content_info->media_meta.composer,
1140 content_info->media_meta.year,
1141 content_info->media_meta.recorded_date,
1142 content_info->media_meta.copyright,
1143 content_info->media_meta.track_num,
1144 content_info->media_meta.description,
1145 content_info->media_meta.bitrate,
1146 content_info->media_meta.bitpersample,
1147 content_info->media_meta.samplerate,
1148 content_info->media_meta.channel,
1149 content_info->media_meta.duration,
1150 content_info->media_meta.longitude,
1151 content_info->media_meta.latitude,
1152 content_info->media_meta.altitude,
1153 content_info->media_meta.width,
1154 content_info->media_meta.height,
1155 content_info->media_meta.datetaken,
1156 content_info->media_meta.orientation,
1157 content_info->media_meta.exposure_time,
1158 content_info->media_meta.fnumber,
1159 content_info->media_meta.iso,
1160 content_info->media_meta.model,
1161 content_info->media_meta.rating,
1162 content_info->media_meta.weather,
1163 content_info->file_name_pinyin,
1164 content_info->media_meta.title_pinyin,
1165 content_info->media_meta.album_pinyin,
1166 content_info->media_meta.artist_pinyin,
1167 content_info->media_meta.album_artist_pinyin,
1168 content_info->media_meta.genre_pinyin,
1169 content_info->media_meta.composer_pinyin,
1170 content_info->media_meta.copyright_pinyin,
1171 content_info->media_meta.description_pinyin,
1172 content_info->media_meta.is_360,
1177 ret = _media_svc_sql_query(sql, uid);
1179 if (ret != MS_MEDIA_ERR_NONE) {
1181 media_svc_error("failed to insert item");
1185 /*media_svc_debug("query : %s", sql);*/
1186 _media_svc_sql_query_add(&g_media_svc_update_item_query_list, &sql);
1189 media_svc_debug_fleave();
1191 return MS_MEDIA_ERR_NONE;