Change update query 80/174180/2 accepted/tizen/unified/20180403.060119 submit/tizen/20180402.053402
authorMinje Ahn <minje.ahn@samsung.com>
Thu, 29 Mar 2018 02:05:18 +0000 (11:05 +0900)
committerMinje Ahn <minje.ahn@samsung.com>
Thu, 29 Mar 2018 08:16:32 +0000 (17:16 +0900)
Modified 'media' to storage_id

Change-Id: Iadcd852800525f899af817cc7c72f3ab8465d216
Signed-off-by: Minje Ahn <minje.ahn@samsung.com>
src/include/util/media-thumb-db.h
src/util/media-thumb-db.c

index c1ccec1..146ebf2 100755 (executable)
@@ -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);
index 5fdc614..3431df2 100755 (executable)
@@ -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);