From f4fcdcd1b064f219b7bb99f5a01705c6976af4fb Mon Sep 17 00:00:00 2001 From: Minje Ahn Date: Tue, 5 Nov 2019 10:09:40 +0900 Subject: [PATCH] Merge all storage tables Change-Id: Ied41832a17dbd5043756a1b8e5d16e582cdb3252 Signed-off-by: Minje Ahn --- include/media_info_private.h | 72 +++-- packaging/capi-content-media-content.spec | 2 +- src/media_db.c | 340 +++++++++++++++++++--- src/media_image.c | 9 +- src/media_info.c | 48 ++- 5 files changed, 398 insertions(+), 73 deletions(-) diff --git a/include/media_info_private.h b/include/media_info_private.h index 55c8784..e7e8cb2 100755 --- a/include/media_info_private.h +++ b/include/media_info_private.h @@ -352,7 +352,6 @@ typedef struct _media_content_cb_data { /* DB View */ #define DB_VIEW_PLAYLIST "playlist_view" #define DB_VIEW_TAG "tag_view" -#define DB_VIEW_MEDIA "media_view" /* DB field for media */ #define DB_FIELD_MEDIA_DISPLAY_NAME "media_display_name" @@ -389,14 +388,16 @@ typedef struct _media_content_cb_data { #define QUERY_KEYWORD_COLLATE " COLLATE " /* DB TABLE JOIN */ -#define FOLDER_MEDIA_JOIN DB_TABLE_FOLDER" NATURAL LEFT OUTER JOIN '%s' WHERE validity IN (1, 2) " -#define BOOKMARK_MEDIA_JOIN DB_TABLE_BOOKMARK" NATURAL JOIN '%s' WHERE validity IN (1, 2) " -#define ALBUM_MEDIA_JOIN DB_TABLE_ALBUM" NATURAL JOIN '%s' WHERE validity IN (1, 2) " -#define FACE_MEDIA_JOIN DB_TABLE_FACE" NATURAL JOIN '%s' WHERE validity IN (1, 2) " +#define FOLDER_MEDIA_JOIN DB_TABLE_FOLDER" NATURAL LEFT OUTER JOIN "DB_TABLE_MEDIA" WHERE validity IN (1, 2) " +#define BOOKMARK_MEDIA_JOIN DB_TABLE_BOOKMARK" NATURAL JOIN "DB_TABLE_MEDIA" WHERE validity IN (1, 2) " +#define ALBUM_MEDIA_JOIN DB_TABLE_ALBUM" NATURAL JOIN "DB_TABLE_MEDIA" WHERE validity IN (1, 2) " +#define FACE_MEDIA_JOIN DB_TABLE_FACE" NATURAL JOIN "DB_TABLE_MEDIA" WHERE validity IN (1, 2) " /* Get Group List */ #define SELECT_ALBUM_LIST "SELECT DISTINCT album_id, name, artist, album_art FROM "ALBUM_MEDIA_JOIN -#define SELECT_MEDIA_GROUP_LIST "SELECT DISTINCT %s FROM '%s' WHERE validity IN (1, 2) " +#define SELECT_ALBUM_LIST_BY_STORAGE_ID SELECT_ALBUM_LIST"AND storage_uuid='%s' " +#define SELECT_MEDIA_GROUP_LIST "SELECT DISTINCT %s FROM "DB_TABLE_MEDIA" WHERE validity IN (1, 2) " +#define SELECT_MEDIA_GROUP_LIST_BY_STORAGE_ID SELECT_MEDIA_GROUP_LIST"AND storage_uuid='%s' " #define SELECT_FOLDER_LIST "SELECT DISTINCT folder_id, folder_path, folder_name, folder_storage_type, storage_uuid FROM "FOLDER_MEDIA_JOIN #define SELECT_FOLDER_LIST_BY_STORAGE_ID SELECT_FOLDER_LIST"AND storage_uuid='%s' " @@ -405,22 +406,30 @@ typedef struct _media_content_cb_data { /* Get Group Count */ #define SELECT_ALBUM_COUNT "SELECT COUNT(DISTINCT album_id) FROM "ALBUM_MEDIA_JOIN +#define SELECT_ALBUM_COUNT_BY_STORAGE_ID SELECT_ALBUM_COUNT"AND storage_uuid='%s' " #define SELECT_FOLDER_COUNT "SELECT COUNT(DISTINCT folder_id) FROM "FOLDER_MEDIA_JOIN #define SELECT_FOLDER_COUNT_BY_STORAGE_ID SELECT_FOLDER_COUNT"AND storage_uuid='%s' " #define SELECT_TAG_COUNT "SELECT COUNT(DISTINCT tag_id) FROM "DB_VIEW_TAG" WHERE 1 " #define SELECT_PLAYLIST_COUNT "SELECT COUNT(DISTINCT playlist_id) FROM "DB_VIEW_PLAYLIST" WHERE 1 " #define SELECT_BOOKMARK_COUNT "SELECT COUNT(*) FROM "BOOKMARK_MEDIA_JOIN +#define SELECT_BOOKMARK_COUNT_BY_STORAGE_ID SELECT_BOOKMARK_COUNT"AND storage_uuid='%s' " #define SELECT_MEDIA_GROUP_COUNT "SELECT COUNT(*) FROM ("SELECT_MEDIA_GROUP_LIST +#define SELECT_MEDIA_GROUP_COUNT_BY_STORAGE_ID SELECT_MEDIA_GROUP_COUNT"AND storage_uuid='%s' " /*count(distinct x) count only non-null values, but select distinct X returns include null. so sync the result of count and list, don't use count(distinct x)*/ /* Get Media Count of Group */ #define SELECT_MEDIA_COUNT_FROM_MEDIA "SELECT COUNT(*) FROM ("SELECT_MEDIA_ITEM /*to apply limit condition. "SELECT COUNT(*) FROM "DB_TABLE_MEDIA" WHERE validity=1" */ -#define SELECT_MEDIA_COUNT_FROM_MEDIA_SIMPLE "SELECT COUNT(*) FROM '%s' WHERE validity IN (1, 2) " -#define SELECT_MEDIA_COUNT_FROM_ALBUM "SELECT COUNT(*) FROM '%s' WHERE validity IN (1, 2) AND album_id='%d'" +#define SELECT_MEDIA_COUNT_FROM_MEDIA_SIMPLE "SELECT COUNT(*) FROM "DB_TABLE_MEDIA" WHERE validity IN (1, 2) " +#define SELECT_MEDIA_COUNT_FROM_MEDIA_SIMPLE_BY_STORAGE_ID SELECT_MEDIA_COUNT_FROM_MEDIA_SIMPLE"AND storage_uuid='%s' " +#define SELECT_MEDIA_COUNT_FROM_ALBUM "SELECT COUNT(*) FROM "DB_TABLE_MEDIA" WHERE validity IN (1, 2) AND album_id='%d' " +#define SELECT_MEDIA_COUNT_FROM_ALBUM_BY_STORAGE_ID SELECT_MEDIA_COUNT_FROM_ALBUM"AND storage_uuid='%s' " #define SELECT_MEDIA_COUNT_FROM_GROUP "SELECT COUNT(*) FROM ("SELECT_MEDIA_FROM_GROUP /*to apply limit condition. */ +#define SELECT_MEDIA_COUNT_FROM_GROUP_BY_STORAGE_ID "SELECT COUNT(*) FROM ("SELECT_MEDIA_FROM_GROUP_BY_STORAGE_ID /*to apply limit condition. */ #define SELECT_MEDIA_COUNT_FROM_GROUP_NULL "SELECT COUNT(*) FROM ("SELECT_MEDIA_FROM_GROUP_NULL /* to apply limit condition. */ -#define SELECT_MEDIA_COUNT_FROM_FOLDER "SELECT COUNT(*) FROM '%s' WHERE validity IN (1, 2) AND folder_id='%q'" -#define SELECT_MEDIA_COUNT_FROM_STORAGE "SELECT COUNT(*) FROM '%s' WHERE validity IN (1, 2) AND storage_uuid='%q'" +#define SELECT_MEDIA_COUNT_FROM_GROUP_NULL_BY_STORAGE_ID "SELECT COUNT(*) FROM ("SELECT_MEDIA_FROM_GROUP_NULL_BY_STORAGE_ID /* to apply limit condition. */ +#define SELECT_MEDIA_COUNT_FROM_FOLDER "SELECT COUNT(*) FROM "DB_TABLE_MEDIA" WHERE validity IN (1, 2) AND folder_id='%q'" +#define SELECT_MEDIA_COUNT_FROM_FOLDER_BY_STORAGE_ID SELECT_MEDIA_COUNT_FROM_FOLDER" AND storage_uuid='%s' " +#define SELECT_MEDIA_COUNT_FROM_STORAGE "SELECT COUNT(*) FROM "DB_TABLE_MEDIA" WHERE validity IN (1, 2) AND storage_uuid='%q'" #define SELECT_MEDIA_COUNT_FROM_TAG "SELECT COUNT(*) FROM "DB_VIEW_TAG" WHERE (tag_id=%d AND tag_media_count>0) " #define SELECT_MEDIA_COUNT_FROM_PLAYLIST "SELECT COUNT(*) FROM "DB_VIEW_PLAYLIST" WHERE (playlist_id=%d and playlist_media_count>0) " @@ -461,26 +470,33 @@ typedef struct _media_content_cb_data { #define INSERT_BOOKMARK_TO_BOOKMARK "INSERT INTO "DB_TABLE_BOOKMARK" (media_id, bookmark_marked_time, bookmark_thumbnail_path, bookmark_name) VALUES ('%q', '%d', %Q, %Q)" #define SELECT_BOOKMARK_COUNT_BY_MEDIA_ID "SELECT COUNT(*) FROM "BOOKMARK_MEDIA_JOIN" AND media_id='%s'" #define SELECT_BOOKMARK_LIST "SELECT bookmark_id, media_id, bookmark_marked_time, bookmark_thumbnail_path, bookmark_name FROM "BOOKMARK_MEDIA_JOIN +#define SELECT_BOOKMARK_LIST_BY_STORAGE_ID SELECT_BOOKMARK_LIST"AND storage_uuid='%s' " #define SELECT_BOOKMARK_LIST_BY_MEDIA_ID "SELECT bookmark_id, media_id, bookmark_marked_time, bookmark_thumbnail_path, bookmark_name FROM "BOOKMARK_MEDIA_JOIN" AND media_id='%s'" #define SELECT_BOOKMARK_ID_FROM_BOOKMARK "SELECT bookmark_id FROM "DB_TABLE_BOOKMARK" WHERE media_id='%s' AND bookmark_marked_time=%d" #define UPDATE_BOOKMARK_FROM_BOOKMARK "UPDATE "DB_TABLE_BOOKMARK" SET bookmark_name=%Q WHERE bookmark_id=%d;" /* Update Meta*/ -#define UPDATE_IMAGE_META_FROM_MEDIA "UPDATE '%s' SET media_orientation=%d WHERE media_id='%q'" - -#define SELECT_MEDIA_ITEM "SELECT "MEDIA_INFO_ITEM" FROM '%s' WHERE validity IN (1, 2)" -#define SELECT_MEDIA_FROM_MEDIA "SELECT "MEDIA_INFO_ITEM" FROM '%s' WHERE validity IN (1, 2) AND media_id='%s'" -#define SELECT_MEDIA_BY_PATH "SELECT "MEDIA_INFO_ITEM" FROM '%s' WHERE validity=1 AND media_path='%q'" -#define SELECT_MEDIA_FROM_ALBUM "SELECT "MEDIA_INFO_ITEM" FROM '%s' WHERE validity IN (1, 2) AND album_id=%d" -#define SELECT_MEDIA_FROM_GROUP "SELECT "MEDIA_INFO_ITEM" FROM '%s' WHERE validity IN (1, 2) AND %s='%q'" -#define SELECT_MEDIA_FROM_GROUP_NULL "SELECT "MEDIA_INFO_ITEM" FROM '%s' WHERE validity IN (1, 2) AND %s IS NULL" -#define SELECT_MEDIA_FROM_FOLDER "SELECT "MEDIA_INFO_ITEM" FROM '%s' WHERE validity IN (1, 2) AND folder_id='%s'" -#define SELECT_MEDIA_FROM_STORAGE "SELECT "MEDIA_INFO_ITEM" FROM '%s' WHERE validity IN (1, 2) AND storage_uuid='%s'" -#define SELECT_MEDIA_FROM_TAG "SELECT "MEDIA_INFO_ITEM" FROM '%s' WHERE media_id IN (SELECT media_id FROM "DB_TABLE_TAG_MAP" WHERE tag_id=%d) AND validity IN (1, 2)" -#define SELECT_MEDIA_FROM_PLAYLIST "SELECT "MEDIA_INFO_ITEM" FROM '%s' WHERE media_id IN (SELECT media_id FROM "DB_TABLE_PLAYLIST_MAP" WHERE playlist_id=%d) AND validity IN (1, 2)" -#define SELECT_MEDIA_PATH_BY_ID "SELECT media_path FROM "DB_VIEW_MEDIA" WHERE media_id='%q'" -#define SELECT_MEDIA_STORAGE_ID_BY_ID "SELECT storage_uuid FROM "DB_VIEW_MEDIA" WHERE media_id='%q'" +#define UPDATE_IMAGE_META_FROM_MEDIA "UPDATE "DB_TABLE_MEDIA" SET media_orientation=%d WHERE media_id='%q'" + +#define SELECT_MEDIA_ITEM "SELECT "MEDIA_INFO_ITEM" FROM "DB_TABLE_MEDIA" WHERE validity IN (1, 2) " +#define SELECT_MEDIA_ITEM_BY_STORAGE_ID SELECT_MEDIA_ITEM"AND storage_uuid='%s' " +#define SELECT_MEDIA_FROM_MEDIA "SELECT "MEDIA_INFO_ITEM" FROM "DB_TABLE_MEDIA" WHERE validity IN (1, 2) AND media_id='%s'" +#define SELECT_MEDIA_BY_PATH "SELECT "MEDIA_INFO_ITEM" FROM "DB_TABLE_MEDIA" WHERE validity=1 AND media_path='%q'" +#define SELECT_MEDIA_FROM_ALBUM "SELECT "MEDIA_INFO_ITEM" FROM "DB_TABLE_MEDIA" WHERE validity IN (1, 2) AND album_id=%d" +#define SELECT_MEDIA_FROM_ALBUM_BY_STORAGE_ID SELECT_MEDIA_FROM_ALBUM" AND storage_uuid='%s' " +#define SELECT_MEDIA_FROM_GROUP "SELECT "MEDIA_INFO_ITEM" FROM "DB_TABLE_MEDIA" WHERE validity IN (1, 2) AND %s='%q'" +#define SELECT_MEDIA_FROM_GROUP_BY_STORAGE_ID SELECT_MEDIA_FROM_GROUP" AND storage_uuid='%s' " +#define SELECT_MEDIA_FROM_GROUP_NULL "SELECT "MEDIA_INFO_ITEM" FROM "DB_TABLE_MEDIA" WHERE validity IN (1, 2) AND %s IS NULL" +#define SELECT_MEDIA_FROM_GROUP_NULL_BY_STORAGE_ID SELECT_MEDIA_FROM_GROUP_NULL" AND storage_uuid='%s' " +#define SELECT_MEDIA_FROM_FOLDER "SELECT "MEDIA_INFO_ITEM" FROM "DB_TABLE_MEDIA" WHERE validity IN (1, 2) AND folder_id='%s'" +#define SELECT_MEDIA_FROM_STORAGE "SELECT "MEDIA_INFO_ITEM" FROM "DB_TABLE_MEDIA" WHERE validity IN (1, 2) AND storage_uuid='%s'" +#define SELECT_MEDIA_FROM_TAG "SELECT "MEDIA_INFO_ITEM" FROM "DB_TABLE_MEDIA" WHERE media_id IN (SELECT media_id FROM "DB_TABLE_TAG_MAP" WHERE tag_id=%d) AND validity IN (1, 2)" +#define SELECT_MEDIA_FROM_PLAYLIST "SELECT "MEDIA_INFO_ITEM" FROM "DB_TABLE_MEDIA" WHERE media_id IN (SELECT media_id FROM "DB_TABLE_PLAYLIST_MAP" WHERE playlist_id=%d) AND validity IN (1, 2)" +#define SELECT_MEDIA_FROM_TAG_BY_STORAGE_ID SELECT_MEDIA_FROM_TAG" AND storage_uuid='%s' " +#define SELECT_MEDIA_FROM_PLAYLIST_BY_STORAGE_ID SELECT_MEDIA_FROM_PLAYLIST" AND storage_uuid='%s' " +#define SELECT_MEDIA_PATH_BY_ID "SELECT media_path FROM "DB_TABLE_MEDIA" WHERE media_id='%q'" +#define SELECT_MEDIA_STORAGE_ID_BY_ID "SELECT storage_uuid FROM "DB_TABLE_MEDIA" WHERE media_id='%q'" /* Delete */ #define DELETE_PLAYLIST_FROM_PLAYLIST "DELETE FROM "DB_TABLE_PLAYLIST" WHERE playlist_id=%d" @@ -496,11 +512,13 @@ typedef struct _media_content_cb_data { #define DELETE_FACE_FROM_FACE "DELETE FROM "DB_TABLE_FACE" WHERE media_face_id=%d" #define INSERT_FACE_TO_FACE "INSERT INTO "DB_TABLE_FACE" (media_id, face_rect_x , face_rect_y, face_rect_w, face_rect_h, face_orientation, media_face_tag) VALUES ('%q', %d, %d, %d, %d, %d, %Q);" #define UPDATE_FACE_TO_FACE "UPDATE "DB_TABLE_FACE" SET face_rect_x=%d, face_rect_y=%d, face_rect_w=%d, face_rect_h=%d, face_orientation=%d, media_face_tag=%Q WHERE media_face_id=%d" -#define SELECT_MEDIA_COUNT_FROM_MEDIA_BY_ID "SELECT COUNT(*) FROM "DB_VIEW_MEDIA" WHERE media_id='%q' AND validity IN (1, 2)" -#define SELECT_IMAGE_COUNT_FROM_MEDIA_BY_ID "SELECT COUNT(*) FROM "DB_VIEW_MEDIA" WHERE media_id='%q' AND media_type=0 AND validity IN (1, 2)" +#define SELECT_MEDIA_COUNT_FROM_MEDIA_BY_ID "SELECT COUNT(*) FROM "DB_TABLE_MEDIA" WHERE media_id='%q' AND validity IN (1, 2)" +#define SELECT_IMAGE_COUNT_FROM_MEDIA_BY_ID "SELECT COUNT(*) FROM "DB_TABLE_MEDIA" WHERE media_id='%q' AND media_type=0 AND validity IN (1, 2)" #define SELECT_FACE_COUNT "SELECT COUNT(*) FROM "FACE_MEDIA_JOIN +#define SELECT_FACE_COUNT_BY_STORAGE_ID SELECT_FACE_COUNT"AND storage_uuid='%s' " #define SELECT_FACE_COUNT_BY_MEDIA_ID "SELECT COUNT(*) FROM "FACE_MEDIA_JOIN" AND media_id='%s'" #define SELECT_FACE_LIST "SELECT media_face_id, media_id, face_rect_x, face_rect_y, face_rect_w, face_rect_h, face_orientation, media_face_tag FROM "FACE_MEDIA_JOIN +#define SELECT_FACE_LIST_BY_STORAGE_ID SELECT_FACE_LIST"AND storage_uuid='%s' " #define SELECT_FACE_LIST_BY_MEDIA_ID "SELECT media_face_id, media_id, face_rect_x, face_rect_y, face_rect_w, face_rect_h, face_orientation, media_face_tag FROM "FACE_MEDIA_JOIN" AND media_id='%s'" #define UPDATE_MEDIA_INFO_IN_FACE_SCAN_LIST "UPDATE "DB_TABLE_FACE_SCAN_LIST" SET modified_time = 0 WHERE media_id IN (SELECT media_id FROM "DB_TABLE_FACE" WHERE media_face_id=%d)" #define SELECT_FACE_ID "SELECT media_face_id FROM "DB_TABLE_FACE" WHERE media_id='%q' AND face_rect_x=%d AND face_rect_y=%d AND face_rect_w=%d AND face_rect_h=%d AND face_orientation=%d" @@ -511,7 +529,7 @@ int _content_error_capi(int content_error); int _content_query_sql(char *query_str); sqlite3 * _content_get_db_handle(void); uid_t _content_get_uid(void); -int _media_info_get_media_info_from_db(const char *path, const char *storage_id, media_info_h media); +int _media_info_get_media_info_from_db(const char *path, media_info_h media); void _media_info_item_get_detail(sqlite3_stmt *stmt, media_info_h media); int _media_db_get_group_count(filter_h filter, group_list_e group_type, int *group_count); int _media_db_get_media_group_count(media_group_e group, filter_h filter, int *group_count); diff --git a/packaging/capi-content-media-content.spec b/packaging/capi-content-media-content.spec index b2ecf1e..43e79ed 100644 --- a/packaging/capi-content-media-content.spec +++ b/packaging/capi-content-media-content.spec @@ -1,6 +1,6 @@ Name: capi-content-media-content Summary: A Media content library in Tizen Native API -Version: 0.4.2 +Version: 0.4.3 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/media_db.c b/src/media_db.c index 8bfc59e..b69774d 100755 --- a/src/media_db.c +++ b/src/media_db.c @@ -219,6 +219,7 @@ static int __media_db_make_query(filter_h filter, char *select_query, int select return ret; } +#ifdef _USE_TVPD_MODE int _media_db_get_group_count(filter_h filter, group_list_e group_type, int *group_count) { int ret = MEDIA_CONTENT_ERROR_NONE; @@ -285,10 +286,8 @@ int _media_db_get_group_count(filter_h filter, group_list_e group_type, int *gro else snprintf(select_query, sizeof(select_query), SELECT_FACE_COUNT, DB_VIEW_MEDIA); break; -#ifdef _USE_TVPD_MODE case MEDIA_GROUP_PVR: case MEDIA_GROUP_UHD: -#endif default: { media_content_error("Invalid group type [%d]", group_type); @@ -323,7 +322,6 @@ int _media_db_get_media_group_count(media_group_e group, filter_h filter, int *g filter_s *_filter = (filter_s*)filter; memset(select_query, 0x00, sizeof(select_query)); -#ifdef _USE_TVPD_MODE if (group < MEDIA_PVR_GROUP_DURATION) { /*media content*/ if ((_filter != NULL) && STRING_VALID(_filter->storage_id)) snprintf(select_query, sizeof(select_query), SELECT_MEDIA_GROUP_COUNT, __media_db_get_group_name(group), _filter->storage_id); @@ -340,12 +338,6 @@ int _media_db_get_media_group_count(media_group_e group, filter_h filter, int *g else snprintf(select_query, sizeof(select_query), SELECT_UHD_GROUP_COUNT, __media_db_get_group_name(group)); } -#else - if ((_filter != NULL) && STRING_VALID(_filter->storage_id)) - snprintf(select_query, sizeof(select_query), SELECT_MEDIA_GROUP_COUNT, __media_db_get_group_name(group), _filter->storage_id); - else - snprintf(select_query, sizeof(select_query), SELECT_MEDIA_GROUP_COUNT, __media_db_get_group_name(group), DB_VIEW_MEDIA); -#endif ret = __media_db_make_query(filter, select_query, sizeof(select_query), &condition_query, &option_query); media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); @@ -382,7 +374,6 @@ int _media_db_get_media_group(media_group_e group, filter_h filter, media_group_ sqlite3_stmt *stmt = NULL; filter_s *_filter = (filter_s*)filter; memset(select_query, 0x00, sizeof(select_query)); -#ifdef _USE_TVPD_MODE if (group < MEDIA_PVR_GROUP_DURATION) { /*media content */ if ((_filter != NULL) && STRING_VALID(_filter->storage_id)) snprintf(select_query, sizeof(select_query), SELECT_MEDIA_GROUP_LIST, __media_db_get_group_name(group), _filter->storage_id); @@ -399,12 +390,6 @@ int _media_db_get_media_group(media_group_e group, filter_h filter, media_group_ else snprintf(select_query, sizeof(select_query), SELECT_UHD_GROUP_LIST, __media_db_get_group_name(group)); } -#else - if ((_filter != NULL) && STRING_VALID(_filter->storage_id)) - snprintf(select_query, sizeof(select_query), SELECT_MEDIA_GROUP_LIST, __media_db_get_group_name(group), _filter->storage_id); - else - snprintf(select_query, sizeof(select_query), SELECT_MEDIA_GROUP_LIST, __media_db_get_group_name(group), DB_VIEW_MEDIA); -#endif ret = __media_db_make_query(filter, select_query, sizeof(select_query), &condition_query, &option_query); media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); @@ -428,7 +413,7 @@ int _media_db_get_media_group(media_group_e group, filter_h filter, media_group_ return ret; } -#ifdef _USE_TVPD_MODE + int _media_db_get_media_group_and_count(media_group_e group, filter_h filter, media_group_and_count_cb callback, void *user_data) { int ret = MEDIA_CONTENT_ERROR_NONE; @@ -495,7 +480,179 @@ int _media_db_get_media_group_and_count(media_group_e group, filter_h filter, me return ret; } +#else +int _media_db_get_group_count(filter_h filter, group_list_e group_type, int *group_count) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + sqlite3_stmt *stmt = NULL; + char select_query[MAX_QUERY_SIZE] = {0, }; + char *condition_query = NULL; + char *option_query = NULL; + filter_s *_filter = (filter_s*)filter; + + memset(select_query, 0x00, sizeof(select_query)); + + switch (group_type) { + case MEDIA_GROUP_NONE: + case MEDIA_GROUP_TAG_BY_MEDIA_ID: + case MEDIA_GROUP_BOOKMARK_BY_MEDIA_ID: + case MEDIA_GROUP_FACE_BY_MEDIA_ID: + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + break; + case MEDIA_GROUP_ALBUM: + if ((_filter != NULL) && STRING_VALID(_filter->storage_id)) + snprintf(select_query, sizeof(select_query), SELECT_ALBUM_COUNT_BY_STORAGE_ID, _filter->storage_id); + else + snprintf(select_query, sizeof(select_query), SELECT_ALBUM_COUNT); + + break; + case MEDIA_GROUP_FOLDER: + if ((_filter != NULL) && STRING_VALID(_filter->storage_id)) + snprintf(select_query, sizeof(select_query), SELECT_FOLDER_COUNT_BY_STORAGE_ID, _filter->storage_id); + else + snprintf(select_query, sizeof(select_query), SELECT_FOLDER_COUNT); + + break; + case MEDIA_GROUP_PLAYLIST: + if (!SAFE_STRLCPY(select_query, SELECT_PLAYLIST_COUNT, sizeof(select_query))) { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + break; + case MEDIA_GROUP_TAG: + if (!SAFE_STRLCPY(select_query, SELECT_TAG_COUNT, sizeof(select_query))) { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + break; + case MEDIA_GROUP_BOOKMARK: + if ((_filter != NULL) && STRING_VALID(_filter->storage_id)) + snprintf(select_query, sizeof(select_query), SELECT_BOOKMARK_COUNT_BY_STORAGE_ID, _filter->storage_id); + else + snprintf(select_query, sizeof(select_query), SELECT_BOOKMARK_COUNT); + + break; + case MEDIA_GROUP_STORAGE: + if (!SAFE_STRLCPY(select_query, SELECT_STORAGE_COUNT, sizeof(select_query))) { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + break; + case MEDIA_GROUP_FACE: + if ((_filter != NULL) && STRING_VALID(_filter->storage_id)) + snprintf(select_query, sizeof(select_query), SELECT_FACE_COUNT_BY_STORAGE_ID, _filter->storage_id); + else + snprintf(select_query, sizeof(select_query), SELECT_FACE_COUNT); + break; + default: + { + media_content_error("Invalid group type [%d]", group_type); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + break; + } + + ret = __media_db_make_query(filter, select_query, sizeof(select_query), &condition_query, &option_query); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _content_query_prepare(select_query, condition_query, option_query, &stmt); + SAFE_FREE(condition_query); + SAFE_FREE(option_query); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + if (sqlite3_step(stmt) == SQLITE_ROW) + *group_count = (int)sqlite3_column_int(stmt, 0); + + SQLITE3_FINALIZE(stmt); + + return ret; +} + +int _media_db_get_media_group_count(media_group_e group, filter_h filter, int *group_count) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + sqlite3_stmt *stmt = NULL; + char select_query[MAX_QUERY_SIZE] = {0, }; + char *condition_query = NULL; + char *option_query = NULL; + filter_s *_filter = (filter_s*)filter; + + memset(select_query, 0x00, sizeof(select_query)); + if ((_filter != NULL) && STRING_VALID(_filter->storage_id)) + snprintf(select_query, sizeof(select_query), SELECT_MEDIA_GROUP_COUNT_BY_STORAGE_ID, __media_db_get_group_name(group), _filter->storage_id); + else + snprintf(select_query, sizeof(select_query), SELECT_MEDIA_GROUP_COUNT, __media_db_get_group_name(group)); + + ret = __media_db_make_query(filter, select_query, sizeof(select_query), &condition_query, &option_query); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + SAFE_STRLCAT(select_query, QUERY_KEYWORD_SPACE, sizeof(select_query)); + if (STRING_VALID(condition_query)) + SAFE_STRLCAT(select_query, condition_query, sizeof(select_query)); + if (STRING_VALID(option_query)) + SAFE_STRLCAT(select_query, option_query, sizeof(select_query)); + SAFE_STRLCAT(select_query, QUERY_KEYWORD_BRACKET, sizeof(select_query)); + + SAFE_FREE(condition_query); + SAFE_FREE(option_query); + + ret = _content_query_prepare(select_query, condition_query, option_query, &stmt); + SAFE_FREE(condition_query); + SAFE_FREE(option_query); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + if (sqlite3_step(stmt) == SQLITE_ROW) + *group_count = (int)sqlite3_column_int(stmt, 0); + + SQLITE3_FINALIZE(stmt); + + return ret; +} + +int _media_db_get_media_group(media_group_e group, filter_h filter, media_group_cb callback, void *user_data) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + char select_query[MAX_QUERY_SIZE] = {0, }; + char *condition_query = NULL; + char *option_query = NULL; + char *name = NULL; + sqlite3_stmt *stmt = NULL; + filter_s *_filter = (filter_s*)filter; + memset(select_query, 0x00, sizeof(select_query)); + + if ((_filter != NULL) && STRING_VALID(_filter->storage_id)) + snprintf(select_query, sizeof(select_query), SELECT_MEDIA_GROUP_LIST_BY_STORAGE_ID, __media_db_get_group_name(group), _filter->storage_id); + else + snprintf(select_query, sizeof(select_query), SELECT_MEDIA_GROUP_LIST, __media_db_get_group_name(group)); + + ret = __media_db_make_query(filter, select_query, sizeof(select_query), &condition_query, &option_query); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _content_query_prepare(select_query, condition_query, option_query, &stmt); + SAFE_FREE(condition_query); + SAFE_FREE(option_query); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + while (sqlite3_step(stmt) == SQLITE_ROW) { + name = g_strdup((const char *)sqlite3_column_text(stmt, 0)); + + if (callback(name, user_data) == false) { + SAFE_FREE(name); + break; + } + + SAFE_FREE(name); + } + + SQLITE3_FINALIZE(stmt); + + return ret; +} #endif + int _media_db_get_album(filter_h filter, media_album_cb callback, void *user_data) { int ret = MEDIA_CONTENT_ERROR_NONE; @@ -506,12 +663,17 @@ int _media_db_get_album(filter_h filter, media_album_cb callback, void *user_dat filter_s *_filter = (filter_s*)filter; memset(select_query, 0x00, sizeof(select_query)); - +#ifdef _USE_TVPD_MODE if ((_filter != NULL) && STRING_VALID(_filter->storage_id)) snprintf(select_query, sizeof(select_query), SELECT_ALBUM_LIST, _filter->storage_id); else snprintf(select_query, sizeof(select_query), SELECT_ALBUM_LIST, DB_VIEW_MEDIA); - +#else + if ((_filter != NULL) && STRING_VALID(_filter->storage_id)) + snprintf(select_query, sizeof(select_query), SELECT_ALBUM_LIST_BY_STORAGE_ID, _filter->storage_id); + else + snprintf(select_query, sizeof(select_query), SELECT_ALBUM_LIST); +#endif ret = __media_db_make_query(filter, select_query, sizeof(select_query), &condition_query, &option_query); media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); @@ -557,12 +719,17 @@ int _media_db_get_folder(filter_h filter, media_folder_cb callback, void *user_d filter_s *_filter = (filter_s*)filter; memset(select_query, 0x00, sizeof(select_query)); - +#ifdef _USE_TVPD_MODE if ((_filter != NULL) && STRING_VALID(_filter->storage_id)) snprintf(select_query, sizeof(select_query), SELECT_FOLDER_LIST_BY_STORAGE_ID, _filter->storage_id, _filter->storage_id); else snprintf(select_query, sizeof(select_query), SELECT_FOLDER_LIST, DB_VIEW_MEDIA); - +#else + if ((_filter != NULL) && STRING_VALID(_filter->storage_id)) + snprintf(select_query, sizeof(select_query), SELECT_FOLDER_LIST_BY_STORAGE_ID, _filter->storage_id); + else + snprintf(select_query, sizeof(select_query), SELECT_FOLDER_LIST); +#endif ret = __media_db_make_query(filter, select_query, sizeof(select_query), &condition_query, &option_query); media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); @@ -756,7 +923,7 @@ int _media_db_get_bookmark(const char *media_id, filter_h filter, media_bookmark filter_s *_filter = (filter_s*)filter; memset(select_query, 0x00, sizeof(select_query)); - +#ifdef _USE_TVPD_MODE if (STRING_VALID(media_id)) { //get bookmark by media_id if ((_filter != NULL) && STRING_VALID(_filter->storage_id)) snprintf(select_query, sizeof(select_query), SELECT_BOOKMARK_LIST_BY_MEDIA_ID, _filter->storage_id, media_id); @@ -768,6 +935,16 @@ int _media_db_get_bookmark(const char *media_id, filter_h filter, media_bookmark else snprintf(select_query, sizeof(select_query), SELECT_BOOKMARK_LIST, DB_VIEW_MEDIA); } +#else + if (STRING_VALID(media_id)) { //get bookmark by media_id + snprintf(select_query, sizeof(select_query), SELECT_BOOKMARK_LIST_BY_MEDIA_ID, media_id); + } else { + if ((_filter != NULL) && STRING_VALID(_filter->storage_id)) + snprintf(select_query, sizeof(select_query), SELECT_BOOKMARK_LIST_BY_STORAGE_ID, _filter->storage_id); + else + snprintf(select_query, sizeof(select_query), SELECT_BOOKMARK_LIST); + } +#endif ret = __media_db_make_query(filter, select_query, sizeof(select_query), &condition_query, &option_query); media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); @@ -816,7 +993,7 @@ int _media_db_get_face(const char *media_id, filter_h filter, media_face_cb call filter_s *_filter = (filter_s*)filter; memset(select_query, 0x00, sizeof(select_query)); - +#ifdef _USE_TVPD_MODE if (STRING_VALID(media_id)) { //get face by media_id if ((_filter != NULL) && STRING_VALID(_filter->storage_id)) snprintf(select_query, sizeof(select_query), SELECT_FACE_LIST_BY_MEDIA_ID, _filter->storage_id, media_id); @@ -828,7 +1005,16 @@ int _media_db_get_face(const char *media_id, filter_h filter, media_face_cb call else snprintf(select_query, sizeof(select_query), SELECT_FACE_LIST, DB_VIEW_MEDIA); } - +#else + if (STRING_VALID(media_id)) { //get face by media_id + snprintf(select_query, sizeof(select_query), SELECT_FACE_LIST_BY_MEDIA_ID, media_id); + } else { + if ((_filter != NULL) && STRING_VALID(_filter->storage_id)) + snprintf(select_query, sizeof(select_query), SELECT_FACE_LIST_BY_STORAGE_ID, _filter->storage_id); + else + snprintf(select_query, sizeof(select_query), SELECT_FACE_LIST); + } +#endif ret = __media_db_make_query(filter, select_query, sizeof(select_query), &condition_query, &option_query); media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); @@ -881,10 +1067,17 @@ int _media_db_get_group_item_count_by_id(int group_id, filter_h filter, group_li memset(select_query, 0x00, sizeof(select_query)); if (group_type == MEDIA_GROUP_ALBUM) { +#ifdef _USE_TVPD_MODE if ((_filter != NULL) && STRING_VALID(_filter->storage_id)) snprintf(select_query, sizeof(select_query), SELECT_MEDIA_COUNT_FROM_ALBUM, _filter->storage_id, group_id); else snprintf(select_query, sizeof(select_query), SELECT_MEDIA_COUNT_FROM_ALBUM, DB_VIEW_MEDIA, group_id); +#else + if ((_filter != NULL) && STRING_VALID(_filter->storage_id)) + snprintf(select_query, sizeof(select_query), SELECT_MEDIA_COUNT_FROM_ALBUM_BY_STORAGE_ID, group_id, _filter->storage_id); + else + snprintf(select_query, sizeof(select_query), SELECT_MEDIA_COUNT_FROM_ALBUM, group_id); +#endif } else if (group_type == MEDIA_GROUP_PLAYLIST) { snprintf(select_query, sizeof(select_query), SELECT_MEDIA_COUNT_FROM_PLAYLIST, group_id); } else if (group_type == MEDIA_GROUP_TAG) { @@ -928,40 +1121,66 @@ int _media_db_get_group_item_count(const char *group_name, filter_h filter, grou If user wants to set offset and count, use SQL SELECT_MEDIA_COUNT_FROM_MEDIA. If user wants to get count without setting count, SELECT_MEDIA_COUNT_FROM_MEDIA_SIMPLE */ if (_filter && ((_filter->offset < 0) && (_filter->count < 0))) { +#ifdef _USE_TVPD_MODE if (STRING_VALID(_filter->storage_id)) snprintf(select_query, sizeof(select_query), SELECT_MEDIA_COUNT_FROM_MEDIA_SIMPLE, _filter->storage_id); else snprintf(select_query, sizeof(select_query), SELECT_MEDIA_COUNT_FROM_MEDIA_SIMPLE, DB_VIEW_MEDIA); +#else + if (STRING_VALID(_filter->storage_id)) + snprintf(select_query, sizeof(select_query), SELECT_MEDIA_COUNT_FROM_MEDIA_SIMPLE_BY_STORAGE_ID, _filter->storage_id); + else + snprintf(select_query, sizeof(select_query), SELECT_MEDIA_COUNT_FROM_MEDIA_SIMPLE); +#endif is_simple = TRUE; } else { +#ifdef _USE_TVPD_MODE snprintf(select_query, sizeof(select_query), SELECT_MEDIA_COUNT_FROM_MEDIA, DB_VIEW_MEDIA); +#else + snprintf(select_query, sizeof(select_query), SELECT_MEDIA_COUNT_FROM_MEDIA); +#endif } } else if (group_type == MEDIA_GROUP_FOLDER) { +#ifdef _USE_TVPD_MODE if ((_filter != NULL) && STRING_VALID(_filter->storage_id)) tmp_query = sqlite3_mprintf(SELECT_MEDIA_COUNT_FROM_FOLDER, _filter->storage_id, group_name); else tmp_query = sqlite3_mprintf(SELECT_MEDIA_COUNT_FROM_FOLDER, DB_VIEW_MEDIA, group_name); - +#else + if ((_filter != NULL) && STRING_VALID(_filter->storage_id)) + tmp_query = sqlite3_mprintf(SELECT_MEDIA_COUNT_FROM_FOLDER_BY_STORAGE_ID, group_name, _filter->storage_id); + else + tmp_query = sqlite3_mprintf(SELECT_MEDIA_COUNT_FROM_FOLDER, group_name); +#endif SAFE_STRLCAT(select_query, tmp_query, sizeof(select_query)); } else if (group_type == MEDIA_GROUP_TAG_BY_MEDIA_ID) { snprintf(select_query, sizeof(select_query), SELECT_TAG_COUNT_BY_MEDIA_ID, group_name); } else if (group_type == MEDIA_GROUP_BOOKMARK_BY_MEDIA_ID) { +#ifdef _USE_TVPD_MODE if ((_filter != NULL) && STRING_VALID(_filter->storage_id)) tmp_query = sqlite3_mprintf(SELECT_BOOKMARK_COUNT_BY_MEDIA_ID, _filter->storage_id, group_name); else tmp_query = sqlite3_mprintf(SELECT_BOOKMARK_COUNT_BY_MEDIA_ID, DB_VIEW_MEDIA, group_name); - +#else + tmp_query = sqlite3_mprintf(SELECT_BOOKMARK_COUNT_BY_MEDIA_ID, group_name); +#endif SAFE_STRLCAT(select_query, tmp_query, sizeof(select_query)); } else if (group_type == MEDIA_GROUP_STORAGE) { +#ifdef _USE_TVPD_MODE tmp_query = sqlite3_mprintf(SELECT_MEDIA_COUNT_FROM_STORAGE, group_name, group_name); - +#else + tmp_query = sqlite3_mprintf(SELECT_MEDIA_COUNT_FROM_STORAGE, group_name); +#endif SAFE_STRLCAT(select_query, tmp_query, sizeof(select_query)); } else if (group_type == MEDIA_GROUP_FACE_BY_MEDIA_ID) { +#ifdef _USE_TVPD_MODE if ((_filter != NULL) && STRING_VALID(_filter->storage_id)) tmp_query = sqlite3_mprintf(SELECT_FACE_COUNT_BY_MEDIA_ID, _filter->storage_id, group_name); else tmp_query = sqlite3_mprintf(SELECT_FACE_COUNT_BY_MEDIA_ID, DB_VIEW_MEDIA, group_name); - +#else + tmp_query = sqlite3_mprintf(SELECT_FACE_COUNT_BY_MEDIA_ID, group_name); +#endif SAFE_STRLCAT(select_query, tmp_query, sizeof(select_query)); #ifdef _USE_TVPD_MODE } else if (group_type == MEDIA_GROUP_PVR) { @@ -1027,6 +1246,7 @@ int _media_db_get_group_item_by_id(int group_id, filter_h filter, media_info_cb memset(select_query, 0x00, sizeof(select_query)); +#ifdef _USE_TVPD_MODE if (group_type == MEDIA_GROUP_ALBUM) { if ((_filter != NULL) && STRING_VALID(_filter->storage_id)) snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_ALBUM, _filter->storage_id, group_id); @@ -1046,7 +1266,27 @@ int _media_db_get_group_item_by_id(int group_id, filter_h filter, media_info_cb media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; } - +#else + if (group_type == MEDIA_GROUP_ALBUM) { + if ((_filter != NULL) && STRING_VALID(_filter->storage_id)) + snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_ALBUM_BY_STORAGE_ID, group_id, _filter->storage_id); + else + snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_ALBUM, group_id); + } else if (group_type == MEDIA_GROUP_PLAYLIST) { + if ((_filter != NULL) && STRING_VALID(_filter->storage_id)) + snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_PLAYLIST_BY_STORAGE_ID, group_id, _filter->storage_id); + else + snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_PLAYLIST, group_id); + } else if (group_type == MEDIA_GROUP_TAG) { + if ((_filter != NULL) && STRING_VALID(_filter->storage_id)) + snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_TAG_BY_STORAGE_ID, group_id, _filter->storage_id); + else + snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_TAG, group_id); + } else { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } +#endif ret = __media_db_make_query(filter, select_query, sizeof(select_query), &condition_query, &option_query); media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); @@ -1088,7 +1328,7 @@ int _media_db_get_group_item(const char *group_name, filter_h filter, media_info filter_s *_filter = (filter_s*)filter; memset(select_query, 0x00, sizeof(select_query)); - +#ifdef _USE_TVPD_MODE if (group_type == MEDIA_GROUP_NONE) { if ((_filter != NULL) && STRING_VALID(_filter->storage_id)) snprintf(select_query, sizeof(select_query), SELECT_MEDIA_ITEM, _filter->storage_id); @@ -1105,7 +1345,21 @@ int _media_db_get_group_item(const char *group_name, filter_h filter, media_info media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; } - +#else + if (group_type == MEDIA_GROUP_NONE) { + if ((_filter != NULL) && STRING_VALID(_filter->storage_id)) + snprintf(select_query, sizeof(select_query), SELECT_MEDIA_ITEM_BY_STORAGE_ID, _filter->storage_id); + else + snprintf(select_query, sizeof(select_query), SELECT_MEDIA_ITEM); + } else if (group_type == MEDIA_GROUP_FOLDER) { + snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_FOLDER, group_name); + } else if (group_type == MEDIA_GROUP_STORAGE) { + snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_STORAGE, group_name); + } else { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } +#endif ret = __media_db_make_query(filter, select_query, sizeof(select_query), &condition_query, &option_query); media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); @@ -1272,17 +1526,17 @@ int _media_db_get_media_group_item_count(const char *group_name, filter_h filter #else if (group_name != NULL) { if ((_filter != NULL) && STRING_VALID(_filter->storage_id)) { - tmp_query = sqlite3_mprintf(SELECT_MEDIA_COUNT_FROM_GROUP, _filter->storage_id, __media_db_get_group_name(group), group_name); + tmp_query = sqlite3_mprintf(SELECT_MEDIA_COUNT_FROM_GROUP_BY_STORAGE_ID, __media_db_get_group_name(group), group_name, _filter->storage_id); SAFE_STRLCAT(select_query, tmp_query, sizeof(select_query)); } else { - tmp_query = sqlite3_mprintf(SELECT_MEDIA_COUNT_FROM_GROUP, DB_VIEW_MEDIA, __media_db_get_group_name(group), group_name); + tmp_query = sqlite3_mprintf(SELECT_MEDIA_COUNT_FROM_GROUP, __media_db_get_group_name(group), group_name); SAFE_STRLCAT(select_query, tmp_query, sizeof(select_query)); } } else { if ((_filter != NULL) && STRING_VALID(_filter->storage_id)) - snprintf(select_query, sizeof(select_query), SELECT_MEDIA_COUNT_FROM_GROUP_NULL, _filter->storage_id, __media_db_get_group_name(group)); + snprintf(select_query, sizeof(select_query), SELECT_MEDIA_COUNT_FROM_GROUP_NULL_BY_STORAGE_ID, __media_db_get_group_name(group), _filter->storage_id); else - snprintf(select_query, sizeof(select_query), SELECT_MEDIA_COUNT_FROM_GROUP_NULL, DB_VIEW_MEDIA, __media_db_get_group_name(group)); + snprintf(select_query, sizeof(select_query), SELECT_MEDIA_COUNT_FROM_GROUP_NULL, __media_db_get_group_name(group)); } #endif ret = __media_db_make_query(filter, select_query, sizeof(select_query), &condition_query, &option_query); @@ -1328,7 +1582,7 @@ int _media_db_get_media_group_item(const char *group_name, filter_h filter, medi filter_s *_filter = (filter_s*)filter; memset(select_query, 0x00, sizeof(select_query)); - +#ifdef _USE_TVPD_MODE if (group_name != NULL) { if ((_filter != NULL) && STRING_VALID(_filter->storage_id)) tmp_query = sqlite3_mprintf(SELECT_MEDIA_FROM_GROUP, _filter->storage_id, __media_db_get_group_name(group), group_name); @@ -1342,7 +1596,21 @@ int _media_db_get_media_group_item(const char *group_name, filter_h filter, medi else snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_GROUP_NULL, DB_VIEW_MEDIA, __media_db_get_group_name(group)); } +#else + if (group_name != NULL) { + if ((_filter != NULL) && STRING_VALID(_filter->storage_id)) + tmp_query = sqlite3_mprintf(SELECT_MEDIA_FROM_GROUP_BY_STORAGE_ID, __media_db_get_group_name(group), group_name, _filter->storage_id); + else + tmp_query = sqlite3_mprintf(SELECT_MEDIA_FROM_GROUP, __media_db_get_group_name(group), group_name); + SAFE_STRLCAT(select_query, tmp_query, sizeof(select_query)); + } else { + if ((_filter != NULL) && STRING_VALID(_filter->storage_id)) + snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_GROUP_NULL_BY_STORAGE_ID, __media_db_get_group_name(group), _filter->storage_id); + else + snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_GROUP_NULL, __media_db_get_group_name(group)); + } +#endif ret = __media_db_make_query(filter, select_query, sizeof(select_query), &condition_query, &option_query); if (ret != MEDIA_CONTENT_ERROR_NONE) { if (tmp_query != NULL) diff --git a/src/media_image.c b/src/media_image.c index 341c6a4..16ad32a 100755 --- a/src/media_image.c +++ b/src/media_image.c @@ -276,16 +276,19 @@ int image_meta_update_to_db(image_meta_h image) media_content_warn("DEPRECATION WARNING: image_meta_update_to_db() is deprecated and will be removed from next release."); image_meta_s *_image = (image_meta_s*)image; char *sql = NULL; - char *storage_id = NULL; if (_image != NULL && STRING_VALID(_image->media_id)) { +#ifdef _USE_TVPD_MODE + char *storage_id = NULL; ret = _media_db_get_storage_id_by_media_id(_image->media_id, &storage_id); media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); - sql = sqlite3_mprintf(UPDATE_IMAGE_META_FROM_MEDIA, storage_id, _image->orientation, _image->media_id); + SAFE_FREE(storage_id); +#else + sql = sqlite3_mprintf(UPDATE_IMAGE_META_FROM_MEDIA, _image->orientation, _image->media_id); +#endif ret = _content_query_sql(sql); SQLITE3_SAFE_FREE(sql); - SAFE_FREE(storage_id); } else { media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; diff --git a/src/media_info.c b/src/media_info.c index 910fc30..994e253 100644 --- a/src/media_info.c +++ b/src/media_info.c @@ -358,7 +358,7 @@ void _media_info_item_get_detail(sqlite3_stmt* stmt, media_info_h media) } } } - +#ifdef _USE_TVPD_MODE int _media_info_get_media_info_from_db(const char *path, const char *storage_id, media_info_h media) { int ret = MEDIA_CONTENT_ERROR_NONE; @@ -385,6 +385,34 @@ int _media_info_get_media_info_from_db(const char *path, const char *storage_id, return ret; } +#else +int _media_info_get_media_info_from_db(const char *path, media_info_h media) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + sqlite3_stmt *stmt = NULL; + char *select_query = NULL; + media_info_s *_media = (media_info_s*)media; + + media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid media"); + + select_query = sqlite3_mprintf(SELECT_MEDIA_BY_PATH, path); + + ret = _content_get_result(select_query, &stmt); + SQLITE3_SAFE_FREE(select_query); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + if (sqlite3_step(stmt) == SQLITE_ROW) { + _media_info_item_get_detail(stmt, (media_info_h)_media); + } else { + media_content_sec_error("No media : path[%s]", path); + ret = MEDIA_CONTENT_ERROR_DB_FAILED; + } + + SQLITE3_FINALIZE(stmt); + + return ret; +} +#endif int media_info_insert_to_db(const char *path, media_info_h *info) { @@ -449,14 +477,18 @@ int media_info_insert_to_db(const char *path, media_info_h *info) media_info_s *_media = (media_info_s*)calloc(1, sizeof(media_info_s)); media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY"); - +#ifdef _USE_TVPD_MODE if (STRING_VALID(storage_id)) ret = _media_info_get_media_info_from_db(repl_path, storage_id, (media_info_h)_media); else ret = _media_info_get_media_info_from_db(repl_path, DB_TABLE_MEDIA, (media_info_h)_media); *info = (media_info_h)_media; +#else + ret = _media_info_get_media_info_from_db(repl_path, (media_info_h)_media); + *info = (media_info_h)_media; +#endif return ret; } @@ -1772,7 +1804,6 @@ int media_info_get_media_from_db(const char *media_id, media_info_h *media) { int ret = MEDIA_CONTENT_ERROR_NONE; char select_query[DEFAULT_QUERY_SIZE] = {0, }; - char *storage_id = NULL; sqlite3_stmt *stmt = NULL; if (!STRING_VALID(media_id) || (media == NULL)) { @@ -1782,12 +1813,17 @@ int media_info_get_media_from_db(const char *media_id, media_info_h *media) memset(select_query, 0x00, sizeof(select_query)); +#ifdef _USE_TVPD_MODE + char *storage_id = NULL; + ret = _media_db_get_storage_id_by_media_id(media_id, &storage_id); media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); - snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_MEDIA, storage_id, media_id); - ret = _content_get_result(select_query, &stmt); SAFE_FREE(storage_id); +#else + snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_MEDIA, media_id); +#endif + ret = _content_get_result(select_query, &stmt); media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); media_info_s *_media = NULL; @@ -2164,4 +2200,4 @@ int media_info_set_display_name(media_info_h media, const char *display_name) return MEDIA_CONTENT_ERROR_NONE; } -#endif \ No newline at end of file +#endif -- 2.34.1