Exception handling and behavior improvements 91/183991/3
authorMinje Ahn <minje.ahn@samsung.com>
Fri, 13 Jul 2018 02:39:03 +0000 (11:39 +0900)
committerMinje Ahn <minje.ahn@samsung.com>
Mon, 16 Jul 2018 02:31:42 +0000 (11:31 +0900)
Change-Id: Iea495c4ae0f13dc0ac382b4eaec29823ad45390f
Signed-off-by: Minje Ahn <minje.ahn@samsung.com>
src/media_bookmark.c
src/media_db.c
src/media_face.c
src/media_group.c
src/media_info.c
src/media_playlist.c
src/media_pvr.c
src/media_storage.c
src/media_tag.c
src/media_uhd.c

index 8e2cca4..96ae824 100755 (executable)
@@ -33,7 +33,7 @@ static int __media_bookmark_check_media_id(const char *media_id)
        SQLITE3_SAFE_FREE(query_str);
        media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
 
-       while (sqlite3_step(stmt) == SQLITE_ROW)
+       if (sqlite3_step(stmt) == SQLITE_ROW)
                item_count = (int)sqlite3_column_int(stmt, 0);
 
        SQLITE3_FINALIZE(stmt);
@@ -350,7 +350,7 @@ int media_bookmark_insert_to_db_v2(media_bookmark_h bookmark)
        SQLITE3_SAFE_FREE(select_query);
        media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
 
-       while (sqlite3_step(stmt) == SQLITE_ROW)
+       if (sqlite3_step(stmt) == SQLITE_ROW)
                bookmark_id = (int)sqlite3_column_int(stmt, 0);
 
        SQLITE3_FINALIZE(stmt);
