From e159267cc8276ef6a84f30082e1c61066fb5cc8e Mon Sep 17 00:00:00 2001 From: Minje Ahn Date: Fri, 23 Jun 2017 13:47:43 +0900 Subject: [PATCH] Fixed how to get parent folder ID Use another query for getting parent folder uuid Change-Id: Iffc9e300b95d017aae2cede1ae1676503324fa2b Signed-off-by: Minje Ahn --- include/media_info_private.h | 4 ++-- include_product/media_info_private.h | 4 ++-- src/media_content.c | 1 - src/media_db.c | 25 ++++++++++++++++++--- src/media_folder.c | 33 ++++++++++++++++++---------- 5 files changed, 48 insertions(+), 19 deletions(-) diff --git a/include/media_info_private.h b/include/media_info_private.h index 80665a6..4c9ae65 100755 --- a/include/media_info_private.h +++ b/include/media_info_private.h @@ -504,7 +504,6 @@ typedef struct _media_content_cb_data { #define DB_FIELD_FOLDER_STORAGE_TYPE "storage_type" #define DB_FIELD_FOLDER_NAME_PINYIN "name_pinyin" #define DB_FIELD_FOLDER_ORDER "folder_order" -#define DB_FIELD_FOLDER_PARENT_FOLDER_ID "parent_folder_uuid" /* DB field for playlist */ #define DB_FIELD_PLAYLIST_ID "playlist_id" @@ -559,7 +558,7 @@ typedef struct _media_content_cb_data { #define SELECT_ALBUM_LIST "SELECT DISTINCT a.album_id, a.name, a.artist, a.album_art FROM "ALBUM_MEDIA_JOIN #define SELECT_MEDIA_GROUP_LIST "SELECT DISTINCT %s FROM '%s' WHERE validity=1 " -#define SELECT_FOLDER_LIST "SELECT DISTINCT f.folder_uuid, f.path, f.name, f.storage_type, f.modified_time, f.storage_uuid, f.folder_order, f.parent_folder_uuid FROM "FOLDER_MEDIA_JOIN +#define SELECT_FOLDER_LIST "SELECT DISTINCT f.folder_uuid, f.path, f.name, f.storage_type, f.modified_time, f.storage_uuid, f.folder_order FROM "FOLDER_MEDIA_JOIN #define SELECT_FOLDER_LIST_BY_STORAGE_ID SELECT_FOLDER_LIST"AND f.storage_uuid='%s' " #define SELECT_TAG_LIST "SELECT DISTINCT tag_id, name FROM "DB_VIEW_TAG" WHERE 1 " #define SELECT_PLAYLIST_LIST "SELECT DISTINCT playlist_id, name, p_thumbnail_path FROM "DB_VIEW_PLAYLIST" WHERE 1 " @@ -606,6 +605,7 @@ typedef struct _media_content_cb_data { /*Folder info*/ #define UPDATE_FOLDER_ORDER "UPDATE "DB_TABLE_FOLDER" SET folder_order=%d WHERE folder_uuid=%Q" +#define SELECT_FOLDER_ID_BY_PATH "SELECT folder_uuid FROM "DB_TABLE_FOLDER" WHERE path = '%s'" /* Playlist Info */ #define INSERT_PLAYLIST_TO_PLAYLIST "INSERT INTO "DB_TABLE_PLAYLIST" (name) VALUES (%Q)" diff --git a/include_product/media_info_private.h b/include_product/media_info_private.h index cc4fd07..7022dfb 100755 --- a/include_product/media_info_private.h +++ b/include_product/media_info_private.h @@ -607,7 +607,6 @@ typedef struct _media_content_scan_cb_data_v2 { #define DB_FIELD_FOLDER_STORAGE_TYPE "storage_type" #define DB_FIELD_FOLDER_NAME_PINYIN "name_pinyin" #define DB_FIELD_FOLDER_ORDER "folder_order" -#define DB_FIELD_FOLDER_PARENT_FOLDER_ID "parent_folder_uuid" /* DB field for playlist */ #define DB_FIELD_PLAYLIST_ID "playlist_id" @@ -717,7 +716,7 @@ typedef struct _media_content_scan_cb_data_v2 { #define SELECT_ALBUM_LIST "SELECT DISTINCT a.album_id, a.name, a.artist, a.album_art FROM "ALBUM_MEDIA_JOIN #define SELECT_MEDIA_GROUP_LIST "SELECT DISTINCT %s FROM '%s' WHERE validity=1 " -#define SELECT_FOLDER_LIST "SELECT DISTINCT f.folder_uuid, f.path, f.name, f.storage_type, f.modified_time, f.storage_uuid, f.folder_order, f.parent_folder_uuid FROM "FOLDER_MEDIA_JOIN +#define SELECT_FOLDER_LIST "SELECT DISTINCT f.folder_uuid, f.path, f.name, f.storage_type, f.modified_time, f.storage_uuid, f.folder_order FROM "FOLDER_MEDIA_JOIN #define SELECT_FOLDER_LIST_BY_STORAGE_ID SELECT_FOLDER_LIST"AND f.storage_uuid='%s' " #define SELECT_TAG_LIST "SELECT DISTINCT tag_id, name FROM "DB_VIEW_TAG" WHERE 1 " #define SELECT_PLAYLIST_LIST "SELECT DISTINCT playlist_id, name, p_thumbnail_path FROM "DB_VIEW_PLAYLIST" WHERE 1 " @@ -769,6 +768,7 @@ typedef struct _media_content_scan_cb_data_v2 { /*Folder info*/ #define UPDATE_FOLDER_ORDER "UPDATE "DB_TABLE_FOLDER" SET folder_order=%d WHERE folder_uuid=%Q" +#define SELECT_FOLDER_ID_BY_PATH "SELECT folder_uuid FROM "DB_TABLE_FOLDER" WHERE path = '%s'" /* Playlist Info */ #define INSERT_PLAYLIST_TO_PLAYLIST "INSERT INTO "DB_TABLE_PLAYLIST" (name) VALUES (%Q)" diff --git a/src/media_content.c b/src/media_content.c index 73e6ce0..f765a14 100755 --- a/src/media_content.c +++ b/src/media_content.c @@ -119,7 +119,6 @@ static media_content_attribute_info_s g_content_attrs_info[] = { {FOLDER_STORAGE_TYPE, NULL, DB_TABLE_ALIAS_FOLDER"."DB_FIELD_FOLDER_STORAGE_TYPE}, {FOLDER_NAME_PINYIN, NULL, DB_TABLE_ALIAS_FOLDER"."DB_FIELD_FOLDER_NAME_PINYIN}, {FOLDER_ORDER, NULL, DB_TABLE_ALIAS_FOLDER"."DB_FIELD_FOLDER_ORDER}, - {FOLDER_PARENT_FOLDER_ID, NULL, DB_TABLE_ALIAS_FOLDER"."DB_FIELD_FOLDER_PARENT_FOLDER_ID}, /* Playlist */ {MEDIA_PLAYLIST_ID, DB_FIELD_PLAYLIST_ID, NULL}, diff --git a/src/media_db.c b/src/media_db.c index e37b544..5b0f1f2 100755 --- a/src/media_db.c +++ b/src/media_db.c @@ -614,9 +614,11 @@ int _media_db_get_folder(filter_h filter, media_folder_cb callback, void *user_d char *condition_query = NULL; char *option_query = NULL; sqlite3_stmt *stmt = NULL; + sqlite3_stmt *sub_stmt = NULL; attribute_h attr = NULL; filter_s *_filter = (filter_s*)filter; char *tmp_path = NULL; + char *parent_path = NULL; char repl_path[MAX_PATH_LEN] = {0, }; attr = _content_get_alias_attirbute_handle(); @@ -650,14 +652,31 @@ int _media_db_get_folder(filter_h filter, media_folder_cb callback, void *user_d tmp_path = g_strdup((const char *)sqlite3_column_text(stmt, 1)); _media_content_rollback_path(tmp_path, repl_path); _folder->path = g_strdup(repl_path); - SAFE_FREE(tmp_path); - _folder->name = g_strdup((const char *)sqlite3_column_text(stmt, 2)); _folder->storage_type = (int)sqlite3_column_int(stmt, 3); _folder->modified_time = (int)sqlite3_column_int(stmt, 4); _folder->storage_uuid = g_strdup((const char *)sqlite3_column_text(stmt, 5)); _folder->folder_order = (int)sqlite3_column_int(stmt, 6); - _folder->parent_folder_id = g_strdup((const char *)sqlite3_column_text(stmt, 7)); + + parent_path = g_path_get_dirname(tmp_path); + memset(select_query, 0x00, sizeof(select_query)); + snprintf(select_query, sizeof(select_query), SELECT_FOLDER_ID_BY_PATH, parent_path); + + SAFE_FREE(tmp_path); + SAFE_FREE(parent_path); + + ret = _content_query_prepare(&sub_stmt, select_query, NULL, NULL); + if (ret != MEDIA_CONTENT_ERROR_NONE) { + media_content_error("_content_query_prepare failed"); + media_folder_destroy((media_folder_h) _folder); + SQLITE3_FINALIZE(stmt); + return ret; + } + + if (sqlite3_step(sub_stmt) == SQLITE_ROW) + _folder->parent_folder_id = g_strdup((const char *)sqlite3_column_text(sub_stmt, 0)); + + SQLITE3_FINALIZE(sub_stmt); if (callback((media_folder_h)_folder, user_data) == false) { media_folder_destroy((media_folder_h) _folder); diff --git a/src/media_folder.c b/src/media_folder.c index 27f8046..d46b60b 100755 --- a/src/media_folder.c +++ b/src/media_folder.c @@ -212,6 +212,7 @@ int media_folder_get_folder_id(media_folder_h folder, char **folder_id) int media_folder_get_parent_folder_id(media_folder_h folder, char **parent_folder_id) { int ret = MEDIA_CONTENT_ERROR_NONE; + media_content_warn("DEPRECATION WARNING: media_folder_get_parent_folder_id() is deprecated and will be removed from next release."); media_folder_s *_folder = (media_folder_s*)folder; if (_folder) { @@ -353,7 +354,9 @@ int media_folder_get_folder_from_db(const char *folder_id, media_folder_h *folde sqlite3_stmt *stmt = NULL; char select_query[DEFAULT_QUERY_SIZE]; char *tmp_path = NULL; + char *parent_path = NULL; char repl_path[MAX_PATH_LEN] = {0, }; + media_folder_s *_folder = NULL; if (!STRING_VALID(folder_id)) { media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); @@ -367,12 +370,7 @@ int media_folder_get_folder_from_db(const char *folder_id, media_folder_h *folde ret = _content_query_prepare(&stmt, select_query, NULL, NULL); media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); - media_folder_s *_folder = NULL; - - while (sqlite3_step(stmt) == SQLITE_ROW) { - if (_folder) - media_folder_destroy((media_folder_h)_folder); - + if (sqlite3_step(stmt) == SQLITE_ROW) { _folder = (media_folder_s*)calloc(1, sizeof(media_folder_s)); if (_folder == NULL) { media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); @@ -380,27 +378,40 @@ int media_folder_get_folder_from_db(const char *folder_id, media_folder_h *folde return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; } - media_content_error("folder handle %p", _folder); - _folder->folder_id = g_strdup((const char *)sqlite3_column_text(stmt, 0)); tmp_path = g_strdup((const char *)sqlite3_column_text(stmt, 1)); _media_content_rollback_path(tmp_path, repl_path); _folder->path = g_strdup(repl_path); - SAFE_FREE(tmp_path); - _folder->name = g_strdup((const char *)sqlite3_column_text(stmt, 2)); _folder->modified_time = (int)sqlite3_column_int(stmt, 3); _folder->storage_type = (int)sqlite3_column_int(stmt, 5); _folder->storage_uuid = g_strdup((const char *)sqlite3_column_text(stmt, 6)); _folder->folder_order = (int)sqlite3_column_int(stmt, 7); - _folder->parent_folder_id = g_strdup((const char *)sqlite3_column_text(stmt, 8)); *folder = (media_folder_h)_folder; } SQLITE3_FINALIZE(stmt); + /*Get parent UUID */ + if (STRING_VALID(tmp_path)) { + parent_path = g_path_get_dirname(tmp_path); + memset(select_query, 0x00, sizeof(select_query)); + snprintf(select_query, sizeof(select_query), SELECT_FOLDER_ID_BY_PATH, parent_path); + + SAFE_FREE(tmp_path); + SAFE_FREE(parent_path); + + ret = _content_query_prepare(&stmt, select_query, NULL, NULL); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + if (sqlite3_step(stmt) == SQLITE_ROW) + _folder->parent_folder_id = g_strdup((const char *)sqlite3_column_text(stmt, 0)); + + SQLITE3_FINALIZE(stmt); + } + return ret; } -- 2.34.1