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.
22 #include <glib/gstdio.h>
23 #include <media-util-err.h>
24 #include "media-svc-media-folder.h"
25 #include "media-svc-debug.h"
26 #include "media-svc-env.h"
27 #include "media-svc-util.h"
28 #include "media-svc-db-utils.h"
30 #define FOLDER_SCAN_DONE 4
32 static __thread GList *g_media_svc_insert_folder_query_list;
34 int _media_svc_get_folder_id_by_foldername(sqlite3 *handle, const char *storage_id, const char *folder_name, char *folder_id, uid_t uid)
36 int ret = MS_MEDIA_ERR_NONE;
37 sqlite3_stmt *sql_stmt = NULL;
40 sql = sqlite3_mprintf("SELECT folder_uuid FROM %q WHERE storage_uuid = '%q' AND path = '%q';", MEDIA_SVC_DB_TABLE_FOLDER, storage_id, folder_name);
42 ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
43 if (ret != MS_MEDIA_ERR_NONE) {
44 if (ret == MS_MEDIA_ERR_DB_NO_RECORD)
45 media_svc_debug("there is no folder.");
47 media_svc_error("error when _media_svc_get_folder_id_by_foldername. err = [%d]", ret);
52 SAFE_STRLCPY(folder_id, (const char *)sqlite3_column_text(sql_stmt, 0), MEDIA_SVC_UUID_SIZE + 1);
54 SQLITE3_FINALIZE(sql_stmt);
59 int _media_svc_get_folder_id_by_foldername_with_validity(sqlite3 *handle, const char *storage_id, const char *folder_name, char *folder_id, uid_t uid, int *validity)
61 int ret = MS_MEDIA_ERR_NONE;
62 sqlite3_stmt *sql_stmt = NULL;
65 sql = sqlite3_mprintf("SELECT folder_uuid, validity FROM %q WHERE storage_uuid = '%q' AND path = '%q';", MEDIA_SVC_DB_TABLE_FOLDER, storage_id, folder_name);
67 ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
68 if (ret != MS_MEDIA_ERR_NONE) {
69 if (ret == MS_MEDIA_ERR_DB_NO_RECORD)
70 media_svc_debug("there is no folder.");
72 media_svc_error("error when _media_svc_get_folder_id_by_foldername_with_validity. err = [%d]", ret);
77 SAFE_STRLCPY(folder_id, (const char *)sqlite3_column_text(sql_stmt, 0), MEDIA_SVC_UUID_SIZE + 1);
78 *validity = (int)sqlite3_column_int(sql_stmt, 1);
80 SQLITE3_FINALIZE(sql_stmt);
85 static int __media_svc_append_folder(const char *storage_id, media_svc_storage_type_e storage_type,
86 const char *folder_id, const char *folder_path, bool stack_query, uid_t uid)
88 int ret = MS_MEDIA_ERR_NONE;
89 char *folder_name = NULL;
90 int folder_modified_date = 0;
92 folder_name = g_path_get_basename(folder_path);
93 folder_modified_date = _media_svc_get_file_time(folder_path);
95 /*Update Pinyin If Support Pinyin*/
96 char *folder_name_pinyin = NULL;
97 if (_media_svc_check_pinyin_support())
98 _media_svc_get_pinyin_str(folder_name, &folder_name_pinyin);
99 /* Sometime SQLITE3 returns NO_RECORD, so need to consider conflict case.. */
100 media_svc_debug("UNIQUE:path[%s], storage_uuid[%s]", folder_path, storage_id);
101 char *sql = sqlite3_mprintf("INSERT OR IGNORE INTO %q (folder_uuid, path, name, storage_uuid, storage_type, modified_time, name_pinyin) values (%Q, %Q, %Q, %Q, '%d', '%d', %Q); ",
102 MEDIA_SVC_DB_TABLE_FOLDER, folder_id, folder_path, folder_name, storage_id, storage_type, folder_modified_date, folder_name_pinyin);
105 ret = _media_svc_sql_query(sql, uid);
106 SQLITE3_SAFE_FREE(sql);
108 _media_svc_sql_query_add(&g_media_svc_insert_folder_query_list, &sql);
111 SAFE_FREE(folder_name);
112 SAFE_FREE(folder_name_pinyin);
117 int _media_svc_update_folder_modified_time_by_folder_uuid(const char *folder_uuid, const char *folder_path, uid_t uid)
119 int ret = MS_MEDIA_ERR_NONE;
120 int modified_time = 0;
122 modified_time = _media_svc_get_file_time(folder_path);
124 char *sql = sqlite3_mprintf("UPDATE %q SET modified_time=%d WHERE folder_uuid=%Q;", MEDIA_SVC_DB_TABLE_FOLDER, modified_time, folder_uuid);
126 ret = _media_svc_sql_query(sql, uid);
127 SQLITE3_SAFE_FREE(sql);
132 static int __media_svc_get_and_append_parent_folder(sqlite3 *handle, const char *storage_id, const char *path, media_svc_storage_type_e storage_type, char *folder_id, uid_t uid)
134 int ret = MS_MEDIA_ERR_NONE;
135 unsigned int next_pos = 0;
137 char *dir_path = NULL;
138 const char *token = "/";
139 char *folder_uuid = NULL;
140 char tmp_folder_uuid[MEDIA_SVC_UUID_SIZE + 1] = {0, };
141 bool folder_search_end = FALSE;
142 char *internal_path = NULL;
144 memset(tmp_folder_uuid, 0, sizeof(tmp_folder_uuid));
145 ret = ms_user_get_internal_root_path(uid, &internal_path);
146 media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "Fail to get root path");
148 if (STRING_VALID(internal_path) && (strncmp(path, internal_path, strlen(internal_path)) == 0))
149 next_pos = strlen(internal_path);
150 else if (STRING_VALID(MEDIA_ROOT_PATH_SDCARD) && strncmp(path, MEDIA_ROOT_PATH_SDCARD, strlen(MEDIA_ROOT_PATH_SDCARD)) == 0)
151 next_pos = strlen(MEDIA_ROOT_PATH_SDCARD);
152 else if (STRING_VALID(MEDIA_ROOT_PATH_EXTERNAL) && strncmp(path, MEDIA_ROOT_PATH_EXTERNAL, strlen(MEDIA_ROOT_PATH_EXTERNAL)) == 0)
153 next_pos = strlen(MEDIA_ROOT_PATH_EXTERNAL);
154 else if (STRING_VALID(MEDIA_ROOT_PATH_DISC) && strncmp(path, MEDIA_ROOT_PATH_DISC, strlen(MEDIA_ROOT_PATH_DISC)) == 0)
155 next_pos = strlen(MEDIA_ROOT_PATH_DISC);
157 media_svc_error("Invalid Path");
158 media_svc_sec_error("Invalid Path [%s], internal_path [%s]", path, internal_path);
159 SAFE_FREE(internal_path);
160 return MS_MEDIA_ERR_INTERNAL;
163 SAFE_FREE(internal_path);
165 while (!folder_search_end) {
166 next = strstr(path + next_pos, token);
168 next_pos = (next - path);
169 dir_path = strndup(path, next_pos);
172 dir_path = strndup(path, strlen(path));
173 folder_search_end = TRUE;
174 media_svc_error("[No-Error] End Path [%s]", dir_path);
177 if (STRING_VALID(MEDIA_ROOT_PATH_EXTERNAL) && (g_strcmp0(dir_path, MEDIA_ROOT_PATH_EXTERNAL) == 0)) {
178 /*To avoid insert MEDIA_ROOT_PATH_EXTERNAL path*/
183 ret = _media_svc_get_folder_id_by_foldername(handle, storage_id, dir_path, tmp_folder_uuid, uid);
184 if (ret == MS_MEDIA_ERR_DB_NO_RECORD) {
185 folder_uuid = _media_info_generate_uuid();
186 if (folder_uuid == NULL) {
187 media_svc_error("Invalid UUID");
189 return MS_MEDIA_ERR_INTERNAL;
192 ret = __media_svc_append_folder(storage_id, storage_type, folder_uuid, dir_path, FALSE, uid);
193 if (ret != MS_MEDIA_ERR_NONE)
194 media_svc_error("__media_svc_append_folder is failed");
196 media_svc_error("[No-Error] New Appended folder path [%s], folder_uuid [%s]", dir_path, folder_uuid);
198 media_svc_error("EXIST dir path : %s", dir_path);
204 if (STRING_VALID(folder_uuid)) {
205 SAFE_STRLCPY(folder_id, folder_uuid, MEDIA_SVC_UUID_SIZE + 1);
207 media_svc_error("Fail to get folder_uuid");
208 return MS_MEDIA_ERR_INTERNAL;
211 return MS_MEDIA_ERR_NONE;
214 static int __media_svc_update_parent_folder_validity(sqlite3 *handle, const char *storage_id, const char *path, uid_t uid)
216 int ret = MS_MEDIA_ERR_NONE;
217 unsigned int next_pos = 0;
219 char *dir_path = NULL;
220 const char *token = "/";
221 bool folder_search_end = FALSE;
222 char *internal_path = NULL;
224 ret = ms_user_get_internal_root_path(uid, &internal_path);
225 media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "Fail to get root path");
227 if (STRING_VALID(internal_path) && (strncmp(path, internal_path, strlen(internal_path)) == 0))
228 next_pos = strlen(internal_path);
229 else if (STRING_VALID(MEDIA_ROOT_PATH_SDCARD) && strncmp(path, MEDIA_ROOT_PATH_SDCARD, strlen(MEDIA_ROOT_PATH_SDCARD)) == 0)
230 next_pos = strlen(MEDIA_ROOT_PATH_SDCARD);
231 else if (STRING_VALID(MEDIA_ROOT_PATH_EXTERNAL) && strncmp(path, MEDIA_ROOT_PATH_EXTERNAL, strlen(MEDIA_ROOT_PATH_EXTERNAL)) == 0)
232 next_pos = strlen(MEDIA_ROOT_PATH_EXTERNAL);
233 else if (STRING_VALID(MEDIA_ROOT_PATH_DISC) && strncmp(path, MEDIA_ROOT_PATH_DISC, strlen(MEDIA_ROOT_PATH_DISC)) == 0)
234 next_pos = strlen(MEDIA_ROOT_PATH_DISC);
236 media_svc_error("Invalid Path");
237 media_svc_sec_error("Invalid Path [%s], internal_path [%s]", path, internal_path);
238 SAFE_FREE(internal_path);
239 return MS_MEDIA_ERR_INTERNAL;
242 SAFE_FREE(internal_path);
244 while (!folder_search_end) {
245 next = strstr(path + next_pos, token);
247 next_pos = (next - path);
248 dir_path = strndup(path, next_pos);
251 dir_path = strndup(path, strlen(path));
252 folder_search_end = TRUE;
253 media_svc_error("[No-Error] End Path [%s]", dir_path);
256 if (STRING_VALID(MEDIA_ROOT_PATH_EXTERNAL) && (g_strcmp0(dir_path, MEDIA_ROOT_PATH_EXTERNAL) == 0)) {
257 /*To avoid insert MEDIA_ROOT_PATH_EXTERNAL path*/
262 ret = _media_svc_set_folder_validity(handle, storage_id, dir_path, 1, false, uid);
264 media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "Fail to set folder validity");
267 return MS_MEDIA_ERR_NONE;
270 int _media_svc_get_and_append_folder(sqlite3 *handle, const char *storage_id, const char *path, media_svc_storage_type_e storage_type, char *folder_id, uid_t uid)
272 int ret = MS_MEDIA_ERR_NONE;
275 ret = _media_svc_get_folder_id_by_foldername_with_validity(handle, storage_id, path, folder_id, uid, &validity);
277 if (ret == MS_MEDIA_ERR_DB_NO_RECORD)
278 ret = __media_svc_get_and_append_parent_folder(handle, storage_id, path, storage_type, folder_id, uid);
279 else if (ret == MS_MEDIA_ERR_NONE && validity == 0)
280 ret = __media_svc_update_parent_folder_validity(handle, storage_id, path, uid);
285 int _media_svc_get_and_append_folder_id_by_path(sqlite3 *handle, const char *storage_id, const char *path, media_svc_storage_type_e storage_type, char *folder_id, uid_t uid)
287 char *dir_path = NULL;
288 int ret = MS_MEDIA_ERR_NONE;
290 dir_path = g_path_get_dirname(path);
292 ret = _media_svc_get_and_append_folder(handle, storage_id, dir_path, storage_type, folder_id, uid);
299 int _media_svc_get_folder_info_by_foldername(sqlite3 *handle, const char *storage_id, const char *folder_name, char *folder_id, time_t *modified_time)
301 int ret = MS_MEDIA_ERR_NONE;
302 sqlite3_stmt *sql_stmt = NULL;
304 char *sql = sqlite3_mprintf("SELECT folder_uuid, modified_time FROM %q WHERE (storage_uuid = '%q' AND path = '%q');", MEDIA_SVC_DB_TABLE_FOLDER, storage_id, folder_name);
306 ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
308 if (ret != MS_MEDIA_ERR_NONE) {
309 if (ret == MS_MEDIA_ERR_DB_NO_RECORD)
310 media_svc_debug("there is no folder.");
312 media_svc_error("error when _media_svc_get_folder_id_by_foldername. err = [%d]", ret);
317 SAFE_STRLCPY(folder_id, (const char *)sqlite3_column_text(sql_stmt, 0), MEDIA_SVC_UUID_SIZE + 1);
318 *modified_time = (int)sqlite3_column_int(sql_stmt, 1);
320 SQLITE3_FINALIZE(sql_stmt);
325 int _media_svc_get_and_append_folder_id_by_folder_path(sqlite3 *handle, const char *storage_id, const char *path, media_svc_storage_type_e storage_type, char *folder_id, bool stack_query, uid_t uid)
327 char *path_name = NULL;
328 int ret = MS_MEDIA_ERR_NONE;
331 path_name = strdup(path);
332 if (path_name == NULL) {
333 media_svc_error("out of memory");
334 return MS_MEDIA_ERR_OUT_OF_MEMORY;
337 ret = _media_svc_get_folder_id_by_foldername(handle, storage_id, path_name, folder_id, uid);
338 if (ret == MS_MEDIA_ERR_DB_NO_RECORD) {
339 ret = __media_svc_get_and_append_parent_folder(handle, storage_id, path_name, storage_type, folder_id, uid);
341 sql = sqlite3_mprintf("UPDATE %q SET validity=1 WHERE storage_uuid = '%q' AND path = '%q';", MEDIA_SVC_DB_TABLE_FOLDER, storage_id, path);
343 ret = _media_svc_sql_query(sql, uid);
344 SQLITE3_SAFE_FREE(sql);
346 _media_svc_sql_query_add(&g_media_svc_insert_folder_query_list, &sql);
350 SAFE_FREE(path_name);
355 int _media_svc_delete_invalid_folder(const char *storage_id, int storage_type, uid_t uid)
357 int ret = MS_MEDIA_ERR_NONE;
360 sql = sqlite3_mprintf("DELETE FROM %q WHERE storage_uuid = '%q' AND storage_type = %d AND validity = 0;", MEDIA_SVC_DB_TABLE_FOLDER, storage_id, storage_type);
361 ret = _media_svc_sql_query(sql, uid);
363 SQLITE3_SAFE_FREE(sql);
368 int _media_svc_set_folder_validity(sqlite3 *handle, const char *storage_id, const char *start_path, int validity, bool is_recursive, uid_t uid)
370 int ret = MS_MEDIA_ERR_NONE;
372 char start_path_id[MEDIA_SVC_UUID_SIZE+1] = {0,};
375 ret = _media_svc_get_folder_id_by_foldername(handle, storage_id, start_path, start_path_id, uid);
376 media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "_media_svc_get_folder_id_by_foldername fail");
377 media_svc_retvm_if(!STRING_VALID(start_path_id), MS_MEDIA_ERR_INVALID_PARAMETER, "start_path_id is NULL");
379 sql = sqlite3_mprintf("UPDATE %q SET validity = %d WHERE storage_uuid = '%q' AND (path LIKE '%q/%%' OR folder_uuid ='%q');",
380 MEDIA_SVC_DB_TABLE_FOLDER, validity, storage_id, start_path, start_path_id);
382 sql = sqlite3_mprintf("UPDATE %q SET validity = %d WHERE storage_uuid = '%q' AND path = '%q';",
383 MEDIA_SVC_DB_TABLE_FOLDER, validity, storage_id, start_path);
386 ret = _media_svc_sql_query(sql, uid);
388 SQLITE3_SAFE_FREE(sql);
393 int _media_svc_delete_folder_by_storage_id(const char *storage_id, media_svc_storage_type_e storage_type, uid_t uid)
395 int ret = MS_MEDIA_ERR_NONE;
398 sql = sqlite3_mprintf("DELETE FROM %q WHERE storage_uuid = '%q' AND storage_type = %d;", MEDIA_SVC_DB_TABLE_FOLDER, storage_id, storage_type);
399 ret = _media_svc_sql_query(sql, uid);
401 SQLITE3_SAFE_FREE(sql);
406 GList **_media_svc_get_folder_list_ptr(void)
408 return &g_media_svc_insert_folder_query_list;
411 int _media_svc_get_folder_scan_status(sqlite3 *handle, const char *storage_id, const char *path, int *scan_status)
413 int ret = MS_MEDIA_ERR_NONE;
414 sqlite3_stmt *sql_stmt = NULL;
417 media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid path");
419 sql = sqlite3_mprintf("SELECT scan_status FROM %q WHERE path = '%q' AND storage_uuid = '%q'", MEDIA_SVC_DB_TABLE_FOLDER, path, storage_id);
421 ret = _media_svc_sql_prepare_to_step_simple(handle, sql, &sql_stmt);
423 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
425 while (sqlite3_step(sql_stmt) == SQLITE_ROW)
426 *scan_status = sqlite3_column_int(sql_stmt, 0);
428 SQLITE3_FINALIZE(sql_stmt);
433 int _media_svc_set_folder_scan_status(const char *storage_id, const char *path, int scan_status, uid_t uid)
435 int ret = MS_MEDIA_ERR_NONE;
439 sql = sqlite3_mprintf("UPDATE %q SET scan_status=%d WHERE path = '%q' AND storage_uuid = '%q'", MEDIA_SVC_DB_TABLE_FOLDER, scan_status, path, storage_id);
441 sql = sqlite3_mprintf("UPDATE %q SET scan_status=%d WHERE storage_uuid = '%q'", MEDIA_SVC_DB_TABLE_FOLDER, scan_status, storage_id);
443 ret = _media_svc_sql_query(sql, uid);
444 SQLITE3_SAFE_FREE(sql);
449 int _media_svc_get_folder_modified_time_by_path(sqlite3 *handle, const char *path, const char *storage_id, time_t *modified_time)
451 int ret = MS_MEDIA_ERR_NONE;
452 sqlite3_stmt *sql_stmt = NULL;
454 char *sql = sqlite3_mprintf("SELECT modified_time FROM %q WHERE path = '%q' AND storage_uuid = '%q';", MEDIA_SVC_DB_TABLE_FOLDER, path, storage_id);
456 ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
458 if (ret != MS_MEDIA_ERR_NONE) {
459 if (ret == MS_MEDIA_ERR_DB_NO_RECORD)
460 media_svc_debug("there is no folder.");
462 media_svc_error("error when _media_svc_get_folder_modified_time_by_path. err = [%d]", ret);
467 *modified_time = (int)sqlite3_column_int(sql_stmt, 0);
469 SQLITE3_FINALIZE(sql_stmt);
474 int _media_svc_get_null_scan_folder_list(sqlite3 *handle, const char *storage_id, const char *path, char ***folder_list, int *count)
476 int ret = MS_MEDIA_ERR_NONE;
480 sqlite3_stmt *sql_stmt = NULL;
483 sql = sqlite3_mprintf("SELECT count(*) FROM %q WHERE storage_uuid = '%q' AND scan_status!=%d", MEDIA_SVC_DB_TABLE_FOLDER, storage_id, FOLDER_SCAN_DONE);
484 ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
486 if (ret != MS_MEDIA_ERR_NONE) {
487 if (ret == MS_MEDIA_ERR_DB_NO_RECORD)
488 media_svc_debug("there is no folder.");
490 media_svc_error("error when get folder_id by path. err = [%d]", ret);
498 cnt = sqlite3_column_int(sql_stmt, 0);
499 SQLITE3_FINALIZE(sql_stmt);
501 sql = sqlite3_mprintf("SELECT path FROM %q WHERE storage_uuid = '%q' AND scan_status!=%d", MEDIA_SVC_DB_TABLE_FOLDER, storage_id, FOLDER_SCAN_DONE);
506 return MS_MEDIA_ERR_INTERNAL;
509 ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
511 if (ret != MS_MEDIA_ERR_NONE) {
512 media_svc_error("prepare error [%s]", sqlite3_errmsg(handle));
520 sql = sqlite3_mprintf("SELECT count(*) FROM %q WHERE path IN (SELECT DISTINCT '%q/'||name from '%s' WHERE path LIKE '%q/%%')",
521 MEDIA_SVC_DB_TABLE_FOLDER, path, MEDIA_SVC_DB_TABLE_FOLDER, path);
522 ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
524 if (ret != MS_MEDIA_ERR_NONE) {
525 media_svc_error("error when _media_svc_sql_prepare_to_step. err = [%d]", ret);
529 cnt = sqlite3_column_int(sql_stmt, 0);
530 SQLITE3_FINALIZE(sql_stmt);
532 sql = sqlite3_mprintf("SELECT path FROM %q WHERE path IN (SELECT DISTINCT '%q/'||name from '%s' WHERE path LIKE '%q/%%')",
533 MEDIA_SVC_DB_TABLE_FOLDER, path, MEDIA_SVC_DB_TABLE_FOLDER, path);
538 return MS_MEDIA_ERR_NONE;
541 ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
543 if (ret != MS_MEDIA_ERR_NONE) {
544 media_svc_error("prepare error [%s]", sqlite3_errmsg(handle));
553 *folder_list = malloc(sizeof(char *) * cnt);
554 if (*folder_list == NULL) {
555 media_svc_error("Allocation failed");
560 return MS_MEDIA_ERR_OUT_OF_MEMORY;
564 (*folder_list)[idx] = strdup((char *)sqlite3_column_text(sql_stmt, 0));
566 if (sqlite3_step(sql_stmt) != SQLITE_ROW)
571 if (cnt == idx + 1) {
573 media_svc_debug("OK");
577 for (i = 0; i < idx; i++)
578 SAFE_FREE((*folder_list)[i]);
580 SAFE_FREE(*folder_list);
582 ret = MS_MEDIA_ERR_INTERNAL;
585 SQLITE3_FINALIZE(sql_stmt);
590 int _media_svc_count_folder_with_path(sqlite3 *handle, const char *storage_id, const char *path, int *count)
592 int ret = MS_MEDIA_ERR_NONE;
593 sqlite3_stmt *sql_stmt = NULL;
595 char *sql = sqlite3_mprintf("SELECT count(*) FROM %q WHERE (storage_uuid='%q' AND path='%q')", MEDIA_SVC_DB_TABLE_FOLDER, storage_id, path);
597 ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
599 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
601 *count = sqlite3_column_int(sql_stmt, 0);
603 SQLITE3_FINALIZE(sql_stmt);
605 return MS_MEDIA_ERR_NONE;
608 int _media_svc_get_folder_uuid(sqlite3 *handle, const char *storage_id, const char *path, char *folder_id)
610 int ret = MS_MEDIA_ERR_NONE;
611 sqlite3_stmt *sql_stmt = NULL;
614 sql = sqlite3_mprintf("SELECT folder_uuid FROM %q WHERE (storage_uuid='%q' AND path='%q')", MEDIA_SVC_DB_TABLE_FOLDER, storage_id, path);
616 ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
618 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
620 SAFE_STRLCPY(folder_id, (const char *)sqlite3_column_text(sql_stmt, 0), MEDIA_SVC_UUID_SIZE+1);
622 SQLITE3_FINALIZE(sql_stmt);
624 if (!STRING_VALID(folder_id)) {
625 media_svc_error("Not found valid storage id [%s]", path);
626 ret = MS_MEDIA_ERR_INVALID_PARAMETER;