char *tmp_query = NULL;
char *condition_query = NULL;
char *option_query = NULL;
- bool is_simple = FALSE;
+ char *tmp_option = NULL;
+ bool need_bracket = false;
filter_s *_filter = (filter_s *)filter;
memset(select_query, 0x00, sizeof(select_query));
/* There are 2 ways to get count for media table for performance
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))) {
+ if (_filter) {
+ if (_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);
#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
+ need_bracket = true;
+ }
} else {
#ifdef _USE_TVPD_MODE
- snprintf(select_query, sizeof(select_query), SELECT_MEDIA_COUNT_FROM_MEDIA, DB_VIEW_MEDIA);
+ snprintf(select_query, sizeof(select_query), SELECT_MEDIA_COUNT_FROM_MEDIA_SIMPLE, DB_VIEW_MEDIA);
#else
- snprintf(select_query, sizeof(select_query), SELECT_MEDIA_COUNT_FROM_MEDIA);
+ snprintf(select_query, sizeof(select_query), SELECT_MEDIA_COUNT_FROM_MEDIA_SIMPLE);
#endif
}
} else if (group_type == MEDIA_GROUP_FOLDER) {
return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
}
- ret = __media_db_make_query(filter, &condition_query, &option_query);
- if (ret != MEDIA_CONTENT_ERROR_NONE) {
- if (tmp_query != NULL)
- SQLITE3_SAFE_FREE(tmp_query);
- return ret;
- }
-
- if (group_type == MEDIA_GROUP_NONE) {
- SAFE_STRLCAT(select_query, QUERY_KEYWORD_SPACE, sizeof(select_query));
- if (STRING_VALID(condition_query)) {
- SAFE_STRLCAT(select_query, QUERY_KEYWORD_AND, sizeof(select_query));
- SAFE_STRLCAT(select_query, condition_query, sizeof(select_query));
- }
- if (STRING_VALID(option_query))
- SAFE_STRLCAT(select_query, option_query, sizeof(select_query));
+ SQLITE3_SAFE_FREE(tmp_query);
- if (!is_simple)
- SAFE_STRLCAT(select_query, QUERY_KEYWORD_BRACKET, sizeof(select_query));
+ ret = __media_db_make_query(filter, &condition_query, &option_query);
+ media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
- SAFE_FREE(condition_query);
- SAFE_FREE(option_query);
+ if (need_bracket) {
+ tmp_option = g_strconcat(option_query, ")", NULL);
+ g_free(option_query);
+ option_query = tmp_option;
}
ret = _content_query_prepare(select_query, condition_query, option_query, &stmt);
- if (tmp_query != NULL)
- SQLITE3_SAFE_FREE(tmp_query);
SAFE_FREE(condition_query);
SAFE_FREE(option_query);
media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
sqlite3_stmt *stmt = NULL;
char select_query[MAX_QUERY_SIZE] = {0, };
char *tmp_query = NULL;
+ char *tmp_option = NULL;
char *condition_query = NULL;
char *option_query = NULL;
filter_s *_filter = (filter_s *)filter;
snprintf(select_query, sizeof(select_query), SELECT_MEDIA_COUNT_FROM_GROUP_NULL, __media_db_get_group_name(group));
}
#endif
+ SQLITE3_SAFE_FREE(tmp_query);
+
ret = __media_db_make_query(filter, &condition_query, &option_query);
- if (ret != MEDIA_CONTENT_ERROR_NONE) {
- if (tmp_query != NULL)
- SQLITE3_SAFE_FREE(tmp_query);
- return ret;
- }
+ 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, QUERY_KEYWORD_AND, sizeof(select_query));
- SAFE_STRLCAT(select_query, condition_query, sizeof(select_query));
+ if (option_query) {
+ tmp_option = g_strconcat(option_query, ")", NULL);
+ g_free(option_query);
+ option_query = tmp_option;
+ } else {
+ SAFE_STRLCAT(select_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);
- if (tmp_query != NULL)
- SQLITE3_SAFE_FREE(tmp_query);
SAFE_FREE(condition_query);
SAFE_FREE(option_query);
media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
int _media_db_get_storage(filter_h filter, media_storage_cb callback, void *user_data)
{
int ret = MEDIA_CONTENT_ERROR_NONE;
- char select_query[DEFAULT_QUERY_SIZE] = {0, };
char *condition_query = NULL;
char *option_query = NULL;
sqlite3_stmt *stmt = NULL;
- memset(select_query, 0x00, sizeof(select_query));
-
- if (!SAFE_STRLCPY(select_query, SELECT_STORAGE_LIST, sizeof(select_query))) {
- media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
- return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
- }
-
ret = __media_db_make_query(filter, &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);
+ ret = _content_query_prepare(SELECT_STORAGE_LIST, condition_query, option_query, &stmt);
SAFE_FREE(condition_query);
SAFE_FREE(option_query);
media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);