From 12345c8796fe146da2a0c898a8c7de66e15dcdf8 Mon Sep 17 00:00:00 2001 From: Minje Ahn Date: Thu, 29 Mar 2018 11:05:18 +0900 Subject: Change update query Modified 'media' to storage_id Change-Id: Iadcd852800525f899af817cc7c72f3ab8465d216 Signed-off-by: Minje Ahn --- src/include/util/media-thumb-db.h | 5 ++-- src/util/media-thumb-db.c | 55 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 57 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/include/util/media-thumb-db.h b/src/include/util/media-thumb-db.h index c1ccec1..146ebf2 100755 --- a/src/include/util/media-thumb-db.h +++ b/src/include/util/media-thumb-db.h @@ -29,8 +29,9 @@ #define SQLITE3_FINALIZE(x) {if (x != NULL) sqlite3_finalize(x); } #define SQLITE3_SAFE_FREE(x) {if (x != NULL) {sqlite3_free(x); x = NULL; } } -#define SELECT_THUMB_BY_PATH "SELECT thumbnail_path FROM media WHERE path='%q' AND thumbnail_path IS NOT NULL;" -#define UPDATE_THUMB_BY_PATH "UPDATE media SET thumbnail_path = '%q' WHERE path='%q';" +#define SELECT_THUMB_BY_PATH "SELECT thumbnail_path FROM media_view WHERE path='%q' AND thumbnail_path IS NOT NULL;" +#define SELECT_STORAGE_ID_BY_PATH "SELECT storage_uuid FROM media_view WHERE path='%q';" +#define UPDATE_THUMB_BY_PATH "UPDATE '%q' SET thumbnail_path = '%q' WHERE path='%q';" int _media_thumb_get_thumb_from_db(const char *origin_path, char *thumb_path, int max_length, uid_t uid); int _media_thumb_update_db(const char *origin_path, char *thumb_path, uid_t uid); diff --git a/src/util/media-thumb-db.c b/src/util/media-thumb-db.c index 5fdc614..3431df2 100755 --- a/src/util/media-thumb-db.c +++ b/src/util/media-thumb-db.c @@ -75,14 +75,67 @@ int _media_thumb_get_thumb_from_db(const char *origin_path, char *thumb_path, in return MS_MEDIA_ERR_NONE; } +int __media_thumb_get_storage_id(const char *origin_path, uid_t uid, char **storage_id) +{ + int err = MS_MEDIA_ERR_NONE; + char *query_string = NULL; + sqlite3_stmt *stmt = NULL; + MediaDBHandle *db_handle = NULL; + + thumb_retvm_if(!STRING_VALID(origin_path), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid origin_path"); + + query_string = sqlite3_mprintf(SELECT_STORAGE_ID_BY_PATH, origin_path); + thumb_retvm_if(!STRING_VALID(query_string), MS_MEDIA_ERR_OUT_OF_MEMORY, "Memory allocation is failed"); + thumb_dbg_slog("Query: %s", query_string); + + err = media_db_connect(&db_handle, uid, FALSE); + if (err != MS_MEDIA_ERR_NONE) { + thumb_err("media_db_connect failed: %d", err); + db_handle = NULL; + SQLITE3_SAFE_FREE(query_string); + return err; + } + + err = sqlite3_prepare_v2(db_handle, query_string, strlen(query_string), &stmt, NULL); + SQLITE3_SAFE_FREE(query_string); + if (SQLITE_OK != err) { + thumb_err("prepare error [%s]", sqlite3_errmsg(db_handle)); + media_db_disconnect(db_handle); + + return MS_MEDIA_ERR_DB_INTERNAL; + } + + if (sqlite3_step(stmt) == SQLITE_ROW) { + *storage_id = g_strdup((const char *)sqlite3_column_text(stmt, 0)); + } else { + thumb_err("end of row [%s]", sqlite3_errmsg(db_handle)); + SQLITE3_FINALIZE(stmt); + media_db_disconnect(db_handle); + + return MS_MEDIA_ERR_DB_INTERNAL; + } + + SQLITE3_FINALIZE(stmt); + media_db_disconnect(db_handle); + + return MS_MEDIA_ERR_NONE; +} + int _media_thumb_update_db(const char *origin_path, char *thumb_path, uid_t uid) { int err = MS_MEDIA_ERR_NONE; char *query_string = NULL; + char *storage_id = NULL; thumb_retvm_if(!STRING_VALID(origin_path), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid origin_path"); - query_string = sqlite3_mprintf(UPDATE_THUMB_BY_PATH, thumb_path, origin_path); + /*Get storage_id */ + err = __media_thumb_get_storage_id(origin_path, uid, &storage_id); + thumb_retvm_if(err != MS_MEDIA_ERR_NONE, err, "Failed to get storage_id"); + thumb_retvm_if(storage_id == NULL, MS_MEDIA_ERR_OUT_OF_MEMORY, "Memory allocation is failed"); + + query_string = sqlite3_mprintf(UPDATE_THUMB_BY_PATH, storage_id, thumb_path, origin_path); + SAFE_FREE(storage_id); thumb_retvm_if(!STRING_VALID(query_string), MS_MEDIA_ERR_OUT_OF_MEMORY, "Memory allocation is failed"); err = media_db_request_update_db(query_string, uid); -- cgit v1.2.3