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"
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;
44 static int __media_svc_count_invalid_records_with_thumbnail(sqlite3 *handle, const char *storage_id, media_svc_storage_type_e storage_type, int *count);
45 static int __media_svc_get_invalid_records_with_thumbnail(sqlite3 *handle, const char *storage_id, media_svc_storage_type_e storage_type,
46 int count, media_svc_thumbnailpath_s *thumb_path);
47 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);
48 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);
50 static int __media_svc_count_invalid_records_with_thumbnail(sqlite3 *handle, const char *storage_id, media_svc_storage_type_e storage_type, int *count)
52 int ret = MS_MEDIA_ERR_NONE;
53 sqlite3_stmt *sql_stmt = NULL;
54 char *sql = sqlite3_mprintf("SELECT count(*) FROM '%s' WHERE validity=0 AND storage_type=%d AND thumbnail_path IS NOT NULL",
55 storage_id, storage_type);
57 ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
59 if (ret != MS_MEDIA_ERR_NONE) {
60 media_svc_error("error when __media_svc_count_invalid_records_with_thumbnail. err = [%d]", ret);
64 *count = sqlite3_column_int(sql_stmt, 0);
66 SQLITE3_FINALIZE(sql_stmt);
68 return MS_MEDIA_ERR_NONE;
72 static int __media_svc_get_invalid_records_with_thumbnail(sqlite3 *handle, const char *storage_id, media_svc_storage_type_e storage_type,
73 int count, media_svc_thumbnailpath_s * thumb_path)
75 int ret = MS_MEDIA_ERR_NONE;
76 sqlite3_stmt *sql_stmt = NULL;
79 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",
80 MEDIA_SVC_DB_TABLE_MEDIA, storage_type);
82 media_svc_debug("[SQL query] : %s", sql);
84 ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
85 if (ret != MS_MEDIA_ERR_NONE) {
86 media_svc_error("error when __media_svc_get_invalid_records_with_thumbnail. err = [%d]", ret);
90 while (sqlite3_step(sql_stmt) == SQLITE_ROW) {
91 _strncpy_safe(thumb_path[idx].thumbnail_path, (const char *)sqlite3_column_text(sql_stmt, 0), sizeof(thumb_path[idx]));
92 /*media_svc_debug("thumb_path[%d]=[%s]", idx, thumb_path[idx].thumbnail_path); */
96 SQLITE3_FINALIZE(sql_stmt);
98 return MS_MEDIA_ERR_NONE;
101 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)
103 int ret = MS_MEDIA_ERR_NONE;
104 sqlite3_stmt *sql_stmt = NULL;
108 sql = sqlite3_mprintf("SELECT count(*) FROM '%s' WHERE validity=0 AND path LIKE '%q/%%' AND thumbnail_path IS NOT NULL", storage_id, folder_path);
110 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);
142 media_svc_debug("[SQL query] : %s", sql);
144 ret = _media_svc_sql_prepare_to_step_simple(handle, sql, &sql_stmt);
145 if (ret != MS_MEDIA_ERR_NONE) {
146 media_svc_error("error when __media_svc_get_invalid_folder_records_with_thumbnail. err = [%d]", ret);
150 while (sqlite3_step(sql_stmt) == SQLITE_ROW) {
151 _strncpy_safe(thumb_path[idx].thumbnail_path, (const char *)sqlite3_column_text(sql_stmt, 0), sizeof(thumb_path[idx]));
155 SQLITE3_FINALIZE(sql_stmt);
157 return MS_MEDIA_ERR_NONE;
160 int _media_svc_count_record_with_path(sqlite3 *handle, const char *storage_id, const char *path, int *count)
162 int ret = MS_MEDIA_ERR_NONE;
163 sqlite3_stmt *sql_stmt = NULL;
165 char *sql = sqlite3_mprintf("SELECT count(*) FROM '%s' WHERE path='%q'", storage_id, path);
167 ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
169 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
171 *count = sqlite3_column_int(sql_stmt, 0);
173 SQLITE3_FINALIZE(sql_stmt);
175 return MS_MEDIA_ERR_NONE;
178 char *_media_svc_get_thumb_default_path(uid_t uid)
180 char *result_passwd = NULL;
181 struct group *grpinfo = NULL;
182 if (uid == getuid()) {
183 grpinfo = getgrnam("users");
184 if (grpinfo == NULL) {
185 media_svc_error("getgrnam(users) returns NULL !");
188 result_passwd = g_strdup(MEDIA_SVC_THUMB_DEFAULT_PATH);
190 char passwd_str[MEDIA_SVC_PATHNAME_SIZE] = {0, };
191 struct passwd *userinfo = getpwuid(uid);
192 if (userinfo == NULL) {
193 media_svc_error("getpwuid(%d) returns NULL !", uid);
196 grpinfo = getgrnam("users");
197 if (grpinfo == NULL) {
198 media_svc_error("getgrnam(users) returns NULL !");
201 /* Compare git_t type and not group name */
202 if (grpinfo->gr_gid != userinfo->pw_gid) {
203 media_svc_error("UID [%d] does not belong to 'users' group!", uid);
206 sprintf(passwd_str, "%s/share/media/.thumb/thumb_default.png", userinfo->pw_dir);
207 result_passwd = g_strdup(passwd_str);
210 return result_passwd;
213 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)
215 int ret = MS_MEDIA_ERR_NONE;
216 char *burst_id = NULL;
217 int ini_val = _media_svc_get_ini_value();
219 const char *db_fields = "media_uuid, path, file_name, media_type, mime_type, size, added_time, modified_time, folder_uuid, \
220 thumbnail_path, title, album_id, album, artist, album_artist, genre, composer, year, recorded_date, copyright, track_num, description, \
221 category, keyword, location_tag, content_name, age_rating, author, provider, last_played_time, played_count, favourite, \
222 bitrate, bitpersample, samplerate, channel, duration, longitude, latitude, altitude, exposure_time, fnumber, iso, model, width, height, datetaken, orientation, \
223 rating, is_drm, storage_type, burst_id, timeline, weather, sync_status, \
224 file_name_pinyin, title_pinyin, album_pinyin, artist_pinyin, album_artist_pinyin, genre_pinyin, composer_pinyin, copyright_pinyin, description_pinyin, storage_uuid";
226 /* This sql is due to sqlite3_mprintf's wrong operation when using floating point in the text format */
227 /* This code will be removed when sqlite3_mprintf works clearly */
228 char *test_sql = sqlite3_mprintf("%f, %f, %f", content_info->media_meta.longitude, content_info->media_meta.latitude, content_info->media_meta.altitude);
229 sqlite3_free(test_sql);
232 int burst_id_int = 0;
233 ret = _media_svc_get_burst_id(handle, storage_id, &burst_id_int);
234 if (ret != MS_MEDIA_ERR_NONE) {
238 if (burst_id_int > 0) {
239 media_svc_debug("Burst id : %d", burst_id_int);
240 burst_id = sqlite3_mprintf("%d", burst_id_int);
243 /* Get thumbnail for burst shot */
245 char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, };
249 ret = _media_svc_request_thumbnail_with_origin_size(content_info->path, thumb_path, sizeof(thumb_path), &width, &height, uid);
250 if (ret == MS_MEDIA_ERR_NONE) {
251 ret = __media_svc_malloc_and_strncpy(&(content_info->thumbnail_path), thumb_path);
252 if (ret != MS_MEDIA_ERR_NONE) {
253 content_info->thumbnail_path = NULL;
257 if (content_info->media_meta.width <= 0)
258 content_info->media_meta.width = width;
260 if (content_info->media_meta.height <= 0)
261 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);",
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
362 sqlite3_free(burst_id);
367 ret = _media_svc_sql_query(handle, sql, uid);
369 if (ret != MS_MEDIA_ERR_NONE) {
370 media_svc_error("failed to insert item");
374 media_svc_debug("query : %s", sql);
375 _media_svc_sql_query_add(&g_media_svc_insert_item_query_list, &sql);
378 return MS_MEDIA_ERR_NONE;
381 int _media_svc_update_meta_with_data(sqlite3 *handle, media_svc_content_info_s *content_info)
383 int ret = MS_MEDIA_ERR_NONE;
385 /* This sql is due to sqlite3_mprintf's wrong operation when using floating point in the text format */
386 /* This code will be removed when sqlite3_mprintf works clearly */
387 char *test_sql = sqlite3_mprintf("%f, %f, %f", content_info->media_meta.longitude, content_info->media_meta.latitude, content_info->media_meta.altitude);
388 sqlite3_free(test_sql);
390 /*Update Pinyin If Support Pinyin*/
391 if (_media_svc_check_pinyin_support()) {
392 if (STRING_VALID(content_info->file_name))
393 _media_svc_get_pinyin_str(content_info->file_name, &content_info->file_name_pinyin);
394 if (STRING_VALID(content_info->media_meta.title))
395 _media_svc_get_pinyin_str(content_info->media_meta.title, &content_info->media_meta.title_pinyin);
396 if (STRING_VALID(content_info->media_meta.album))
397 _media_svc_get_pinyin_str(content_info->media_meta.album, &content_info->media_meta.album_pinyin);
398 if (STRING_VALID(content_info->media_meta.artist))
399 _media_svc_get_pinyin_str(content_info->media_meta.artist, &content_info->media_meta.artist_pinyin);
400 if (STRING_VALID(content_info->media_meta.album_artist))
401 _media_svc_get_pinyin_str(content_info->media_meta.album_artist, &content_info->media_meta.album_artist_pinyin);
402 if (STRING_VALID(content_info->media_meta.genre))
403 _media_svc_get_pinyin_str(content_info->media_meta.genre, &content_info->media_meta.genre_pinyin);
404 if (STRING_VALID(content_info->media_meta.composer))
405 _media_svc_get_pinyin_str(content_info->media_meta.composer, &content_info->media_meta.composer_pinyin);
406 if (STRING_VALID(content_info->media_meta.copyright))
407 _media_svc_get_pinyin_str(content_info->media_meta.copyright, &content_info->media_meta.copyright_pinyin);
408 if (STRING_VALID(content_info->media_meta.description))
409 _media_svc_get_pinyin_str(content_info->media_meta.description, &content_info->media_meta.description_pinyin);
412 char *sql = sqlite3_mprintf("UPDATE %s SET title=%Q, album=%Q, artist=%Q, album_artist=%Q, genre=%Q, composer=%Q, copyright=%Q, description=%Q, \
413 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 \
415 MEDIA_SVC_DB_TABLE_MEDIA,
416 content_info->media_meta.title,
417 content_info->media_meta.album,
418 content_info->media_meta.artist,
419 content_info->media_meta.album_artist,
420 content_info->media_meta.genre,
421 content_info->media_meta.composer,
422 content_info->media_meta.copyright,
423 content_info->media_meta.description,
424 content_info->file_name_pinyin,
425 content_info->media_meta.title_pinyin,
426 content_info->media_meta.album_pinyin,
427 content_info->media_meta.artist_pinyin,
428 content_info->media_meta.album_artist_pinyin,
429 content_info->media_meta.genre_pinyin,
430 content_info->media_meta.composer_pinyin,
431 content_info->media_meta.copyright_pinyin,
432 content_info->media_meta.description_pinyin,
437 media_svc_debug("query : %s", sql);
438 _media_svc_sql_query_add(&g_media_svc_update_item_query_list, &sql);
440 media_svc_error("sqlite3_mprintf failed");
441 ret = MS_MEDIA_ERR_OUT_OF_MEMORY;
447 int _media_svc_update_item_with_data(sqlite3 *handle, const char *storage_id, media_svc_content_info_s *content_info, uid_t uid)
449 int ret = MS_MEDIA_ERR_NONE;
451 /* This sql is due to sqlite3_mprintf's wrong operation when using floating point in the text format */
452 /* This code will be removed when sqlite3_mprintf works clearly */
453 char *test_sql = sqlite3_mprintf("%f, %f, %f", content_info->media_meta.longitude, content_info->media_meta.latitude, content_info->media_meta.altitude);
454 sqlite3_free(test_sql);
456 /*Update Pinyin If Support Pinyin*/
457 if (_media_svc_check_pinyin_support()) {
458 if (STRING_VALID(content_info->file_name))
459 _media_svc_get_pinyin_str(content_info->file_name, &content_info->file_name_pinyin);
460 if (STRING_VALID(content_info->media_meta.title))
461 _media_svc_get_pinyin_str(content_info->media_meta.title, &content_info->media_meta.title_pinyin);
462 if (STRING_VALID(content_info->media_meta.album))
463 _media_svc_get_pinyin_str(content_info->media_meta.album, &content_info->media_meta.album_pinyin);
464 if (STRING_VALID(content_info->media_meta.artist))
465 _media_svc_get_pinyin_str(content_info->media_meta.artist, &content_info->media_meta.artist_pinyin);
466 if (STRING_VALID(content_info->media_meta.album_artist))
467 _media_svc_get_pinyin_str(content_info->media_meta.album_artist, &content_info->media_meta.album_artist_pinyin);
468 if (STRING_VALID(content_info->media_meta.genre))
469 _media_svc_get_pinyin_str(content_info->media_meta.genre, &content_info->media_meta.genre_pinyin);
470 if (STRING_VALID(content_info->media_meta.composer))
471 _media_svc_get_pinyin_str(content_info->media_meta.composer, &content_info->media_meta.composer_pinyin);
472 if (STRING_VALID(content_info->media_meta.copyright))
473 _media_svc_get_pinyin_str(content_info->media_meta.copyright, &content_info->media_meta.copyright_pinyin);
474 if (STRING_VALID(content_info->media_meta.description))
475 _media_svc_get_pinyin_str(content_info->media_meta.description, &content_info->media_meta.description_pinyin);
478 char *sql = sqlite3_mprintf("UPDATE '%s' SET \
479 size=%lld, modified_time=%d, thumbnail_path=%Q, title=%Q, album_id=%d, album=%Q, artist=%Q, album_artist=%Q, genre=%Q, \
480 composer=%Q, year=%Q, recorded_date=%Q, copyright=%Q, track_num=%Q, description=%Q, \
481 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, \
482 orientation=%d WHERE path=%Q",
485 content_info->modified_time,
486 content_info->thumbnail_path,
487 content_info->media_meta.title,
488 content_info->album_id,
489 content_info->media_meta.album,
490 content_info->media_meta.artist,
491 content_info->media_meta.album_artist,
492 content_info->media_meta.genre,
493 content_info->media_meta.composer,
494 content_info->media_meta.year,
495 content_info->media_meta.recorded_date,
496 content_info->media_meta.copyright,
497 content_info->media_meta.track_num,
498 content_info->media_meta.description,
499 content_info->media_meta.bitrate,
500 content_info->media_meta.bitpersample,
501 content_info->media_meta.samplerate,
502 content_info->media_meta.channel,
503 content_info->media_meta.duration,
504 content_info->media_meta.longitude,
505 content_info->media_meta.latitude,
506 content_info->media_meta.altitude,
507 content_info->media_meta.exposure_time,
508 content_info->media_meta.fnumber,
509 content_info->media_meta.iso,
510 content_info->media_meta.model,
511 content_info->media_meta.width,
512 content_info->media_meta.height,
513 content_info->media_meta.datetaken,
514 content_info->media_meta.orientation,
518 ret = _media_svc_sql_query(handle, sql, uid);
523 int _media_svc_get_thumbnail_path_by_path(sqlite3 *handle, const char *storage_id, const char *path, char *thumbnail_path)
525 int ret = MS_MEDIA_ERR_NONE;
526 sqlite3_stmt *sql_stmt = NULL;
528 char *sql = sqlite3_mprintf("SELECT thumbnail_path FROM '%s' WHERE path='%q'", storage_id, path);
530 ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
532 if (ret != MS_MEDIA_ERR_NONE) {
533 if (ret == MS_MEDIA_ERR_DB_NO_RECORD) {
534 media_svc_debug("there is no thumbnail.");
536 media_svc_error("error when _media_svc_get_thumbnail_path_by_path. err = [%d]", ret);
541 _strncpy_safe(thumbnail_path, (const char *)sqlite3_column_text(sql_stmt, 0), MEDIA_SVC_PATHNAME_SIZE);
543 SQLITE3_FINALIZE(sql_stmt);
545 return MS_MEDIA_ERR_NONE;
548 int _media_svc_get_media_type_by_path(sqlite3 *handle, const char *storage_id, const char *path, int *media_type)
550 int ret = MS_MEDIA_ERR_NONE;
551 sqlite3_stmt *sql_stmt = NULL;
553 char *sql = sqlite3_mprintf("SELECT media_type FROM '%s' WHERE path='%q'", storage_id, path);
555 ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
557 if (ret != MS_MEDIA_ERR_NONE) {
558 media_svc_error("error when _media_svc_get_media_type_by_path. err = [%d]", ret);
562 *media_type = sqlite3_column_int(sql_stmt, 0);
564 SQLITE3_FINALIZE(sql_stmt);
566 return MS_MEDIA_ERR_NONE;
569 int _media_svc_delete_item_by_path(sqlite3 *handle, const char *storage_id, const char *path, bool stack_query, uid_t uid)
571 int ret = MS_MEDIA_ERR_NONE;
572 char *sql = sqlite3_mprintf("DELETE FROM '%s' WHERE path='%q'", storage_id, path);
575 ret = _media_svc_sql_query(handle, sql, uid);
577 if (ret != MS_MEDIA_ERR_NONE) {
578 media_svc_error("failed to delete item");
582 media_svc_debug("query : %s", sql);
583 _media_svc_sql_query_add(&g_media_svc_insert_item_query_list, &sql);
589 int _media_svc_truncate_table(sqlite3 *handle, const char *storage_id, media_svc_storage_type_e storage_type, uid_t uid)
591 int ret = MS_MEDIA_ERR_NONE;
593 char *sql = sqlite3_mprintf("DELETE FROM '%s' where storage_type=%d", storage_id, storage_type);
595 ret = _media_svc_sql_query(handle, sql, uid);
601 int _media_svc_delete_invalid_items(sqlite3 *handle, const char *storage_id, media_svc_storage_type_e storage_type, uid_t uid)
604 media_svc_thumbnailpath_s *thumbpath_record = NULL;
605 int invalid_count = 0;
606 int ret = MS_MEDIA_ERR_NONE;
608 ret = __media_svc_count_invalid_records_with_thumbnail(handle, storage_id, storage_type, &invalid_count);
609 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
611 media_svc_debug("invalid count: %d", invalid_count);
613 if (invalid_count > 0) {
614 thumbpath_record = (media_svc_thumbnailpath_s *)calloc(invalid_count, sizeof(media_svc_thumbnailpath_s));
615 if (thumbpath_record == NULL) {
616 media_svc_error("fail to memory allocation");
617 return MS_MEDIA_ERR_OUT_OF_MEMORY;
620 ret = __media_svc_get_invalid_records_with_thumbnail(handle, storage_id, storage_type, invalid_count, thumbpath_record);
621 if (ret != MS_MEDIA_ERR_NONE) {
622 media_svc_error("error when get thumbnail record");
623 SAFE_FREE(thumbpath_record);
627 media_svc_debug("There is no item with thumbnail");
630 char *sql = sqlite3_mprintf("DELETE FROM '%s' WHERE validity = 0", storage_id);
632 ret = _media_svc_sql_query(handle, sql, uid);
634 if (ret != MS_MEDIA_ERR_NONE) {
635 SAFE_FREE(thumbpath_record);
639 /*Delete thumbnails*/
640 char *default_thumbnail_path = _media_svc_get_thumb_default_path(uid);
641 for (idx = 0; idx < invalid_count; idx++) {
642 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)) {
643 ret = _media_svc_remove_file(thumbpath_record[idx].thumbnail_path);
644 if (ret != MS_MEDIA_ERR_NONE) {
645 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);
697 ret = _media_svc_sql_query(handle, sql, uid);
699 if (ret != MS_MEDIA_ERR_NONE) {
700 SAFE_FREE(thumbpath_record);
704 /*Delete thumbnails*/
705 if (thumbpath_record != NULL) {
706 char *default_thumbnail_path = _media_svc_get_thumb_default_path(uid);
707 if (STRING_VALID(default_thumbnail_path)) {
708 for (idx = 0; idx < invalid_count; idx++) {
709 if ((strlen(thumbpath_record[idx].thumbnail_path) > 0) && (strncmp(thumbpath_record[idx].thumbnail_path, default_thumbnail_path, strlen(default_thumbnail_path)) != 0)) {
710 ret = _media_svc_remove_file(thumbpath_record[idx].thumbnail_path);
711 if (ret != MS_MEDIA_ERR_NONE) {
712 media_svc_error("fail to remove thumbnail file.");
718 SAFE_FREE(thumbpath_record);
719 SAFE_FREE(default_thumbnail_path);
722 return MS_MEDIA_ERR_NONE;
725 int _media_svc_update_item_validity(sqlite3 *handle, const char *storage_id, const char *path, int validity, bool stack_query, uid_t uid)
727 int ret = MS_MEDIA_ERR_NONE;
729 char *sql = sqlite3_mprintf("UPDATE '%s' SET validity=%d WHERE path= '%q'", storage_id, validity, path);
732 ret = _media_svc_sql_query(handle, sql, uid);
735 _media_svc_sql_query_add(&g_media_svc_item_validity_query_list, &sql);
741 int _media_svc_update_thumbnail_path(sqlite3 *handle, const char *storage_id, const char *path, const char *thumb_path, uid_t uid)
743 int ret = MS_MEDIA_ERR_NONE;
745 char *sql = sqlite3_mprintf("UPDATE '%s' SET thumbnail_path=%Q WHERE path= %Q", storage_id, thumb_path, path);
747 ret = _media_svc_sql_query(handle, sql, uid);
753 int _media_svc_update_storage_item_validity(sqlite3 *handle, const char *storage_id, media_svc_storage_type_e storage_type, int validity, uid_t uid)
755 int ret = MS_MEDIA_ERR_NONE;
757 char *sql = sqlite3_mprintf("UPDATE '%s' SET validity=%d WHERE storage_type=%d", storage_id, validity, storage_type);
759 ret = _media_svc_sql_query(handle, sql, uid);
765 int _media_svc_update_folder_item_validity(sqlite3 *handle, const char *storage_id, const char *folder_path, int validity, uid_t uid)
767 int ret = MS_MEDIA_ERR_NONE;
769 char folder_uuid[MEDIA_SVC_UUID_SIZE + 1] = {0, };
770 sqlite3_stmt *sql_stmt = NULL;
773 sql = sqlite3_mprintf("SELECT folder_uuid FROM '%s' WHERE path='%q' AND storage_uuid='%q'", MEDIA_SVC_DB_TABLE_FOLDER, folder_path, storage_id);
775 ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
776 if (ret != MS_MEDIA_ERR_NONE) {
777 if (ret == MS_MEDIA_ERR_DB_NO_RECORD)
778 media_svc_debug("folder not exist");
780 media_svc_error("error when get folder_id. err = [%d]", ret);
785 _strncpy_safe(folder_uuid, (const char *)sqlite3_column_text(sql_stmt, 0), MEDIA_SVC_UUID_SIZE + 1);
786 SQLITE3_FINALIZE(sql_stmt);
788 /*Update folder item validity*/
789 sql = sqlite3_mprintf("UPDATE '%s' SET validity=%d WHERE folder_uuid='%q'", storage_id, validity, folder_uuid);
791 ret = _media_svc_sql_query(handle, sql, uid);
797 int _media_svc_update_recursive_folder_item_validity(sqlite3 *handle, const char *storage_id, const char *folder_path, int validity, uid_t uid)
799 int ret = MS_MEDIA_ERR_NONE;
801 /*Update folder item validity*/
802 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);
804 ret = _media_svc_sql_query(handle, sql, uid);
810 int _media_svc_update_item_by_path(sqlite3 *handle, const char *storage_id, const char *src_path, media_svc_storage_type_e dest_storage, const char *dest_path,
811 const char *file_name, int modified_time, const char *folder_uuid, const char *thumb_path, bool stack_query, uid_t uid)
813 /* update path, filename, modified_time, folder_uuid, thumbnail_path, */
814 /* played_count, last_played_time, last_played_position, favourite, storaget_type*/
816 int ret = MS_MEDIA_ERR_NONE;
819 if (thumb_path != NULL) {
820 sql = sqlite3_mprintf("UPDATE '%s' SET \
821 path=%Q, file_name=%Q, modified_time=%d, folder_uuid=%Q, thumbnail_path=%Q, storage_type=%d, \
822 played_count=0, last_played_time=0, last_played_position=0 \
824 storage_id, dest_path, file_name, modified_time, folder_uuid, thumb_path, dest_storage, src_path);
826 sql = sqlite3_mprintf("UPDATE '%s' SET \
827 path=%Q, file_name=%Q, modified_time=%d, folder_uuid=%Q, storage_type=%d, \
828 played_count=0, last_played_time=0, last_played_position=0 \
830 storage_id, dest_path, file_name, modified_time, folder_uuid, dest_storage, src_path);
834 ret = _media_svc_sql_query(handle, sql, uid);
837 _media_svc_sql_query_add(&g_media_svc_move_item_query_list, &sql);
843 int _media_svc_list_query_do(sqlite3 *handle, media_svc_query_type_e query_type, uid_t uid)
845 int ret = MS_MEDIA_ERR_NONE;
847 ret = _media_svc_sql_begin_trans(handle, uid);
848 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
850 if (query_type == MEDIA_SVC_QUERY_SET_ITEM_VALIDITY)
851 ret = _media_svc_sql_query_list(handle, &g_media_svc_item_validity_query_list, uid);
852 else if (query_type == MEDIA_SVC_QUERY_MOVE_ITEM)
853 ret = _media_svc_sql_query_list(handle, &g_media_svc_move_item_query_list, uid);
854 else if (query_type == MEDIA_SVC_QUERY_INSERT_ITEM)
855 ret = _media_svc_sql_query_list(handle, &g_media_svc_insert_item_query_list, uid);
856 else if (query_type == MEDIA_SVC_QUERY_UPDATE_ITEM)
857 ret = _media_svc_sql_query_list(handle, &g_media_svc_update_item_query_list, uid);
858 else if (query_type == MEDIA_SVC_QUERY_INSERT_FOLDER)
859 ret = _media_svc_sql_query_list(handle, _media_svc_get_folder_list_ptr(), 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(handle, uid);
869 ret = _media_svc_sql_end_trans(handle, 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(handle, uid);
876 return MS_MEDIA_ERR_NONE;
879 int _media_svc_get_burst_id(sqlite3 *handle, const char *storage_id, int *id)
881 int ret = MS_MEDIA_ERR_NONE;
883 sqlite3_stmt *sql_stmt = NULL;
884 char *sql = sqlite3_mprintf("SELECT max(CAST(burst_id AS INTEGER)) FROM '%s'", storage_id);
886 ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
888 if (ret != MS_MEDIA_ERR_NONE) {
889 media_svc_error("error when _media_svc_get_burst_id. err = [%d]", ret);
893 cur_id = sqlite3_column_int(sql_stmt, 0);
895 SQLITE3_FINALIZE(sql_stmt);
897 return MS_MEDIA_ERR_NONE;
900 int _media_svc_get_noti_info(sqlite3 *handle, const char *storage_id, const char *path, int update_item, media_svc_noti_item **item)
902 int ret = MS_MEDIA_ERR_NONE;
903 sqlite3_stmt *sql_stmt = NULL;
905 int is_root_dir = FALSE;
908 media_svc_error("invalid parameter");
909 return MS_MEDIA_ERR_INVALID_PARAMETER;
912 if (update_item == MS_MEDIA_ITEM_FILE) {
913 sql = sqlite3_mprintf("SELECT media_uuid, media_type, mime_type FROM '%s' WHERE path=%Q", storage_id, path);
914 } else if (update_item == MS_MEDIA_ITEM_DIRECTORY) {
915 sql = sqlite3_mprintf("SELECT folder_uuid FROM '%s' WHERE path=%Q AND storage_uuid='%s'", MEDIA_SVC_DB_TABLE_FOLDER, path, storage_id);
917 media_svc_error("_media_svc_get_noti_info failed : update item");
918 return MS_MEDIA_ERR_INVALID_PARAMETER;
921 ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
923 if (ret != MS_MEDIA_ERR_NONE) {
924 if (ret == MS_MEDIA_ERR_DB_NO_RECORD && update_item == MS_MEDIA_ITEM_DIRECTORY) {
925 media_svc_debug("This is root directory of media");
929 media_svc_error("error when _media_svc_get_noti_info. err = [%d]", ret);
934 *item = calloc(1, sizeof(media_svc_noti_item));
936 media_svc_error("_media_svc_get_noti_info failed : calloc");
937 return MS_MEDIA_ERR_OUT_OF_MEMORY;
940 if (update_item == MS_MEDIA_ITEM_FILE) {
941 (*item)->media_uuid = g_strdup((const char *)sqlite3_column_text(sql_stmt, 0));
942 (*item)->media_type = sqlite3_column_int(sql_stmt, 1);
943 (*item)->mime_type = g_strdup((const char *)sqlite3_column_text(sql_stmt, 2));
944 } else if (update_item == MS_MEDIA_ITEM_DIRECTORY) {
946 (*item)->media_uuid = NULL;
948 (*item)->media_uuid = g_strdup((const char *)sqlite3_column_text(sql_stmt, 0));
952 SQLITE3_FINALIZE(sql_stmt);
954 return MS_MEDIA_ERR_NONE;
957 int _media_svc_count_invalid_folder_items(sqlite3 *handle, const char *storage_id, const char *folder_path, int *count)
959 int ret = MS_MEDIA_ERR_NONE;
960 sqlite3_stmt *sql_stmt = NULL;
962 char *sql = sqlite3_mprintf("SELECT count(*) FROM '%s' WHERE validity=0 AND path LIKE '%q/%%'", storage_id, folder_path);
964 ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
966 if (ret != MS_MEDIA_ERR_NONE) {
967 media_svc_error("error when _media_svc_count_invalid_folder_items. err = [%d]", ret);
971 *count = sqlite3_column_int(sql_stmt, 0);
973 SQLITE3_FINALIZE(sql_stmt);
975 return MS_MEDIA_ERR_NONE;
978 int _media_svc_get_thumbnail_count(sqlite3 *handle, const char *storage_id, const char *thumb_path, int *count)
980 int ret = MS_MEDIA_ERR_NONE;
981 sqlite3_stmt *sql_stmt = NULL;
982 char *sql = sqlite3_mprintf("SELECT count(*) FROM '%s' WHERE thumbnail_path=%Q", storage_id, thumb_path);
984 ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
986 if (ret != MS_MEDIA_ERR_NONE) {
987 media_svc_error("error when _media_svc_get_thumbnail_count. err = [%d]", ret);
991 *count = sqlite3_column_int(sql_stmt, 0);
993 SQLITE3_FINALIZE(sql_stmt);
995 return MS_MEDIA_ERR_NONE;
998 int _media_svc_get_fileinfo_by_path(sqlite3 *handle, const char *storage_id, const char *path, time_t *modified_time, unsigned long long *size)
1000 int ret = MS_MEDIA_ERR_NONE;
1001 sqlite3_stmt *sql_stmt = NULL;
1002 char *sql = sqlite3_mprintf("SELECT modified_time, size FROM '%s' WHERE path='%q'", storage_id, path);
1004 ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
1006 if (ret != MS_MEDIA_ERR_NONE) {
1007 media_svc_error("error when _media_svc_get_fileinfo_by_path. err = [%d]", ret);
1011 *modified_time = (int)sqlite3_column_int(sql_stmt, 0);
1012 *size = (unsigned long long)sqlite3_column_int64(sql_stmt, 1);
1014 SQLITE3_FINALIZE(sql_stmt);
1016 return MS_MEDIA_ERR_NONE;
1019 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)
1021 int ret = MS_MEDIA_ERR_NONE;
1022 char *burst_id = NULL;
1024 media_svc_debug("START pass1");
1026 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";
1029 int burst_id_int = 0;
1030 ret = _media_svc_get_burst_id(handle, storage_id, &burst_id_int);
1031 if (ret != MS_MEDIA_ERR_NONE) {
1035 if (burst_id_int > 0) {
1036 media_svc_debug("Burst id : %d", burst_id_int);
1037 burst_id = sqlite3_mprintf("%d", burst_id_int);
1040 /* Get thumbnail for burst shot */
1041 char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, };
1045 ret = _media_svc_request_thumbnail_with_origin_size(content_info->path, thumb_path, sizeof(thumb_path), &width, &height);
1046 if(ret == MS_MEDIA_ERR_NONE) {
1047 ret = __media_svc_malloc_and_strncpy(&(content_info->thumbnail_path), thumb_path);
1048 if (ret != MS_MEDIA_ERR_NONE) {
1049 content_info->thumbnail_path = NULL;
1053 if (content_info->media_meta.width <= 0)
1054 content_info->media_meta.width = width;
1056 if (content_info->media_meta.height <= 0)
1057 content_info->media_meta.height = height;
1060 /* Update Pinyin If Support Pinyin */
1061 if(_media_svc_check_pinyin_support())
1063 if(STRING_VALID(content_info->file_name))
1064 _media_svc_get_pinyin_str(content_info->file_name, &content_info->file_name_pinyin);
1068 char *sql = sqlite3_mprintf("INSERT INTO '%s' (%s) VALUES (%Q, %Q, %Q, %Q, %d, %Q, %lld, \
1069 %d, %d, %d, %d, %d, %Q, %Q);",
1070 storage_id, db_fields,
1071 content_info->media_uuid,
1072 content_info->folder_uuid,
1074 content_info->file_name,
1075 content_info->media_type,
1076 content_info->mime_type,
1078 content_info->added_time,
1079 content_info->modified_time,
1080 content_info->is_drm,
1081 content_info->storage_type,
1082 content_info->timeline,
1089 sqlite3_free(burst_id);
1093 media_svc_debug("MAKE PASS 1 QUERY END");
1096 ret = _media_svc_sql_query(handle, sql, uid);
1098 if (ret != MS_MEDIA_ERR_NONE) {
1099 media_svc_error("failed to insert item");
1103 media_svc_debug("query : %s", sql);
1104 _media_svc_sql_query_add(&g_media_svc_insert_item_query_list, &sql);
1106 media_svc_debug("END");
1107 return MS_MEDIA_ERR_NONE;
1110 int _media_svc_insert_item_pass2(sqlite3 *handle, const char *storage_id, media_svc_content_info_s *content_info, int is_burst, bool stack_query, uid_t uid)
1112 int ret = MS_MEDIA_ERR_NONE;
1113 //char *burst_id = NULL;
1115 media_svc_debug_fenter();
1117 /*Update Pinyin If Support Pinyin*/
1118 if(_media_svc_check_pinyin_support())
1120 if(STRING_VALID(content_info->file_name))
1121 _media_svc_get_pinyin_str(content_info->file_name, &content_info->file_name_pinyin);
1122 if(STRING_VALID(content_info->media_meta.title))
1123 _media_svc_get_pinyin_str(content_info->media_meta.title, &content_info->media_meta.title_pinyin);
1124 if(STRING_VALID(content_info->media_meta.album))
1125 _media_svc_get_pinyin_str(content_info->media_meta.album, &content_info->media_meta.album_pinyin);
1126 if(STRING_VALID(content_info->media_meta.artist))
1127 _media_svc_get_pinyin_str(content_info->media_meta.artist, &content_info->media_meta.artist_pinyin);
1128 if(STRING_VALID(content_info->media_meta.album_artist))
1129 _media_svc_get_pinyin_str(content_info->media_meta.album_artist, &content_info->media_meta.album_artist_pinyin);
1130 if(STRING_VALID(content_info->media_meta.genre))
1131 _media_svc_get_pinyin_str(content_info->media_meta.genre, &content_info->media_meta.genre_pinyin);
1132 if(STRING_VALID(content_info->media_meta.composer))
1133 _media_svc_get_pinyin_str(content_info->media_meta.composer, &content_info->media_meta.composer_pinyin);
1134 if(STRING_VALID(content_info->media_meta.copyright))
1135 _media_svc_get_pinyin_str(content_info->media_meta.copyright, &content_info->media_meta.copyright_pinyin);
1136 if(STRING_VALID(content_info->media_meta.description))
1137 _media_svc_get_pinyin_str(content_info->media_meta.description, &content_info->media_meta.description_pinyin);
1140 /*modified month does not exist in Tizen 2.4*/
1141 char *sql = sqlite3_mprintf("UPDATE '%s' SET \
1142 thumbnail_path=%Q, title=%Q, album_id=%d, album=%Q, artist=%Q, album_artist=%Q, genre=%Q, composer=%Q, year=%Q, \
1143 recorded_date=%Q, copyright=%Q, track_num=%Q, description=%Q, bitrate=%d, bitpersample=%d, samplerate=%d, channel=%d, \
1144 duration=%d, longitude=%.6f, latitude=%.6f, altitude=%.6f, width=%d, height=%d, datetaken=%Q, orientation=%d, exposure_time=%Q,\
1145 fnumber=%.6f, iso=%d, model=%Q, rating=%d, weather=%Q, file_name_pinyin=%Q, title_pinyin=%Q, album_pinyin=%Q, \
1146 artist_pinyin=%Q, album_artist_pinyin=%Q, genre_pinyin=%Q, composer_pinyin=%Q, copyright_pinyin=%Q, description_pinyin=%Q WHERE path=%Q",
1148 //content_info->folder_uuid,
1149 content_info->thumbnail_path, //
1150 content_info->media_meta.title,
1151 content_info->album_id,
1152 content_info->media_meta.album,
1153 content_info->media_meta.artist,
1154 content_info->media_meta.album_artist,
1155 content_info->media_meta.genre,
1156 content_info->media_meta.composer,
1157 content_info->media_meta.year,
1158 content_info->media_meta.recorded_date,
1159 content_info->media_meta.copyright,
1160 content_info->media_meta.track_num,
1161 content_info->media_meta.description, //
1162 content_info->media_meta.bitrate,
1163 content_info->media_meta.bitpersample,
1164 content_info->media_meta.samplerate,
1165 content_info->media_meta.channel,
1166 content_info->media_meta.duration,
1167 content_info->media_meta.longitude,
1168 content_info->media_meta.latitude,
1169 content_info->media_meta.altitude,
1170 content_info->media_meta.width,
1171 content_info->media_meta.height,
1172 content_info->media_meta.datetaken,
1173 content_info->media_meta.orientation,
1174 content_info->media_meta.exposure_time,
1175 content_info->media_meta.fnumber,
1176 content_info->media_meta.iso,
1177 content_info->media_meta.model,
1178 content_info->media_meta.rating,
1179 content_info->media_meta.weather,
1180 content_info->file_name_pinyin,
1181 content_info->media_meta.title_pinyin,
1182 content_info->media_meta.album_pinyin,
1183 content_info->media_meta.artist_pinyin,
1184 content_info->media_meta.album_artist_pinyin,
1185 content_info->media_meta.genre_pinyin,
1186 content_info->media_meta.composer_pinyin,
1187 content_info->media_meta.copyright_pinyin,
1188 content_info->media_meta.description_pinyin,
1193 ret = _media_svc_sql_query(handle, sql, uid);
1195 if (ret != MS_MEDIA_ERR_NONE) {
1197 media_svc_error("failed to insert item");
1201 //media_svc_debug("query : %s", sql);
1202 _media_svc_sql_query_add(&g_media_svc_update_item_query_list, &sql);
1205 media_svc_debug_fleave();
1207 return MS_MEDIA_ERR_NONE;