From 116a0eb6907b8602e4c95ee9a764a49d65aef3f5 Mon Sep 17 00:00:00 2001 From: Minje Ahn Date: Thu, 11 Apr 2024 12:59:59 +0900 Subject: [PATCH] Rename _media_svc_sql_prepare_to_step_### Change the name to an easier-to-understand name. Change-Id: If4a3cb505756c7ba685c0313d482cfb8c7fe3732 Signed-off-by: Minje Ahn --- include/media-svc-db-utils.h | 4 ++-- packaging/libmedia-service.spec | 2 +- src/media-svc-album.c | 2 +- src/media-svc-db-utils.c | 38 +++++++++++++++++++++++--------------- src/media-svc-media-folder.c | 6 +++--- src/media-svc-media.c | 14 +++++++------- src/media-svc-storage.c | 6 +++--- 7 files changed, 40 insertions(+), 32 deletions(-) diff --git a/include/media-svc-db-utils.h b/include/media-svc-db-utils.h index 874b438..e5acdc7 100755 --- a/include/media-svc-db-utils.h +++ b/include/media-svc-db-utils.h @@ -35,8 +35,8 @@ void _media_svc_destroy_table_query(void); int _media_svc_sql_query(const char *sql_str, uid_t uid); int _media_svc_sql_query_direct(const char *sql_str, uid_t uid); int _media_svc_check_table_exist(sqlite3 *db_handle, bool *exist); -int _media_svc_sql_prepare_to_step(sqlite3 *handle, const char *sql_str, sqlite3_stmt **stmt); -int _media_svc_sql_prepare_to_step_simple(sqlite3 *handle, const char *sql_str, sqlite3_stmt **stmt); +int _media_svc_get_result_with_check_record(sqlite3 *handle, const char *sql_str, sqlite3_stmt **stmt); +int _media_svc_get_result(sqlite3 *handle, const char *sql_str, sqlite3_stmt **stmt); int _media_svc_sql_query_list(GList **query_list, uid_t uid); int _media_svc_sql_query_list_direct(GList **query_list, uid_t uid); void _media_svc_sql_query_add(GList **query_list, char **query); diff --git a/packaging/libmedia-service.spec b/packaging/libmedia-service.spec index 73048f5..6376483 100644 --- a/packaging/libmedia-service.spec +++ b/packaging/libmedia-service.spec @@ -1,6 +1,6 @@ Name: libmedia-service Summary: Media information service library for multimedia applications -Version: 0.6.1 +Version: 0.6.2 Release: 0 Group: Multimedia/Libraries License: Apache-2.0 diff --git a/src/media-svc-album.c b/src/media-svc-album.c index 511900b..be2bb7c 100755 --- a/src/media-svc-album.c +++ b/src/media-svc-album.c @@ -33,7 +33,7 @@ int _media_svc_get_album_id(sqlite3 *handle, const char *album, const char *arti media_svc_retvm_if(!artist, MS_MEDIA_ERR_INVALID_PARAMETER, "artist is NULL"); sql = sqlite3_mprintf("SELECT album_id FROM %s WHERE name=%Q AND artist=%Q", DB_TABLE_ALBUM, album, artist); - ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt); + ret = _media_svc_get_result_with_check_record(handle, sql, &sql_stmt); SQLITE3_SAFE_FREE(sql); if (ret != MS_MEDIA_ERR_NONE) { if (ret == MS_MEDIA_ERR_DB_NO_RECORD) diff --git a/src/media-svc-db-utils.c b/src/media-svc-db-utils.c index 9df0f92..ac1fb12 100755 --- a/src/media-svc-db-utils.c +++ b/src/media-svc-db-utils.c @@ -539,8 +539,8 @@ int _media_svc_check_table_exist(sqlite3 *db_handle, bool *exist) sqlite3_stmt *sql_stmt = NULL; const char *sql = "SELECT name FROM sqlite_master WHERE type='table' AND name='media';"; - ret = _media_svc_sql_prepare_to_step_simple(db_handle, sql, &sql_stmt); - media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "_media_svc_sql_prepare_to_step_simple failed"); + ret = _media_svc_get_result(db_handle, sql, &sql_stmt); + media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "_media_svc_get_result failed"); if (sqlite3_step(sql_stmt) != SQLITE_ROW) { media_svc_debug("Need to create table"); *exist = false; @@ -554,7 +554,20 @@ int _media_svc_check_table_exist(sqlite3 *db_handle, bool *exist) return MS_MEDIA_ERR_NONE; } -static int __media_svc_sql_prepare_base(sqlite3 *handle, const char *sql_str, sqlite3_stmt **stmt, bool use_step) +static int __media_svc_check_record(sqlite3_stmt **stmt) +{ + media_svc_retvm_if(!stmt, MS_MEDIA_ERR_INVALID_PARAMETER, "invalid statement"); + + if (sqlite3_step(*stmt) != SQLITE_ROW) { + media_svc_debug("No record"); + SQLITE3_FINALIZE(*stmt); + return MS_MEDIA_ERR_DB_NO_RECORD; + } + + return MS_MEDIA_ERR_NONE; +} + +static int __media_svc_get_result(sqlite3 *handle, const char *sql_str, sqlite3_stmt **stmt) { int err = SQLITE_OK; @@ -572,25 +585,20 @@ static int __media_svc_sql_prepare_base(sqlite3 *handle, const char *sql_str, sq return MS_MEDIA_ERR_DB_INTERNAL; } - if (use_step) { - if (sqlite3_step(*stmt) != SQLITE_ROW) { - media_svc_debug("No record"); - SQLITE3_FINALIZE(*stmt); - return MS_MEDIA_ERR_DB_NO_RECORD; - } - } - return MS_MEDIA_ERR_NONE; } -int _media_svc_sql_prepare_to_step(sqlite3 *handle, const char *sql_str, sqlite3_stmt **stmt) +int _media_svc_get_result_with_check_record(sqlite3 *handle, const char *sql_str, sqlite3_stmt **stmt) { - return __media_svc_sql_prepare_base(handle, sql_str, stmt, true); + int ret = __media_svc_get_result(handle, sql_str, stmt); + media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "__media_svc_get_result failed"); + + return __media_svc_check_record(stmt); } -int _media_svc_sql_prepare_to_step_simple(sqlite3 *handle, const char *sql_str, sqlite3_stmt **stmt) +int _media_svc_get_result(sqlite3 *handle, const char *sql_str, sqlite3_stmt **stmt) { - return __media_svc_sql_prepare_base(handle, sql_str, stmt, false); + return __media_svc_get_result(handle, sql_str, stmt); } int _media_svc_sql_query_list(GList **query_list, uid_t uid) diff --git a/src/media-svc-media-folder.c b/src/media-svc-media-folder.c index f679826..3da2c48 100755 --- a/src/media-svc-media-folder.c +++ b/src/media-svc-media-folder.c @@ -32,9 +32,9 @@ static int __media_svc_get_folder_id(sqlite3 *handle, const char *path, long lon sqlite3_stmt *sql_stmt = NULL; char *sql = sqlite3_mprintf("SELECT folder_id FROM %q WHERE folder_path=%Q", DB_TABLE_FOLDER, path); - ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt); + ret = _media_svc_get_result_with_check_record(handle, sql, &sql_stmt); SQLITE3_SAFE_FREE(sql); - media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "_media_svc_sql_prepare_to_step failed [%d]", ret); + media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "_media_svc_get_result_with_check_record failed [%d]", ret); *folder_id = sqlite3_column_int64(sql_stmt, 0); @@ -182,7 +182,7 @@ int _media_svc_check_folder_by_path(sqlite3 *handle, const char *path) media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL"); sql = sqlite3_mprintf("SELECT 1 FROM %q WHERE folder_path=%Q", DB_TABLE_FOLDER, path); - ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt); + ret = _media_svc_get_result_with_check_record(handle, sql, &sql_stmt); SQLITE3_SAFE_FREE(sql); media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret); diff --git a/src/media-svc-media.c b/src/media-svc-media.c index 6c0c311..705bbd2 100755 --- a/src/media-svc-media.c +++ b/src/media-svc-media.c @@ -41,7 +41,7 @@ int _media_svc_check_data_by_path(sqlite3 *handle, const char *path) media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "Path is NULL"); sql = sqlite3_mprintf("SELECT 1 FROM %q WHERE media_path=%Q", DB_TABLE_MEDIA, path); - ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt); + ret = _media_svc_get_result_with_check_record(handle, sql, &sql_stmt); SQLITE3_SAFE_FREE(sql); media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret); SQLITE3_FINALIZE(sql_stmt); @@ -58,7 +58,7 @@ int _media_svc_get_modified_time(sqlite3 *handle, const char *path, int *modifie media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "Path is NULL"); sql = sqlite3_mprintf("SELECT media_modified_time FROM %q WHERE media_path=%Q", DB_TABLE_MEDIA, path); - ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt); + ret = _media_svc_get_result_with_check_record(handle, sql, &sql_stmt); SQLITE3_SAFE_FREE(sql); media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret); @@ -169,7 +169,7 @@ int _media_svc_get_thumbnail_path_by_path(sqlite3 *handle, const char *path, cha sql = sqlite3_mprintf("SELECT media_thumbnail_path FROM %q WHERE media_path=%Q", DB_TABLE_MEDIA, path); - ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt); + ret = _media_svc_get_result_with_check_record(handle, sql, &sql_stmt); SQLITE3_SAFE_FREE(sql); if (ret != MS_MEDIA_ERR_NONE) { if (ret == MS_MEDIA_ERR_DB_NO_RECORD) @@ -295,8 +295,8 @@ int _media_svc_get_media(sqlite3 *handle, const char *sql, GList **path_list) media_svc_retvm_if(!sql, MS_MEDIA_ERR_INVALID_PARAMETER, "query is NULL"); media_svc_retvm_if(!path_list, MS_MEDIA_ERR_INVALID_PARAMETER, "array is NULL"); - ret = _media_svc_sql_prepare_to_step_simple(handle, sql, &sql_stmt); - media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "_media_svc_sql_prepare_to_step_simple() failed [%d]", ret); + ret = _media_svc_get_result(handle, sql, &sql_stmt); + media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "_media_svc_get_result() failed [%d]", ret); while (sqlite3_step(sql_stmt) == SQLITE_ROW) *path_list = g_list_append(*path_list, g_strdup((const char *)sqlite3_column_text(sql_stmt, 0))); @@ -316,9 +316,9 @@ int _media_svc_get_noti_info(sqlite3 *handle, const char *path, media_svc_noti_i media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL"); sql = sqlite3_mprintf("SELECT media_id, media_type, media_mime_type FROM %q WHERE media_path=%Q", DB_TABLE_MEDIA, path); - ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt); + ret = _media_svc_get_result_with_check_record(handle, sql, &sql_stmt); SQLITE3_SAFE_FREE(sql); - media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "_media_svc_sql_prepare_to_step() failed [%d]", ret); + media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "_media_svc_get_result_with_check_record() failed [%d]", ret); *item = g_new0(media_svc_noti_item, 1); diff --git a/src/media-svc-storage.c b/src/media-svc-storage.c index b3d355f..3b0e965 100755 --- a/src/media-svc-storage.c +++ b/src/media-svc-storage.c @@ -39,7 +39,7 @@ int _media_svc_check_storage(sqlite3 *handle, const char *storage_id, char **sto *validity = 0; sql = sqlite3_mprintf("SELECT storage_path, validity FROM %q WHERE storage_id=%Q", DB_TABLE_STORAGE, storage_id); - ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt); + ret = _media_svc_get_result_with_check_record(handle, sql, &sql_stmt); SQLITE3_SAFE_FREE(sql); media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret); @@ -104,7 +104,7 @@ static int __media_svc_delete_thumbnail(sqlite3 *handle) const char *sql = "SELECT media_thumbnail_path FROM media WHERE validity=0 AND media_thumbnail_path IS NOT NULL;"; sqlite3_stmt *sql_stmt = NULL; - ret = _media_svc_sql_prepare_to_step_simple(handle, sql, &sql_stmt); + ret = _media_svc_get_result(handle, sql, &sql_stmt); media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret); while (sqlite3_step(sql_stmt) == SQLITE_ROW) @@ -170,7 +170,7 @@ int _media_svc_get_storage_uuid(sqlite3 *handle, const char *path, char *storage sql = sqlite3_mprintf("SELECT storage_id FROM %q WHERE validity=1 AND instr(%Q, storage_path)", DB_TABLE_STORAGE, path); - ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt); + ret = _media_svc_get_result_with_check_record(handle, sql, &sql_stmt); SQLITE3_SAFE_FREE(sql); media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret); -- 2.7.4