index c50e8e2..9b8c6c2 100755 (executable)
@@ -334,7 +334,7 @@ int _media_db_get_group_count(filter_h filter, group_list_e group_type, int *gro
        SAFE_FREE(option_query);
        media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
 
-       while (sqlite3_step(stmt) == SQLITE_ROW)
+       if (sqlite3_step(stmt) == SQLITE_ROW)
                *group_count = (int)sqlite3_column_int(stmt, 0);
 
        SQLITE3_FINALIZE(stmt);
@@ -395,7 +395,7 @@ int _media_db_get_media_group_count(media_group_e group, filter_h filter, int *g
        SAFE_FREE(option_query);
        media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
 
-       while (sqlite3_step(stmt) == SQLITE_ROW)
+       if (sqlite3_step(stmt) == SQLITE_ROW)
                *group_count = (int)sqlite3_column_int(stmt, 0);
 
        SQLITE3_FINALIZE(stmt);
@@ -979,7 +979,7 @@ int _media_db_get_group_item_count_by_id(int group_id, filter_h filter, group_li
        SAFE_FREE(option_query);
        media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
 
-       while (sqlite3_step(stmt) == SQLITE_ROW)
+       if (sqlite3_step(stmt) == SQLITE_ROW)
                *item_count = (int)sqlite3_column_int(stmt, 0);
 
        SQLITE3_FINALIZE(stmt);
@@ -1091,7 +1091,7 @@ int _media_db_get_group_item_count(const char *group_name, filter_h filter, grou
        SAFE_FREE(option_query);
        media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
 
-       while (sqlite3_step(stmt) == SQLITE_ROW)
+       if (sqlite3_step(stmt) == SQLITE_ROW)
                *item_count = (int)sqlite3_column_int(stmt, 0);
 
        SQLITE3_FINALIZE(stmt);
@@ -1401,7 +1401,7 @@ int _media_db_get_media_group_item_count(const char *group_name, filter_h filter
        SAFE_FREE(option_query);
        media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
 
-       while (sqlite3_step(stmt) == SQLITE_ROW)
+       if (sqlite3_step(stmt) == SQLITE_ROW)
                *item_count = (int)sqlite3_column_int(stmt, 0);
 
        SQLITE3_FINALIZE(stmt);
index 152c0d5..cff1beb 100755 (executable)
@@ -33,7 +33,7 @@ static int __media_face_check_media_id(const char *media_id)
        SQLITE3_SAFE_FREE(query_str);
        media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
 
-       while (sqlite3_step(stmt) == SQLITE_ROW)
+       if (sqlite3_step(stmt) == SQLITE_ROW)
                item_count = (int)sqlite3_column_int(stmt, 0);
 
        SQLITE3_FINALIZE(stmt);
@@ -262,7 +262,7 @@ int media_face_insert_to_db(media_face_h face)
        SQLITE3_SAFE_FREE(query_str);
        media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
 
-       while (sqlite3_step(stmt) == SQLITE_ROW)
+       if (sqlite3_step(stmt) == SQLITE_ROW)
                _face->face_id = (int)sqlite3_column_int(stmt, 0);
 
        SQLITE3_FINALIZE(stmt);
index d6efd95..675640c 100755 (executable)
@@ -92,7 +92,7 @@ int media_album_get_album_from_db(int album_id, media_album_h *album)
        ret = _content_query_prepare(&stmt, select_query, NULL, NULL);
        media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
 
-       while (sqlite3_step(stmt) == SQLITE_ROW) {
+       if (sqlite3_step(stmt) == SQLITE_ROW) {
                media_album_s *_album = (media_album_s*)calloc(1, sizeof(media_album_s));
                if (_album == NULL) {
                        media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
index 1a282be..0c4b057 100755 (executable)
@@ -464,9 +464,7 @@ int _media_info_get_media_info_from_db(const char *path, const char *storage_id,
        if (sqlite3_step(stmt) == SQLITE_ROW) {
                _media_info_item_get_detail(stmt, (media_info_h)_media);
        } else {
-               media_content_error("There's no media!!");
-               media_content_error("%s", path);
-               media_content_error("%s", storage_id);
+               media_content_sec_error("No media : path[%s] storage id[%s]", path, storage_id);
                ret = MEDIA_CONTENT_ERROR_DB_FAILED;
        }
 
@@ -2487,10 +2485,7 @@ int media_info_get_media_from_db(const char *media_id, media_info_h *media)
 
        media_info_s *_media = NULL;
 
-       while (sqlite3_step(stmt) == SQLITE_ROW) {
-               if (_media)
-                       media_info_destroy((media_info_h)_media);
-
+       if (sqlite3_step(stmt) == SQLITE_ROW) {
                _media = (media_info_s*)calloc(1, sizeof(media_info_s));
 
                if (_media == NULL) {
@@ -2502,6 +2497,8 @@ int media_info_get_media_from_db(const char *media_id, media_info_h *media)
                _media_info_item_get_detail(stmt, (media_info_h)_media);
 
                *media = (media_info_h)_media;
+       } else {
+               ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
        }
 
        SQLITE3_FINALIZE(stmt);
index 48686b9..cc4db76 100755 (executable)
@@ -88,7 +88,7 @@ static int __media_playlist_insert_playlist_record(const char *playlist_name, in
        SQLITE3_SAFE_FREE(select_query);
        media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
 
-       while (sqlite3_step(stmt) == SQLITE_ROW)
+       if (sqlite3_step(stmt) == SQLITE_ROW)
                *playlist_id = (int)sqlite3_column_int(stmt, 0);
 
        SQLITE3_FINALIZE(stmt);
@@ -112,7 +112,7 @@ static int __media_playlist_insert_item_to_playlist(int playlist_id, const char
        ret = _content_query_prepare(&stmt, select_query, NULL, NULL);
        media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
 
-       while (sqlite3_step(stmt) == SQLITE_ROW)
+       if (sqlite3_step(stmt) == SQLITE_ROW)
                play_order = (int)sqlite3_column_int(stmt, 0);
 
        SQLITE3_FINALIZE(stmt);
@@ -504,10 +504,7 @@ int media_playlist_get_playlist_from_db(int playlist_id, media_playlist_h *playl
 
                media_playlist_s *_playlist = NULL;
 
-               while (sqlite3_step(stmt) == SQLITE_ROW) {
-                       if (_playlist)
-                               media_playlist_destroy((media_playlist_h)_playlist);
-
+               if (sqlite3_step(stmt) == SQLITE_ROW) {
                        _playlist = (media_playlist_s*)calloc(1, sizeof(media_playlist_s));
                        if (_playlist == NULL) {
                                media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
@@ -520,6 +517,9 @@ int media_playlist_get_playlist_from_db(int playlist_id, media_playlist_h *playl
                        _playlist->thumbnail_path = g_strdup((const char *)sqlite3_column_text(stmt, 3));
 
                        *playlist = (media_playlist_h)_playlist;
+               } else {
+                       media_content_error("Nonexistent playlist id[%d]", playlist_id);
+                       ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
                }
 
                SQLITE3_FINALIZE(stmt);
@@ -611,7 +611,7 @@ int media_playlist_get_play_order(media_playlist_h playlist, int playlist_member
        ret = _content_query_prepare(&stmt, select_query, NULL, NULL);
        media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
 
-       while (sqlite3_step(stmt) == SQLITE_ROW)
+       if (sqlite3_step(stmt) == SQLITE_ROW)
                *play_order = (int)sqlite3_column_int(stmt, 0);
 
        SQLITE3_FINALIZE(stmt);
@@ -995,7 +995,7 @@ int media_playlist_get_play_order_v2(int playlist_id, int playlist_member_id, in
        ret = _content_query_prepare(&stmt, select_query, NULL, NULL);
        media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
 
-       while (sqlite3_step(stmt) == SQLITE_ROW)
+       if (sqlite3_step(stmt) == SQLITE_ROW)
                *play_order = (int)sqlite3_column_int(stmt, 0);
 
        SQLITE3_FINALIZE(stmt);
index 70739f8..9b33323 100755 (executable)
@@ -269,10 +269,7 @@ int media_pvr_get_pvr_from_db(const char *media_id, media_pvr_h *pvr)
 
        media_pvr_s *_pvr = NULL;
 
-       while (sqlite3_step(stmt) == SQLITE_ROW) {
-               if (_pvr)
-                       media_pvr_destroy((media_pvr_h)_pvr);
-
+       if (sqlite3_step(stmt) == SQLITE_ROW) {
                _pvr = (media_pvr_s*)calloc(1, sizeof(media_pvr_s));
 
                if (_pvr == NULL) {
@@ -284,6 +281,9 @@ int media_pvr_get_pvr_from_db(const char *media_id, media_pvr_h *pvr)
                _media_pvr_item_get_detail(stmt, (media_pvr_h)_pvr);
 
                *pvr = (media_info_h)_pvr;
+       } else {
+               media_content_error("Nonexistent media_id[%s]", media_id);
+               ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
        }
 
        SQLITE3_FINALIZE(stmt);
index edf6d2e..0a18606 100755 (executable)
@@ -23,6 +23,7 @@ int media_storage_get_storage_info_from_db(const char *storage_id, media_storage
        media_content_warn("DEPRECATION WARNING: media_storage_get_storage_info_from_db() is deprecated and will be removed from next release.");
        char select_query[DEFAULT_QUERY_SIZE] = {0, };
        sqlite3_stmt *stmt = NULL;
+       media_storage_s *_storage = NULL;
 
        if (!STRING_VALID(storage_id) || (storage == NULL)) {
                media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
@@ -35,8 +36,8 @@ int media_storage_get_storage_info_from_db(const char *storage_id, media_storage
        ret = _content_query_prepare(&stmt, select_query, NULL, NULL);
        media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
 
-       while (sqlite3_step(stmt) == SQLITE_ROW) {
-               media_storage_s *_storage = (media_storage_s*)calloc(1, sizeof(media_storage_s));
+       if (sqlite3_step(stmt) == SQLITE_ROW) {
+               _storage = (media_storage_s*)calloc(1, sizeof(media_storage_s));
 
                if (_storage == NULL) {
                        media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
@@ -49,6 +50,9 @@ int media_storage_get_storage_info_from_db(const char *storage_id, media_storage
                _storage->storage_type = (int)sqlite3_column_int(stmt, 2);
 
                *storage = (media_storage_h)_storage;
+       } else {
+               media_content_error("Nonexistent storage id[%s]", storage_id);
+               ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
        }
 
        SQLITE3_FINALIZE(stmt);
index 6c78eb6..de49579 100755 (executable)
@@ -91,8 +91,6 @@ static int __media_tag_get_tag_info_from_db(const char *name, media_tag_h tag)
        int ret = MEDIA_CONTENT_ERROR_NONE;
        sqlite3_stmt *stmt = NULL;
        char *select_query = NULL;
-       int id = 0;
-       char *tag_name = NULL;
        media_tag_s *_tag = (media_tag_s*)tag;
 
        media_content_retvm_if(_tag == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid tag");
@@ -103,16 +101,14 @@ static int __media_tag_get_tag_info_from_db(const char *name, media_tag_h tag)
        SQLITE3_SAFE_FREE(select_query);
        media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
 
-       while (sqlite3_step(stmt) == SQLITE_ROW) {
-               SAFE_FREE(tag_name);
-
-               id = (int)sqlite3_column_int(stmt, 0);
-               tag_name = g_strdup((const char *)sqlite3_column_text(stmt, 1));
+       if (sqlite3_step(stmt) == SQLITE_ROW) {
+               _tag->tag_id = (int)sqlite3_column_int(stmt, 0);
+               _tag->name = g_strdup((const char *)sqlite3_column_text(stmt, 1));
+       } else {
+               media_content_error("Nonexistent tag name[%s]", name);
+               ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
        }
 
-       _tag->tag_id = id;
-       _tag->name = tag_name;
-
        SQLITE3_FINALIZE(stmt);
 
        return ret;
@@ -321,10 +317,7 @@ int media_tag_get_tag_from_db(int tag_id, media_tag_h *tag)
 
        media_tag_s *_tag = NULL;
 
-       while (sqlite3_step(stmt) == SQLITE_ROW) {
-               if (_tag)
-                       media_tag_destroy((media_tag_h)_tag);
-
+       if (sqlite3_step(stmt) == SQLITE_ROW) {
                _tag = (media_tag_s*)calloc(1, sizeof(media_tag_s));
                if (_tag == NULL) {
                        SQLITE3_FINALIZE(stmt);
@@ -336,6 +329,9 @@ int media_tag_get_tag_from_db(int tag_id, media_tag_h *tag)
                _tag->name = g_strdup((const char *)sqlite3_column_text(stmt, 1));
 
                *tag = (media_tag_h)_tag;
+       } else {
+               media_content_error("Nonexistent tag id[%d]", tag_id);
+               ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
        }
 
        SQLITE3_FINALIZE(stmt);
index 39d9ef9..bfd857b 100755 (executable)
@@ -179,10 +179,7 @@ int media_uhd_get_uhd_from_db(const char *media_id, media_uhd_h *uhd)
 
        media_uhd_s *_uhd = NULL;
 
-       while (sqlite3_step(stmt) == SQLITE_ROW) {
-               if (_uhd)
-                       media_uhd_destroy((media_uhd_h)_uhd);
-
+       if (sqlite3_step(stmt) == SQLITE_ROW) {
                _uhd = (media_uhd_s*)calloc(1, sizeof(media_uhd_s));
 
                if (_uhd == NULL) {
@@ -194,6 +191,9 @@ int media_uhd_get_uhd_from_db(const char *media_id, media_uhd_h *uhd)
                _media_uhd_item_get_detail(stmt, (media_uhd_h)_uhd);
 
                *uhd = (media_uhd_h)_uhd;
+       } else {
+               media_content_error("Nonexistent media id[%s]", media_id);
+               ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
        }
 
        SQLITE3_FINALIZE(stmt);