From bddb7b6537d4d96c29c3343ce454a1b1462c07a4 Mon Sep 17 00:00:00 2001 From: Minje Ahn Date: Mon, 22 May 2017 15:22:48 +0900 Subject: Remove and merge DB operation Change-Id: I86b50705f05f68307a0b0d76df244e740626026c Signed-off-by: Minje Ahn --- src/util/media-thumb-db.c | 312 ++++------------------------------------------ 1 file changed, 24 insertions(+), 288 deletions(-) (limited to 'src/util') diff --git a/src/util/media-thumb-db.c b/src/util/media-thumb-db.c index 540d31b..33d00ca 100755 --- a/src/util/media-thumb-db.c +++ b/src/util/media-thumb-db.c @@ -34,165 +34,37 @@ sqlite3 *_media_thumb_db_get_handle() return db_handle; } -int _media_thumb_get_type_from_db(sqlite3 *handle, - const char *origin_path, - int *type) -{ - int err = MS_MEDIA_ERR_NONE; - char *path_string = NULL; - char *query_string = NULL; - sqlite3_stmt *stmt = NULL; - - thumb_dbg_slog("Origin path : %s", origin_path); - - if (handle == NULL) { - thumb_err("DB handle is NULL"); - return MS_MEDIA_ERR_INVALID_PARAMETER; - } - if (!STRING_VALID(origin_path)) { - thumb_err("Invalid origin_path"); - return MS_MEDIA_ERR_INVALID_PARAMETER; - } - - path_string = sqlite3_mprintf("%s", origin_path); - if (!STRING_VALID(path_string)) { - thumb_err("Memory allocation is failed"); - return MS_MEDIA_ERR_OUT_OF_MEMORY; - } - query_string = sqlite3_mprintf(SELECT_TYPE_BY_PATH, path_string); - if (!STRING_VALID(query_string)) { - thumb_err("Memory allocation is failed"); - sqlite3_free(path_string); - return MS_MEDIA_ERR_OUT_OF_MEMORY; - } - - thumb_dbg("Query: %s", query_string); - - err = sqlite3_prepare_v2(handle, query_string, strlen(query_string), &stmt, NULL); - - sqlite3_free(query_string); - sqlite3_free(path_string); - - if (SQLITE_OK != err) { - thumb_err("prepare error [%s]", sqlite3_errmsg(handle)); - return MS_MEDIA_ERR_DB_INTERNAL; - } - - err = sqlite3_step(stmt); - if (err != SQLITE_ROW) { - thumb_err("end of row [%s]", sqlite3_errmsg(handle)); - sqlite3_finalize(stmt); - return MS_MEDIA_ERR_DB_NO_RECORD; - } - - *type = sqlite3_column_int(stmt, 0); - sqlite3_finalize(stmt); - - return MS_MEDIA_ERR_NONE; -} - - -int _media_thumb_get_wh_from_db(sqlite3 *handle, +int _media_thumb_get_thumb_path_wh_from_db(sqlite3 *handle, const char *origin_path, + char *thumb_path, + int max_length, int *width, int *height) { - thumb_dbg_slog("Origin path : %s", origin_path); - - if (handle == NULL) { - thumb_err("DB handle is NULL"); - return MS_MEDIA_ERR_INVALID_PARAMETER; - } - if (!STRING_VALID(origin_path)) { - thumb_err("Invalid origin_path"); - return MS_MEDIA_ERR_INVALID_PARAMETER; - } int err = MS_MEDIA_ERR_NONE; - char *path_string = NULL; char *query_string = NULL; sqlite3_stmt *stmt = NULL; - path_string = sqlite3_mprintf("%s", origin_path); - if (!STRING_VALID(path_string)) { - thumb_err("Memory allocation is failed"); - return MS_MEDIA_ERR_OUT_OF_MEMORY; - } - - query_string = sqlite3_mprintf(SELECT_WH_BY_PATH, path_string); - if (!STRING_VALID(query_string)) { - thumb_err("Memory allocation is failed"); - sqlite3_free(path_string); - return MS_MEDIA_ERR_OUT_OF_MEMORY; - } - - thumb_dbg_slog("Query: %s", query_string); - - err = sqlite3_prepare_v2(handle, query_string, strlen(query_string), &stmt, NULL); - - sqlite3_free(query_string); - sqlite3_free(path_string); - - if (SQLITE_OK != err) { - thumb_err("prepare error [%s]", sqlite3_errmsg(handle)); - return MS_MEDIA_ERR_DB_INTERNAL; - } - - err = sqlite3_step(stmt); - if (err != SQLITE_ROW) { - thumb_err("end of row [%s]", sqlite3_errmsg(handle)); - sqlite3_finalize(stmt); - return MS_MEDIA_ERR_DB_INTERNAL; - } - - *width = sqlite3_column_int(stmt, 0); - *height = sqlite3_column_int(stmt, 1); - sqlite3_finalize(stmt); - - return MS_MEDIA_ERR_NONE; -} - -int _media_thumb_get_thumb_path_from_db(sqlite3 *handle, - const char *origin_path, - char *thumb_path, - int max_length) -{ - thumb_dbg_slog("Origin path : %s", origin_path); - if (handle == NULL) { thumb_err("DB handle is NULL"); return MS_MEDIA_ERR_INVALID_PARAMETER; } + if (!STRING_VALID(origin_path)) { thumb_err("Invalid origin_path"); return MS_MEDIA_ERR_INVALID_PARAMETER; } - int err = MS_MEDIA_ERR_NONE; - char *path_string = NULL; - char *query_string = NULL; - sqlite3_stmt *stmt = NULL; - - path_string = sqlite3_mprintf("%s", origin_path); - if (!STRING_VALID(path_string)) { - thumb_err("Memory allocation is failed"); - return MS_MEDIA_ERR_OUT_OF_MEMORY; - } - - query_string = sqlite3_mprintf(SELECT_MEDIA_BY_PATH, path_string); + query_string = sqlite3_mprintf(SELECT_THUMB_BY_PATH, origin_path); if (!STRING_VALID(query_string)) { thumb_err("Memory allocation is failed"); - sqlite3_free(path_string); return MS_MEDIA_ERR_OUT_OF_MEMORY; } thumb_dbg_slog("Query: %s", query_string); - err = sqlite3_prepare_v2(handle, query_string, strlen(query_string), &stmt, NULL); - sqlite3_free(query_string); - sqlite3_free(path_string); - if (SQLITE_OK != err) { thumb_err("prepare error [%s]", sqlite3_errmsg(handle)); return MS_MEDIA_ERR_DB_INTERNAL; @@ -205,112 +77,21 @@ int _media_thumb_get_thumb_path_from_db(sqlite3 *handle, return MS_MEDIA_ERR_DB_INTERNAL; } - if (sqlite3_column_text(stmt, 0)) + if (sqlite3_column_text(stmt, 0)) { strncpy(thumb_path, (const char *)sqlite3_column_text(stmt, 0), max_length); - else + *width = sqlite3_column_int(stmt, 1); + *height = sqlite3_column_int(stmt, 2); + } else { thumb_path[0] = '\0'; + *width = 0; + *height = 0; + } sqlite3_finalize(stmt); return MS_MEDIA_ERR_NONE; } -int _media_thumb_update_thumb_path_to_db(sqlite3 *handle, - const char *origin_path, - char *thumb_path, - uid_t uid) -{ - int err = MS_MEDIA_ERR_NONE; - char *path_string = NULL; - char *thumbpath_string = NULL; - char *query_string = NULL; - - if (handle == NULL) { - thumb_err("DB handle is NULL"); - return MS_MEDIA_ERR_INVALID_PARAMETER; - } - if (!STRING_VALID(origin_path)) { - thumb_err("Invalid origin_path"); - return MS_MEDIA_ERR_INVALID_PARAMETER; - } - - path_string = sqlite3_mprintf("%s", origin_path); - if (!STRING_VALID(path_string)) { - thumb_err("Memory allocation is failed"); - return MS_MEDIA_ERR_OUT_OF_MEMORY; - } - thumbpath_string = sqlite3_mprintf("%s", thumb_path); - if (!STRING_VALID(thumbpath_string)) { - thumb_err("Memory allocation is failed"); - sqlite3_free(path_string); - return MS_MEDIA_ERR_OUT_OF_MEMORY; - } - query_string = sqlite3_mprintf(UPDATE_THUMB_BY_PATH, thumbpath_string, path_string); - if (!STRING_VALID(query_string)) { - thumb_err("Memory allocation is failed"); - sqlite3_free(path_string); - sqlite3_free(thumbpath_string); - return MS_MEDIA_ERR_OUT_OF_MEMORY; - } - - err = media_db_request_update_db(query_string, uid); - if (err != MS_MEDIA_ERR_NONE) { - thumb_err("media_db_request_update_db failed : %d", err); - } else { - thumb_dbg("Query success"); - } - - sqlite3_free(path_string); - sqlite3_free(thumbpath_string); - sqlite3_free(query_string); - - return err; -} - -int _media_thumb_update_wh_to_db(sqlite3 *handle, - const char *origin_path, - int width, - int height, - uid_t uid) -{ - int err = MS_MEDIA_ERR_NONE; - char *path_string = NULL; - char *query_string = NULL; - - if (handle == NULL) { - thumb_err("DB handle is NULL"); - return MS_MEDIA_ERR_INVALID_PARAMETER; - } - if (!STRING_VALID(origin_path)) { - thumb_err("Invalid origin_path"); - return MS_MEDIA_ERR_INVALID_PARAMETER; - } - - path_string = sqlite3_mprintf("%s", origin_path); - if (!STRING_VALID(path_string)) { - thumb_err("Memory allocation is failed"); - return MS_MEDIA_ERR_OUT_OF_MEMORY; - } - query_string = sqlite3_mprintf(UPDATE_WH_BY_PATH, width, height, path_string); - if (!STRING_VALID(query_string)) { - thumb_err("Memory allocation is failed"); - sqlite3_free(path_string); - return MS_MEDIA_ERR_OUT_OF_MEMORY; - } - - err = media_db_request_update_db(query_string, uid); - if (err != MS_MEDIA_ERR_NONE) { - thumb_err("media_db_request_update_db failed : %d", err); - } else { - thumb_dbg("Query success"); - } - - sqlite3_free(path_string); - sqlite3_free(query_string); - - return err; -} - int _media_thumb_update_thumb_path_wh_to_db(sqlite3 *handle, const char *origin_path, char *thumb_path, @@ -319,7 +100,6 @@ int _media_thumb_update_thumb_path_wh_to_db(sqlite3 *handle, uid_t uid) { int err = MS_MEDIA_ERR_NONE; - char *path_string = NULL; char *query_string = NULL; if (handle == NULL) { @@ -331,15 +111,13 @@ int _media_thumb_update_thumb_path_wh_to_db(sqlite3 *handle, return MS_MEDIA_ERR_INVALID_PARAMETER; } - path_string = sqlite3_mprintf("%s", origin_path); - if (!STRING_VALID(path_string)) { - thumb_err("Memory allocation is failed"); - return MS_MEDIA_ERR_OUT_OF_MEMORY; - } - query_string = sqlite3_mprintf(UPDATE_THUMB_WH_BY_PATH, thumb_path, width, height, path_string); + if (width > 0 && height > 0) + query_string = sqlite3_mprintf(UPDATE_THUMB_WH_BY_PATH, thumb_path, width, height, origin_path); + else + query_string = sqlite3_mprintf(UPDATE_THUMB_BY_PATH, thumb_path, origin_path); + if (!STRING_VALID(query_string)) { thumb_err("Memory allocation is failed"); - sqlite3_free(path_string); return MS_MEDIA_ERR_OUT_OF_MEMORY; } @@ -350,7 +128,6 @@ int _media_thumb_update_thumb_path_wh_to_db(sqlite3 *handle, thumb_dbg("Query success"); } - sqlite3_free(path_string); sqlite3_free(query_string); return err; @@ -377,8 +154,6 @@ int _media_thumb_db_disconnect() err = media_db_disconnect(db_handle); if (err != MS_MEDIA_ERR_NONE) { thumb_err("media_db_disconnect failed: %d", err); - db_handle = NULL; - return err; } db_handle = NULL; @@ -393,9 +168,10 @@ int _media_thumb_get_thumb_from_db_with_size(const char *origin_path, int *height) { int err = MS_MEDIA_ERR_NONE; + int orig_w = 0; + int orig_h = 0; - //err = minfo_get_thumb_path(mb_svc_handle, origin_path, thumb_path, max_length); - err = _media_thumb_get_thumb_path_from_db(db_handle, origin_path, thumb_path, max_length); + err = _media_thumb_get_thumb_path_wh_from_db(db_handle, origin_path, thumb_path, max_length, &orig_w, &orig_h); if (err != MS_MEDIA_ERR_NONE) { thumb_warn("Original path doesn't exist in DB"); return err; @@ -415,17 +191,8 @@ int _media_thumb_get_thumb_from_db_with_size(const char *origin_path, return MS_MEDIA_ERR_INTERNAL; } else { thumb_dbg("This thumb path already exist"); - int orig_w = 0; - int orig_h = 0; - - err = _media_thumb_get_wh_from_db(db_handle, origin_path, &orig_w, &orig_h); - if (err != MS_MEDIA_ERR_NONE) { - thumb_err("_media_thumb_get_wh_from_db failed : %d", err); - } else { - thumb_err("_media_thumb_get_wh_from_db Success ( w:%d, h:%d )", orig_w, orig_h); - *width = orig_w; - *height = orig_h; - } + *width = orig_w; + *height = orig_h; } return MS_MEDIA_ERR_NONE; @@ -438,44 +205,13 @@ int _media_thumb_update_db(const char *origin_path, uid_t uid) { int err = MS_MEDIA_ERR_NONE; - int media_type = THUMB_NONE_TYPE; - err = _media_thumb_get_type_from_db(db_handle, origin_path, &media_type); + err = _media_thumb_update_thumb_path_wh_to_db(db_handle, origin_path, thumb_path, width, height, uid); if (err != MS_MEDIA_ERR_NONE) { - thumb_err("_media_thumb_get_type_from_db (%s) failed: %d", origin_path, err); - return err; - } - -#if 0 - err = _media_thumb_update_thumb_path_to_db(db_handle, origin_path, thumb_path); - if (err < 0) { - thumb_err("_media_thumb_update_thumb_path_to_db (%s) failed: %d", origin_path, err); + thumb_err("_media_thumb_update_wh_to_db (%s) failed: %d", origin_path, err); return err; } - if (media_type == THUMB_IMAGE_TYPE && width > 0 && height > 0) { - err = _media_thumb_update_wh_to_db(db_handle, origin_path, width, height); - if (err < 0) { - thumb_err("_media_thumb_update_wh_to_db (%s) failed: %d", origin_path, err); - return err; - } - } -#else - if (media_type == THUMB_IMAGE_TYPE && width > 0 && height > 0) { - err = _media_thumb_update_thumb_path_wh_to_db(db_handle, origin_path, thumb_path, width, height, uid); - if (err != MS_MEDIA_ERR_NONE) { - thumb_err("_media_thumb_update_wh_to_db (%s) failed: %d", origin_path, err); - return err; - } - } else { - err = _media_thumb_update_thumb_path_to_db(db_handle, origin_path, thumb_path, uid); - if (err != MS_MEDIA_ERR_NONE) { - thumb_err("_media_thumb_update_thumb_path_to_db (%s) failed: %d", origin_path, err); - return err; - } - } -#endif - thumb_dbg("_media_thumb_update_db success"); return MS_MEDIA_ERR_NONE; -- cgit v1.2.3