2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <media_content.h>
19 #include <media_info_private.h>
20 #include <media_util_private.h>
22 static char * __media_db_get_group_name(media_group_e group);
23 static int __media_db_make_query(filter_h filter, attribute_h attr, char *select_query, int select_query_size, char **condition_query, char **option_query);
25 static char * __media_db_get_group_name(media_group_e group)
28 case MEDIA_CONTENT_GROUP_DISPLAY_NAME:
29 return (char *)DB_FIELD_MEDIA_DISPLAY_NAME;
30 case MEDIA_CONTENT_GROUP_TYPE:
31 return (char *)DB_FIELD_MEDIA_TYPE;
32 case MEDIA_CONTENT_GROUP_MIME_TYPE:
33 return (char *) DB_FIELD_MEDIA_MIME_TYPE;
34 case MEDIA_CONTENT_GROUP_SIZE:
35 return (char *) DB_FIELD_MEDIA_SIZE;
36 case MEDIA_CONTENT_GROUP_ADDED_TIME:
37 return (char *) DB_FIELD_MEDIA_ADDED_TIME;
38 case MEDIA_CONTENT_GROUP_MODIFIED_TIME:
39 return (char *) DB_FIELD_MEDIA_MODIFIED_TIME;
40 case MEDIA_CONTENT_GROUP_TITLE:
41 return (char *) DB_FIELD_MEDIA_TITLE;
42 case MEDIA_CONTENT_GROUP_ARTIST:
43 return (char *) DB_FIELD_MEDIA_ARTIST;
44 case MEDIA_CONTENT_GROUP_ALBUM_ARTIST:
45 return (char *) DB_FIELD_MEDIA_ALBUM_ARTIST;
46 case MEDIA_CONTENT_GROUP_GENRE:
47 return (char *) DB_FIELD_MEDIA_GENRE;
48 case MEDIA_CONTENT_GROUP_COMPOSER:
49 return (char *) DB_FIELD_MEDIA_COMPOSER;
50 case MEDIA_CONTENT_GROUP_YEAR:
51 return (char *) DB_FIELD_MEDIA_YEAR;
52 case MEDIA_CONTENT_GROUP_RECORDED_DATE:
53 return (char *) DB_FIELD_MEDIA_RECORDED_DATE;
54 case MEDIA_CONTENT_GROUP_COPYRIGHT:
55 return (char *) DB_FIELD_MEDIA_COPYRIGHT;
56 case MEDIA_CONTENT_GROUP_TRACK_NUM:
57 return (char *) DB_FIELD_MEDIA_TRACK_NUM;
58 case MEDIA_CONTENT_GROUP_DESCRIPTION:
59 return (char *) DB_FIELD_MEDIA_DESCRIPTION;
60 case MEDIA_CONTENT_GROUP_LONGITUDE:
61 return (char *) DB_FIELD_MEDIA_LONGITUDE;
62 case MEDIA_CONTENT_GROUP_LATITUDE:
63 return (char *) DB_FIELD_MEDIA_LATITUDE;
64 case MEDIA_CONTENT_GROUP_ALTITUDE:
65 return (char *) DB_FIELD_MEDIA_ALTITUDE;
66 case MEDIA_CONTENT_GROUP_RATING:
67 return (char *) DB_FIELD_MEDIA_RATING;
69 case MEDIA_CONTENT_GROUP_MODIFIED_MONTH:
70 return (char *) DB_FIELD_MEDIA_MODIFIED_DATE;
71 case MEDIA_CONTENT_GROUP_MODIFIED_DATE:
72 return (char *) DB_FIELD_MEDIA_MODIFIED_DATE;
74 #ifdef _USE_SENIOR_MODE
75 case MEDIA_CONTENT_GROUP_CONTACT:
76 return (char *) DB_FIELD_MEDIA_CONTACT;
79 case MEDIA_CONTENT_GROUP_ALBUM:
80 return (char *) DB_FIELD_MEDIA_ALBUM;
81 case MEDIA_PVR_GROUP_DURATION:
82 return (char *) DB_FIELD_PVR_DURATION;
83 case MEDIA_PVR_GROUP_TIME_ZONE:
84 return (char *) DB_FIELD_PVR_TIME_ZONE;
85 case MEDIA_PVR_GROUP_PTC:
86 return (char *) DB_FIELD_PVR_PTC;
87 case MEDIA_PVR_GROUP_MAJOR:
88 return (char *) DB_FIELD_PVR_MAJOR;
89 case MEDIA_PVR_GROUP_MINOR:
90 return (char *) DB_FIELD_PVR_MINOR;
91 case MEDIA_PVR_GROUP_CHANNEL_TYPE:
92 return (char *) DB_FIELD_PVR_CHANNEL_TYPE;
93 case MEDIA_PVR_GROUP_CHANNEL_NAME:
94 return (char *) DB_FIELD_PVR_CHANNEL_NAME;
95 case MEDIA_PVR_GROUP_CHANNEL_NUM:
96 return (char *) DB_FIELD_PVR_CHANNEL_NUM;
97 case MEDIA_PVR_GROUP_PROGRAM_TITLE:
98 return (char *) DB_FIELD_PVR_PROGRAM_TITLE;
99 case MEDIA_PVR_GROUP_PROGRAM_NUM:
100 return (char *) DB_FIELD_PVR_PROGRAM_NUM;
101 case MEDIA_PVR_GROUP_PROGRAM_CRID:
102 return (char *) DB_FIELD_PVR_PROGRAM_CRID;
103 case MEDIA_PVR_GROUP_GUIDANCE:
104 return (char *) DB_FIELD_PVR_GUIDANCE;
105 case MEDIA_PVR_GROUP_SYNOPSIS:
106 return (char *) DB_FIELD_PVR_SYNOPSIS;
107 case MEDIA_PVR_GROUP_GENRE:
108 return (char *) DB_FIELD_PVR_GENRE;
109 case MEDIA_PVR_GROUP_LANGUAGE:
110 return (char *) DB_FIELD_PVR_LANGUAGE;
111 case MEDIA_PVR_GROUP_EMBARGO_TIME:
112 return (char *) DB_FIELD_PVR_EMBARGO_TIME;
113 case MEDIA_PVR_GROUP_EXPIRY_TIME:
114 return (char *) DB_FIELD_PVR_EXPIRY_TIME;
115 case MEDIA_PVR_GROUP_START_TIME:
116 return (char *) DB_FIELD_PVR_START_TIME;
117 case MEDIA_PVR_GROUP_PROGRAM_START_TIME:
118 return (char *) DB_FIELD_PVR_PROGRAM_START_TIME;
119 case MEDIA_PVR_GROUP_PROGRAM_END_TIME:
120 return (char *) DB_FIELD_PVR_PROGRAM_END_TIME;
121 case MEDIA_PVR_GROUP_PROGRAM_DATE:
122 return (char *) DB_FIELD_PVR_PROGRAM_DATE;
123 case MEDIA_PVR_GROUP_PARENTAL_RATING:
124 return (char *) DB_FIELD_PVR_PARENTAL_RATING;
125 case MEDIA_PVR_GROUP_TIMER_RECORD:
126 return (char *) DB_FIELD_PVR_TIMER_RECORD;
127 case MEDIA_PVR_GROUP_SERIES_RECORD:
128 return (char *) DB_FIELD_PVR_SERIES_RECORD;
129 case MEDIA_PVR_GROUP_HD:
130 return (char *) DB_FIELD_PVR_HD;
131 case MEDIA_PVR_GROUP_SUBTITLE:
132 return (char *) DB_FIELD_PVR_SUBTITLE;
133 case MEDIA_PVR_GROUP_TTX:
134 return (char *) DB_FIELD_PVR_TTX;
135 case MEDIA_PVR_GROUP_AD:
136 return (char *) DB_FIELD_PVR_AD;
137 case MEDIA_PVR_GROUP_HARDOF_HEARINGRADIO:
138 return (char *) DB_FIELD_PVR_HARDOF_HEARINGRADIO;
139 case MEDIA_PVR_GROUP_DATA_SERVICE:
140 return (char *) DB_FIELD_PVR_DATA_SERVICE;
141 case MEDIA_PVR_GROUP_CONTENT_LOCK:
142 return (char *) DB_FIELD_PVR_CONTENT_LOCK;
143 case MEDIA_PVR_GROUP_CONTENT_WATCH:
144 return (char *) DB_FIELD_PVR_CONTENT_WATCH;
145 case MEDIA_PVR_GROUP_HAS_AUDIO_ONLY:
146 return (char *) DB_FIELD_PVR_HAS_AUDIO_ONLY;
147 case MEDIA_PVR_GROUP_IS_LOCAL_RECORDED:
148 return (char *) DB_FIELD_PVR_IS_LOCAL_RECORD;
149 case MEDIA_PVR_GROUP_RESOLUTION:
150 return (char *) DB_FIELD_PVR_RESOLUTION;
151 case MEDIA_PVR_GROUP_ASPECTRATIO:
152 return (char *) DB_FIELD_PVR_ASPECTRATIO;
153 case MEDIA_PVR_GROUP_MODIFIED_MONTH:
154 return (char *) DB_FIELD_PVR_MODIFIED_DATE;
155 case MEDIA_PVR_GROUP_MODIFIED_DATE:
156 return (char *) DB_FIELD_PVR_MODIFIED_DATE;
157 case MEDIA_PVR_GROUP_SPORTS_TYPE:
158 return (char *) DB_FIELD_PVR_SPORTS_TYPE;
159 case MEDIA_PVR_GROUP_GUIDANCE_LENGTH:
160 return (char *) DB_FIELD_PVR_GUIDANCE_LENGTH;
161 case MEDIA_PVR_GROUP_TVMODE:
162 return (char *) DB_FIELD_PVR_TVMODE;
163 case MEDIA_PVR_GROUP_PLAY_COUNT:
164 return (char *) DB_FIELD_PVR_PLAY_COUNT;
165 case MEDIA_PVR_GROUP_PRIVATE_DATA:
166 return (char *) DB_FIELD_PVR_PRIVATE_DATA;
167 case MEDIA_UHD_GROUP_CONTENT_TITLE:
168 return (char *) DB_FIELD_UHD_CONTENT_TITLE;
169 case MEDIA_UHD_GROUP_RELEASE_DATE:
170 return (char *) DB_FIELD_UHD_RELEASE_DATE;
171 case MEDIA_UHD_GROUP_SUB_TYPE:
172 return (char *) DB_FIELD_UHD_SUB_TYPE;
173 case MEDIA_UHD_GROUP_FILE_NAME:
174 return (char *) DB_FIELD_UHD_FILE_NAME;
175 case MEDIA_UHD_GROUP_PLAYED_COUNT:
176 return (char *) DB_FIELD_UHD_PLAYED_COUNT;
185 static int __media_db_make_query(filter_h filter, attribute_h attr, char *select_query, int select_query_size, char **condition_query, char **option_query)
187 int ret = MEDIA_CONTENT_ERROR_NONE;
188 filter_s *_filter = NULL;
190 if (filter != NULL) {
191 _filter = (filter_s*)filter;
193 if (STRING_VALID(_filter->condition)) {
194 ret = _media_filter_attribute_generate(attr, filter, condition_query);
195 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
198 if (_filter->is_full_order == false) {
199 /* Process for filter v1 */
200 ret = _media_filter_attribute_option_generate(attr, filter, option_query);
201 if (ret != MEDIA_CONTENT_ERROR_NONE) {
202 SAFE_FREE(*condition_query);
206 /* Process for filter v2 */
207 ret = _media_filter_attribute_option_generate_with_full_query(attr, filter, option_query);
208 if (ret != MEDIA_CONTENT_ERROR_NONE) {
209 SAFE_FREE(*condition_query);
214 if (STRING_VALID(*condition_query)) {
215 SAFE_STRLCAT(select_query, QUERY_KEYWORD_SPACE, select_query_size);
216 SAFE_STRLCAT(select_query, QUERY_KEYWORD_AND, select_query_size);
223 int _media_db_get_group_count(filter_h filter, group_list_e group_type, int *group_count)
225 int ret = MEDIA_CONTENT_ERROR_NONE;
226 sqlite3_stmt *stmt = NULL;
227 char select_query[MAX_QUERY_SIZE] = {0, };
228 char *condition_query = NULL;
229 char *option_query = NULL;
230 attribute_h attr = NULL;
231 filter_s *_filter = (filter_s*)filter;
233 attr = _content_get_attirbute_handle();
234 memset(select_query, 0x00, sizeof(select_query));
236 switch (group_type) {
237 case MEDIA_GROUP_NONE:
238 case MEDIA_GROUP_TAG_BY_MEDIA_ID:
239 case MEDIA_GROUP_BOOKMARK_BY_MEDIA_ID:
240 case MEDIA_GROUP_FACE_BY_MEDIA_ID:
242 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
243 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
246 case MEDIA_GROUP_ALBUM:
247 attr = _content_get_alias_attirbute_handle();
249 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
250 snprintf(select_query, sizeof(select_query), SELECT_ALBUM_COUNT, _filter->storage_id);
252 snprintf(select_query, sizeof(select_query), SELECT_ALBUM_COUNT, DB_VIEW_MEDIA);
255 case MEDIA_GROUP_FOLDER:
256 attr = _content_get_alias_attirbute_handle();
258 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
259 snprintf(select_query, sizeof(select_query), SELECT_FOLDER_COUNT_BY_STORAGE_ID, _filter->storage_id, _filter->storage_id);
261 snprintf(select_query, sizeof(select_query), SELECT_FOLDER_COUNT, DB_VIEW_MEDIA);
264 case MEDIA_GROUP_PLAYLIST:
265 if (!SAFE_STRLCPY(select_query, SELECT_PLAYLIST_COUNT, sizeof(select_query))) {
266 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
267 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
270 case MEDIA_GROUP_TAG:
271 if (!SAFE_STRLCPY(select_query, SELECT_TAG_COUNT, sizeof(select_query))) {
272 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
273 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
276 case MEDIA_GROUP_BOOKMARK:
277 attr = _content_get_alias_attirbute_handle();
279 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
280 snprintf(select_query, sizeof(select_query), SELECT_BOOKMARK_COUNT, _filter->storage_id);
282 snprintf(select_query, sizeof(select_query), SELECT_BOOKMARK_COUNT, DB_VIEW_MEDIA);
285 case MEDIA_GROUP_STORAGE:
286 if (!SAFE_STRLCPY(select_query, SELECT_STORAGE_COUNT, sizeof(select_query))) {
287 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
288 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
291 case MEDIA_GROUP_FACE:
292 attr = _content_get_alias_attirbute_handle();
294 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
295 snprintf(select_query, sizeof(select_query), SELECT_FACE_COUNT, _filter->storage_id);
297 snprintf(select_query, sizeof(select_query), SELECT_FACE_COUNT, DB_VIEW_MEDIA);
299 #ifdef _USE_TVPD_MODE
300 case MEDIA_GROUP_PVR:
301 case MEDIA_GROUP_UHD:
305 media_content_error("Invalid group type [%d]", group_type);
306 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
311 ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query);
312 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
314 ret = _content_query_prepare(&stmt, select_query, condition_query, option_query);
315 SAFE_FREE(condition_query);
316 SAFE_FREE(option_query);
317 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
319 if (sqlite3_step(stmt) == SQLITE_ROW)
320 *group_count = (int)sqlite3_column_int(stmt, 0);
322 SQLITE3_FINALIZE(stmt);
327 int _media_db_get_media_group_count(media_group_e group, filter_h filter, int *group_count)
329 int ret = MEDIA_CONTENT_ERROR_NONE;
330 sqlite3_stmt *stmt = NULL;
331 char select_query[MAX_QUERY_SIZE] = {0, };
332 char *condition_query = NULL;
333 char *option_query = NULL;
334 attribute_h attr = NULL;
335 filter_s *_filter = (filter_s*)filter;
337 attr = _content_get_attirbute_handle();
338 memset(select_query, 0x00, sizeof(select_query));
339 #ifdef _USE_TVPD_MODE
340 if (group < MEDIA_PVR_GROUP_DURATION) { /*media content*/
341 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
342 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_GROUP_COUNT, __media_db_get_group_name(group), _filter->storage_id);
344 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_GROUP_COUNT, __media_db_get_group_name(group), DB_VIEW_MEDIA);
345 } else if (group < MEDIA_UHD_GROUP_CONTENT_TITLE) { /*pvr content*/
346 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
347 snprintf(select_query, sizeof(select_query), SELECT_PVR_GROUP_COUNT_BY_STORAGE_ID, __media_db_get_group_name(group), _filter->storage_id);
349 snprintf(select_query, sizeof(select_query), SELECT_PVR_GROUP_COUNT, __media_db_get_group_name(group));
350 } else { /*uhd content*/
351 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
352 snprintf(select_query, sizeof(select_query), SELECT_UHD_GROUP_COUNT_BY_STORAGE_ID, __media_db_get_group_name(group), _filter->storage_id);
354 snprintf(select_query, sizeof(select_query), SELECT_UHD_GROUP_COUNT, __media_db_get_group_name(group));
357 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
358 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_GROUP_COUNT, __media_db_get_group_name(group), _filter->storage_id);
360 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_GROUP_COUNT, __media_db_get_group_name(group), DB_VIEW_MEDIA);
362 ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query);
363 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
365 SAFE_STRLCAT(select_query, QUERY_KEYWORD_SPACE, sizeof(select_query));
366 if (STRING_VALID(condition_query))
367 SAFE_STRLCAT(select_query, condition_query, sizeof(select_query));
368 if (STRING_VALID(option_query))
369 SAFE_STRLCAT(select_query, option_query, sizeof(select_query));
370 SAFE_STRLCAT(select_query, QUERY_KEYWORD_BRACKET, sizeof(select_query));
372 SAFE_FREE(condition_query);
373 SAFE_FREE(option_query);
375 ret = _content_query_prepare(&stmt, select_query, condition_query, option_query);
376 SAFE_FREE(condition_query);
377 SAFE_FREE(option_query);
378 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
380 if (sqlite3_step(stmt) == SQLITE_ROW)
381 *group_count = (int)sqlite3_column_int(stmt, 0);
383 SQLITE3_FINALIZE(stmt);
388 int _media_db_get_media_group(media_group_e group, filter_h filter, media_group_cb callback, void *user_data)
390 int ret = MEDIA_CONTENT_ERROR_NONE;
391 char select_query[MAX_QUERY_SIZE] = {0, };
392 char *condition_query = NULL;
393 char *option_query = NULL;
395 sqlite3_stmt *stmt = NULL;
396 attribute_h attr = NULL;
397 filter_s *_filter = (filter_s*)filter;
399 attr = _content_get_attirbute_handle();
400 memset(select_query, 0x00, sizeof(select_query));
401 #ifdef _USE_TVPD_MODE
402 if (group < MEDIA_PVR_GROUP_DURATION) { /*media content */
403 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
404 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_GROUP_LIST, __media_db_get_group_name(group), _filter->storage_id);
406 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_GROUP_LIST, __media_db_get_group_name(group), DB_VIEW_MEDIA);
407 } else if (group < MEDIA_UHD_GROUP_CONTENT_TITLE) { /*pvr content */
408 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
409 snprintf(select_query, sizeof(select_query), SELECT_PVR_GROUP_LIST_BY_STORAGE_ID, __media_db_get_group_name(group), _filter->storage_id);
411 snprintf(select_query, sizeof(select_query), SELECT_PVR_GROUP_LIST, __media_db_get_group_name(group));
412 } else { /* uhd content */
413 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
414 snprintf(select_query, sizeof(select_query), SELECT_UHD_GROUP_LIST_BY_STORAGE_ID, __media_db_get_group_name(group), _filter->storage_id);
416 snprintf(select_query, sizeof(select_query), SELECT_UHD_GROUP_LIST, __media_db_get_group_name(group));
419 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
420 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_GROUP_LIST, __media_db_get_group_name(group), _filter->storage_id);
422 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_GROUP_LIST, __media_db_get_group_name(group), DB_VIEW_MEDIA);
424 ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query);
425 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
427 ret = _content_query_prepare(&stmt, select_query, condition_query, option_query);
428 SAFE_FREE(condition_query);
429 SAFE_FREE(option_query);
430 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
432 while (sqlite3_step(stmt) == SQLITE_ROW) {
433 name = g_strdup((const char *)sqlite3_column_text(stmt, 0));
435 if (callback(name, user_data) == false) {
443 SQLITE3_FINALIZE(stmt);
447 #ifdef _USE_TVPD_MODE
448 int _media_db_get_media_group_and_count(media_group_e group, filter_h filter, media_group_and_count_cb callback, void *user_data)
450 int ret = MEDIA_CONTENT_ERROR_NONE;
451 char select_query[DEFAULT_QUERY_SIZE] = {0, };
452 char group_query[DEFAULT_QUERY_SIZE] = {0, };
453 char *condition_query = NULL;
454 char *option_query = NULL;
456 sqlite3_stmt *stmt = NULL;
457 attribute_h attr = NULL;
458 filter_s *_filter = (filter_s*)filter;
460 attr = _content_get_attirbute_handle();
461 memset(select_query, 0x00, sizeof(select_query));
462 memset(group_query, 0x00, sizeof(group_query));
464 char* group_name = __media_db_get_group_name(group);
465 if (!STRING_VALID(group_name)) {
466 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
467 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
470 if (group < MEDIA_PVR_GROUP_DURATION) { /*media content*/
471 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
472 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_GROUP_AND_COUNT, group_name, _filter->storage_id);
474 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_GROUP_AND_COUNT, group_name, DB_VIEW_MEDIA);
475 } else if (group < MEDIA_UHD_GROUP_CONTENT_TITLE) {/*pvr content*/
476 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
477 snprintf(select_query, sizeof(select_query), SELECT_PVR_GROUP_AND_COUNT_BY_STORAGE_ID, group_name, _filter->storage_id);
479 snprintf(select_query, sizeof(select_query), SELECT_PVR_GROUP_AND_COUNT, group_name);
480 } else {/*uhd content*/
481 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
482 snprintf(select_query, sizeof(select_query), SELECT_UHD_GROUP_AND_COUNT_BY_STORAGE_ID, group_name, _filter->storage_id);
484 snprintf(select_query, sizeof(select_query), SELECT_UHD_GROUP_AND_COUNT, group_name);
487 ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query);
488 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
490 if (STRING_VALID(option_query))
491 snprintf(group_query, sizeof(group_query), "GROUP BY %s %s", group_name, option_query);
493 snprintf(group_query, sizeof(group_query), "GROUP BY %s", group_name);
495 ret = _content_query_prepare(&stmt, select_query, condition_query, group_query);
496 SAFE_FREE(condition_query);
497 SAFE_FREE(option_query);
498 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
500 while (sqlite3_step(stmt) == SQLITE_ROW) {
501 if (STRING_VALID((const char *)sqlite3_column_text(stmt, 0)))
502 name = strdup((const char *)sqlite3_column_text(stmt, 0));
504 if (callback(name, sqlite3_column_int(stmt, 1), user_data) == false) {
512 SQLITE3_FINALIZE(stmt);
517 int _media_db_get_album(filter_h filter, media_album_cb callback, void *user_data)
519 int ret = MEDIA_CONTENT_ERROR_NONE;
520 char select_query[MAX_QUERY_SIZE] = {0, };
521 char *condition_query = NULL;
522 char *option_query = NULL;
523 sqlite3_stmt *stmt = NULL;
524 attribute_h attr = NULL;
525 filter_s *_filter = (filter_s*)filter;
527 attr = _content_get_alias_attirbute_handle();
528 memset(select_query, 0x00, sizeof(select_query));
530 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
531 snprintf(select_query, sizeof(select_query), SELECT_ALBUM_LIST, _filter->storage_id);
533 snprintf(select_query, sizeof(select_query), SELECT_ALBUM_LIST, DB_VIEW_MEDIA);
535 ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query);
536 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
538 ret = _content_query_prepare(&stmt, select_query, condition_query, option_query);
539 SAFE_FREE(condition_query);
540 SAFE_FREE(option_query);
541 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
543 while (sqlite3_step(stmt) == SQLITE_ROW) {
544 media_album_s *album = (media_album_s*)calloc(1, sizeof(media_album_s));
547 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
548 SQLITE3_FINALIZE(stmt);
549 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
552 album->album_id = (int)sqlite3_column_int(stmt, 0);
553 album->name = g_strdup((const char *)sqlite3_column_text(stmt, 1));
554 album->artist = g_strdup((const char *)sqlite3_column_text(stmt, 2));
555 album->album_art_path = g_strdup((const char *)sqlite3_column_text(stmt, 3));
557 if (callback((media_album_h)album, user_data) == false) {
558 media_album_destroy((media_album_h)album);
562 media_album_destroy((media_album_h)album);
565 SQLITE3_FINALIZE(stmt);
570 int _media_db_get_folder(filter_h filter, media_folder_cb callback, void *user_data)
572 int ret = MEDIA_CONTENT_ERROR_NONE;
573 char select_query[MAX_QUERY_SIZE] = {0, };
574 char *condition_query = NULL;
575 char *option_query = NULL;
576 sqlite3_stmt *stmt = NULL;
577 attribute_h attr = NULL;
578 filter_s *_filter = (filter_s*)filter;
580 attr = _content_get_alias_attirbute_handle();
581 memset(select_query, 0x00, sizeof(select_query));
583 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
584 snprintf(select_query, sizeof(select_query), SELECT_FOLDER_LIST_BY_STORAGE_ID, _filter->storage_id, _filter->storage_id);
586 snprintf(select_query, sizeof(select_query), SELECT_FOLDER_LIST, DB_VIEW_MEDIA);
588 ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query);
589 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
591 ret = _content_query_prepare(&stmt, select_query, condition_query, option_query);
593 SAFE_FREE(condition_query);
594 SAFE_FREE(option_query);
595 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
597 while (sqlite3_step(stmt) == SQLITE_ROW) {
598 media_folder_s *_folder = (media_folder_s*)calloc(1, sizeof(media_folder_s));
600 if (_folder == NULL) {
601 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
602 SQLITE3_FINALIZE(stmt);
603 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
606 _folder->folder_id = g_strdup((const char *)sqlite3_column_text(stmt, 0));
607 _folder->path = g_strdup((const char *)sqlite3_column_text(stmt, 1));
608 _folder->name = g_strdup((const char *)sqlite3_column_text(stmt, 2));
609 _folder->storage_type = (int)sqlite3_column_int(stmt, 3);
610 _folder->storage_uuid = g_strdup((const char *)sqlite3_column_text(stmt, 4));
612 if (callback((media_folder_h)_folder, user_data) == false) {
613 media_folder_destroy((media_folder_h) _folder);
617 media_folder_destroy((media_folder_h) _folder);
620 SQLITE3_FINALIZE(stmt);
625 int _media_db_get_playlist(filter_h filter, media_playlist_cb callback, void *user_data)
627 int ret = MEDIA_CONTENT_ERROR_NONE;
628 char select_query[MAX_QUERY_SIZE] = {0, };
629 char *condition_query = NULL;
630 char *option_query = NULL;
631 sqlite3_stmt *stmt = NULL;
632 attribute_h attr = NULL;
634 attr = _content_get_attirbute_handle();
635 memset(select_query, 0x00, sizeof(select_query));
637 if (!SAFE_STRLCPY(select_query, SELECT_PLAYLIST_LIST, sizeof(select_query))) {
638 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
639 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
642 ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query);
643 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
645 ret = _content_query_prepare(&stmt, select_query, condition_query, option_query);
646 SAFE_FREE(condition_query);
647 SAFE_FREE(option_query);
648 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
650 while (sqlite3_step(stmt) == SQLITE_ROW) {
651 media_playlist_s *_playlist = (media_playlist_s*)calloc(1, sizeof(media_playlist_s));
653 if (_playlist == NULL) {
654 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
655 SQLITE3_FINALIZE(stmt);
656 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
659 _playlist->playlist_id = (int)sqlite3_column_int(stmt, 0);
660 _playlist->name = g_strdup((const char *)sqlite3_column_text(stmt, 1));
661 _playlist->thumbnail_path = g_strdup((const char *)sqlite3_column_text(stmt, 2));
663 if (callback((media_playlist_h)_playlist, user_data) == false) {
664 media_playlist_destroy((media_playlist_h)_playlist);
667 media_playlist_destroy((media_playlist_h)_playlist);
670 SQLITE3_FINALIZE(stmt);
675 int _media_db_get_playlist_item(int playlist_id, filter_h filter, playlist_member_cb callback, void *user_data)
677 int ret = MEDIA_CONTENT_ERROR_NONE;
678 char select_query[MAX_QUERY_SIZE] = {0, };
679 char *condition_query = NULL;
680 char *option_query = NULL;
681 sqlite3_stmt *stmt = NULL;
682 attribute_h attr = NULL;
684 attr = _content_get_attirbute_handle();
685 memset(select_query, 0x00, sizeof(select_query));
687 /*snprintf(select_query, sizeof(select_query), SELECT_PLAYLIST_ITEM_ID_FROM_PLAYLIST_VIEW, playlist_id);*/
688 snprintf(select_query, sizeof(select_query), SELECT_PLAYLIST_ITEM_ALL_FROM_PLAYLIST_VIEW, playlist_id);
690 ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query);
691 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
693 ret = _content_query_prepare(&stmt, select_query, condition_query, option_query);
694 SAFE_FREE(condition_query);
695 SAFE_FREE(option_query);
696 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
698 while (sqlite3_step(stmt) == SQLITE_ROW) {
699 int playlist_member_id = 0;
700 playlist_member_id = (int)sqlite3_column_int(stmt, MEDIA_INFO_ITEM_MAX); /*MEDIA_INFO_ITEM_MAX is pm_id*/
702 media_info_s *_media = (media_info_s*)calloc(1, sizeof(media_info_s));
704 if (_media == NULL) {
705 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
706 SQLITE3_FINALIZE(stmt);
707 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
710 _media_info_item_get_detail(stmt, (media_info_h)_media);
712 if (callback(playlist_member_id, (media_info_h)_media, user_data) == false) {
713 media_info_destroy((media_info_h)_media);
716 media_info_destroy((media_info_h)_media);
720 SQLITE3_FINALIZE(stmt);
725 int _media_db_get_tag(const char *media_id, filter_h filter, media_tag_cb callback, void *user_data)
727 int ret = MEDIA_CONTENT_ERROR_NONE;
728 char select_query[MAX_QUERY_SIZE] = {0, };
729 char *condition_query = NULL;
730 char *option_query = NULL;
731 sqlite3_stmt *stmt = NULL;
732 attribute_h attr = NULL;
734 attr = _content_get_attirbute_handle();
735 memset(select_query, 0x00, sizeof(select_query));
737 if (!STRING_VALID(media_id)) {
738 if (!SAFE_STRLCPY(select_query, SELECT_TAG_LIST, sizeof(select_query))) {
739 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
740 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
743 snprintf(select_query, sizeof(select_query), SELECT_TAG_LIST_BY_MEDIA_ID, media_id);
745 ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query);
746 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
748 SAFE_STRLCAT(select_query, QUERY_KEYWORD_SPACE, sizeof(select_query));
750 ret = _content_query_prepare(&stmt, select_query, condition_query, option_query);
751 SAFE_FREE(condition_query);
752 SAFE_FREE(option_query);
753 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
755 while (sqlite3_step(stmt) == SQLITE_ROW) {
756 media_tag_s *_tag = (media_tag_s*)calloc(1, sizeof(media_tag_s));
759 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
760 SQLITE3_FINALIZE(stmt);
761 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
764 _tag->tag_id = (int)sqlite3_column_int(stmt, 0);
765 _tag->name = g_strdup((const char *)sqlite3_column_text(stmt, 1));
767 if (callback((media_tag_h)_tag, user_data) == false) {
768 media_tag_destroy((media_tag_h)_tag);
771 media_tag_destroy((media_tag_h)_tag);
774 SQLITE3_FINALIZE(stmt);
779 int _media_db_get_bookmark(const char *media_id, filter_h filter, media_bookmark_cb callback, void *user_data)
781 int ret = MEDIA_CONTENT_ERROR_NONE;
782 char select_query[MAX_QUERY_SIZE] = {0, };
783 char *condition_query = NULL;
784 char *option_query = NULL;
785 sqlite3_stmt *stmt = NULL;
786 attribute_h attr = NULL;
787 filter_s *_filter = (filter_s*)filter;
789 attr = _content_get_alias_attirbute_handle();
791 memset(select_query, 0x00, sizeof(select_query));
793 if (STRING_VALID(media_id)) { //get bookmark by media_id
794 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
795 snprintf(select_query, sizeof(select_query), SELECT_BOOKMARK_LIST_BY_MEDIA_ID, _filter->storage_id, media_id);
797 snprintf(select_query, sizeof(select_query), SELECT_BOOKMARK_LIST_BY_MEDIA_ID, DB_VIEW_MEDIA, media_id);
799 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
800 snprintf(select_query, sizeof(select_query), SELECT_BOOKMARK_LIST, _filter->storage_id);
802 snprintf(select_query, sizeof(select_query), SELECT_BOOKMARK_LIST, DB_VIEW_MEDIA);
805 ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query);
806 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
808 ret = _content_query_prepare(&stmt, select_query, condition_query, option_query);
809 SAFE_FREE(condition_query);
810 SAFE_FREE(option_query);
811 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
813 while (sqlite3_step(stmt) == SQLITE_ROW) {
814 media_bookmark_s *bookmark = (media_bookmark_s*)calloc(1, sizeof(media_bookmark_s));
816 if (bookmark == NULL) {
817 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
818 SQLITE3_FINALIZE(stmt);
819 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
822 bookmark->bookmark_id = (int)sqlite3_column_int(stmt, 0);
823 bookmark->media_id = g_strdup((const char *)sqlite3_column_text(stmt, 1));
824 bookmark->marked_time = (int)sqlite3_column_int(stmt, 2);
825 bookmark->thumbnail_path = g_strdup((const char *)sqlite3_column_text(stmt, 3));
826 bookmark->name = g_strdup((const char *)sqlite3_column_text(stmt, 4));
828 if (callback((media_bookmark_h)bookmark, user_data) == false) {
829 media_bookmark_destroy((media_bookmark_h)bookmark);
833 media_bookmark_destroy((media_bookmark_h)bookmark);
836 SQLITE3_FINALIZE(stmt);
842 int _media_db_get_face(const char *media_id, filter_h filter, media_face_cb callback, void *user_data)
844 int ret = MEDIA_CONTENT_ERROR_NONE;
845 char select_query[MAX_QUERY_SIZE] = {0, };
846 char *condition_query = NULL;
847 char *option_query = NULL;
848 sqlite3_stmt *stmt = NULL;
849 attribute_h attr = NULL;
850 filter_s *_filter = (filter_s*)filter;
852 attr = _content_get_alias_attirbute_handle();
854 memset(select_query, 0x00, sizeof(select_query));
856 if (STRING_VALID(media_id)) { //get face by media_id
857 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
858 snprintf(select_query, sizeof(select_query), SELECT_FACE_LIST_BY_MEDIA_ID, _filter->storage_id, media_id);
860 snprintf(select_query, sizeof(select_query), SELECT_FACE_LIST_BY_MEDIA_ID, DB_VIEW_MEDIA, media_id);
862 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
863 snprintf(select_query, sizeof(select_query), SELECT_FACE_LIST, _filter->storage_id);
865 snprintf(select_query, sizeof(select_query), SELECT_FACE_LIST, DB_VIEW_MEDIA);
868 ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query);
869 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
871 ret = _content_query_prepare(&stmt, select_query, condition_query, option_query);
872 SAFE_FREE(condition_query);
873 SAFE_FREE(option_query);
874 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
876 while (sqlite3_step(stmt) == SQLITE_ROW) {
877 media_face_s *face = (media_face_s*)calloc(1, sizeof(media_face_s));
880 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
881 SQLITE3_FINALIZE(stmt);
882 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
885 face->face_id = (int)sqlite3_column_int(stmt, 0);
886 face->media_id = g_strdup((const char *)sqlite3_column_text(stmt, 1));
887 face->face_rect_x = (int)sqlite3_column_int(stmt, 2);
888 face->face_rect_y = (int)sqlite3_column_int(stmt, 3);
889 face->face_rect_w = (int)sqlite3_column_int(stmt, 4);
890 face->face_rect_h = (int)sqlite3_column_int(stmt, 5);
891 face->orientation = (int)sqlite3_column_int(stmt, 6);
892 face->face_tag = g_strdup((const char *)sqlite3_column_text(stmt, 7));
894 if (callback((media_face_h)face, user_data) == false) {
895 media_face_destroy((media_face_h)face);
899 media_face_destroy((media_face_h)face);
902 SQLITE3_FINALIZE(stmt);
908 int _media_db_get_group_item_count_by_id(int group_id, filter_h filter, group_list_e group_type, int *item_count)
910 int ret = MEDIA_CONTENT_ERROR_NONE;
911 sqlite3_stmt *stmt = NULL;
912 char select_query[MAX_QUERY_SIZE] = {0, };
913 char *condition_query = NULL;
914 char *option_query = NULL;
915 attribute_h attr = NULL;
916 filter_s *_filter = (filter_s*)filter;
918 attr = _content_get_attirbute_handle();
919 memset(select_query, 0x00, sizeof(select_query));
921 if (group_type == MEDIA_GROUP_ALBUM) {
922 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
923 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_COUNT_FROM_ALBUM, _filter->storage_id, group_id);
925 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_COUNT_FROM_ALBUM, DB_VIEW_MEDIA, group_id);
926 } else if (group_type == MEDIA_GROUP_PLAYLIST) {
927 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_COUNT_FROM_PLAYLIST, group_id);
928 } else if (group_type == MEDIA_GROUP_TAG) {
929 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_COUNT_FROM_TAG, group_id);
931 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
932 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
935 ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query);
936 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
938 ret = _content_query_prepare(&stmt, select_query, condition_query, option_query);
939 SAFE_FREE(condition_query);
940 SAFE_FREE(option_query);
941 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
943 if (sqlite3_step(stmt) == SQLITE_ROW)
944 *item_count = (int)sqlite3_column_int(stmt, 0);
946 SQLITE3_FINALIZE(stmt);
951 int _media_db_get_group_item_count(const char *group_name, filter_h filter, group_list_e group_type, int *item_count)
953 int ret = MEDIA_CONTENT_ERROR_NONE;
954 sqlite3_stmt *stmt = NULL;
955 char select_query[MAX_QUERY_SIZE] = {0, };
956 char *tmp_query = NULL;
957 char *condition_query = NULL;
958 char *option_query = NULL;
959 bool is_simple = FALSE;
960 attribute_h attr = NULL;
961 filter_s *_filter = (filter_s*)filter;
963 attr = _content_get_attirbute_handle();
964 memset(select_query, 0x00, sizeof(select_query));
966 if (group_type == MEDIA_GROUP_NONE) {
967 /* There are 2 ways to get count for media table for performance
968 If user wants to set offset and count, use SQL SELECT_MEDIA_COUNT_FROM_MEDIA.
969 If user wants to get count without setting count, SELECT_MEDIA_COUNT_FROM_MEDIA_SIMPLE */
970 if (_filter && ((_filter->offset < 0) && (_filter->count < 0))) {
971 if (STRING_VALID(_filter->storage_id))
972 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_COUNT_FROM_MEDIA_SIMPLE, _filter->storage_id);
974 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_COUNT_FROM_MEDIA_SIMPLE, DB_VIEW_MEDIA);
977 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_COUNT_FROM_MEDIA, DB_VIEW_MEDIA);
979 } else if (group_type == MEDIA_GROUP_FOLDER) {
980 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
981 tmp_query = sqlite3_mprintf(SELECT_MEDIA_COUNT_FROM_FOLDER, _filter->storage_id, group_name);
983 tmp_query = sqlite3_mprintf(SELECT_MEDIA_COUNT_FROM_FOLDER, DB_VIEW_MEDIA, group_name);
985 SAFE_STRLCAT(select_query, tmp_query, sizeof(select_query));
986 } else if (group_type == MEDIA_GROUP_TAG_BY_MEDIA_ID) {
987 snprintf(select_query, sizeof(select_query), SELECT_TAG_COUNT_BY_MEDIA_ID, group_name);
988 } else if (group_type == MEDIA_GROUP_BOOKMARK_BY_MEDIA_ID) {
989 attr = _content_get_alias_attirbute_handle();
991 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
992 tmp_query = sqlite3_mprintf(SELECT_BOOKMARK_COUNT_BY_MEDIA_ID, _filter->storage_id, group_name);
994 tmp_query = sqlite3_mprintf(SELECT_BOOKMARK_COUNT_BY_MEDIA_ID, DB_VIEW_MEDIA, group_name);
996 SAFE_STRLCAT(select_query, tmp_query, sizeof(select_query));
997 } else if (group_type == MEDIA_GROUP_STORAGE) {
998 tmp_query = sqlite3_mprintf(SELECT_MEDIA_COUNT_FROM_STORAGE, group_name, group_name);
1000 SAFE_STRLCAT(select_query, tmp_query, sizeof(select_query));
1001 } else if (group_type == MEDIA_GROUP_FACE_BY_MEDIA_ID) {
1002 attr = _content_get_alias_attirbute_handle();
1004 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
1005 tmp_query = sqlite3_mprintf(SELECT_FACE_COUNT_BY_MEDIA_ID, _filter->storage_id, group_name);
1007 tmp_query = sqlite3_mprintf(SELECT_FACE_COUNT_BY_MEDIA_ID, DB_VIEW_MEDIA, group_name);
1009 SAFE_STRLCAT(select_query, tmp_query, sizeof(select_query));
1010 #ifdef _USE_TVPD_MODE
1011 } else if (group_type == MEDIA_GROUP_PVR) {
1012 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
1013 snprintf(select_query, sizeof(select_query), SELECT_PVR_COUNT_BY_STORAGE_ID, _filter->storage_id);
1015 SAFE_STRLCAT(select_query, SELECT_PVR_COUNT, sizeof(select_query));
1016 } else if (group_type == MEDIA_GROUP_UHD) {
1017 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
1018 snprintf(select_query, sizeof(select_query), SELECT_UHD_COUNT_BY_STORAGE_ID, _filter->storage_id);
1020 SAFE_STRLCAT(select_query, SELECT_UHD_COUNT, sizeof(select_query));
1023 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1024 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1027 ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query);
1028 if (ret != MEDIA_CONTENT_ERROR_NONE) {
1029 if (tmp_query != NULL)
1030 SQLITE3_SAFE_FREE(tmp_query);
1034 if (group_type == MEDIA_GROUP_NONE) {
1035 SAFE_STRLCAT(select_query, QUERY_KEYWORD_SPACE, sizeof(select_query));
1036 if (STRING_VALID(condition_query))
1037 SAFE_STRLCAT(select_query, condition_query, sizeof(select_query));
1038 if (STRING_VALID(option_query))
1039 SAFE_STRLCAT(select_query, option_query, sizeof(select_query));
1042 SAFE_STRLCAT(select_query, QUERY_KEYWORD_BRACKET, sizeof(select_query));
1044 SAFE_FREE(condition_query);
1045 SAFE_FREE(option_query);
1048 ret = _content_query_prepare(&stmt, select_query, condition_query, option_query);
1049 if (tmp_query != NULL)
1050 SQLITE3_SAFE_FREE(tmp_query);
1051 SAFE_FREE(condition_query);
1052 SAFE_FREE(option_query);
1053 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
1055 if (sqlite3_step(stmt) == SQLITE_ROW)
1056 *item_count = (int)sqlite3_column_int(stmt, 0);
1058 SQLITE3_FINALIZE(stmt);
1063 int _media_db_get_group_item_by_id(int group_id, filter_h filter, media_info_cb callback, void *user_data, group_list_e group_type)
1065 int ret = MEDIA_CONTENT_ERROR_NONE;
1066 char select_query[MAX_QUERY_SIZE] = {0, };
1067 char *condition_query = NULL;
1068 char *option_query = NULL;
1069 sqlite3_stmt *stmt = NULL;
1070 attribute_h attr = NULL;
1071 filter_s *_filter = (filter_s*)filter;
1073 attr = _content_get_attirbute_handle();
1074 memset(select_query, 0x00, sizeof(select_query));
1076 if (group_type == MEDIA_GROUP_ALBUM) {
1077 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
1078 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_ALBUM, _filter->storage_id, group_id);
1080 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_ALBUM, DB_VIEW_MEDIA, group_id);
1081 } else if (group_type == MEDIA_GROUP_PLAYLIST) {
1082 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
1083 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_PLAYLIST, _filter->storage_id, group_id);
1085 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_PLAYLIST, DB_VIEW_MEDIA, group_id);
1086 } else if (group_type == MEDIA_GROUP_TAG) {
1087 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
1088 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_TAG, _filter->storage_id, group_id);
1090 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_TAG, DB_VIEW_MEDIA, group_id);
1092 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1093 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1096 ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query);
1097 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
1099 ret = _content_query_prepare(&stmt, select_query, condition_query, option_query);
1100 SAFE_FREE(condition_query);
1101 SAFE_FREE(option_query);
1102 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
1104 while (sqlite3_step(stmt) == SQLITE_ROW) {
1105 media_info_s *item = (media_info_s*)calloc(1, sizeof(media_info_s));
1107 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1108 SQLITE3_FINALIZE(stmt);
1109 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1112 _media_info_item_get_detail(stmt, (media_info_h)item);
1114 if (callback((media_info_h)item, user_data) == false) {
1115 media_info_destroy((media_info_h)item);
1119 media_info_destroy((media_info_h)item);
1122 SQLITE3_FINALIZE(stmt);
1127 int _media_db_get_group_item(const char *group_name, filter_h filter, media_info_cb callback, void *user_data, group_list_e group_type)
1129 int ret = MEDIA_CONTENT_ERROR_NONE;
1130 char select_query[MAX_QUERY_SIZE] = {0, };
1131 char *condition_query = NULL;
1132 char *option_query = NULL;
1133 sqlite3_stmt *stmt = NULL;
1134 attribute_h attr = NULL;
1135 filter_s *_filter = (filter_s*)filter;
1137 attr = _content_get_attirbute_handle();
1138 memset(select_query, 0x00, sizeof(select_query));
1140 if (group_type == MEDIA_GROUP_NONE) {
1141 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
1142 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_ITEM, _filter->storage_id);
1144 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_ITEM, DB_VIEW_MEDIA);
1145 } else if (group_type == MEDIA_GROUP_FOLDER) {
1146 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
1147 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_FOLDER, _filter->storage_id, group_name);
1149 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_FOLDER, DB_VIEW_MEDIA, group_name);
1150 } else if (group_type == MEDIA_GROUP_STORAGE) {
1151 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_STORAGE, group_name, group_name);
1153 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1154 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1157 ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query);
1158 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
1160 ret = _content_query_prepare(&stmt, select_query, condition_query, option_query);
1161 SAFE_FREE(condition_query);
1162 SAFE_FREE(option_query);
1163 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
1165 while (sqlite3_step(stmt) == SQLITE_ROW) {
1166 media_info_s *item = (media_info_s*)calloc(1, sizeof(media_info_s));
1168 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1169 SQLITE3_FINALIZE(stmt);
1170 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1173 _media_info_item_get_detail(stmt, (media_info_h)item);
1175 if (callback((media_info_h)item, user_data) == false) {
1176 media_info_destroy((media_info_h)item);
1180 media_info_destroy((media_info_h)item);
1183 SQLITE3_FINALIZE(stmt);
1188 #ifdef _USE_SENIOR_MODE
1189 int _media_db_get_group_item_by_union_select(const char *group_name, filter_h filter1, filter_h filter2, media_info_cb callback, void *user_data)
1191 int ret = MEDIA_CONTENT_ERROR_NONE;
1192 char select_query1[MAX_QUERY_SIZE] = {0, };
1193 char *condition_query1 = NULL;
1194 char *option_query1 = NULL;
1195 char select_query2[MAX_QUERY_SIZE] = {0, };
1196 char *condition_query2 = NULL;
1197 char *option_query2 = NULL;
1198 sqlite3_stmt *stmt = NULL;
1199 attribute_h attr = NULL;
1200 filter_s *_filter1 = (filter_s*)filter1;
1201 filter_s *_filter2 = (filter_s*)filter2;
1203 attr = _content_get_attirbute_handle();
1205 memset(select_query1, 0x00, sizeof(select_query1));
1207 if ((_filter1 != NULL) && STRING_VALID(_filter1->storage_id))
1208 snprintf(select_query1, sizeof(select_query1), SELECT_MEDIA_FROM_FOLDER, _filter1->storage_id, group_name);
1210 snprintf(select_query1, sizeof(select_query1), SELECT_MEDIA_FROM_FOLDER, DB_VIEW_MEDIA, group_name);
1212 ret = __media_db_make_query(filter1, attr, select_query1, sizeof(select_query1), &condition_query1, &option_query1);
1213 if (ret != MEDIA_CONTENT_ERROR_NONE) {
1214 SAFE_FREE(condition_query1);
1215 SAFE_FREE(option_query1);
1216 media_content_error("create select_query1 failed");
1220 memset(select_query2, 0x00, sizeof(select_query2));
1222 if ((_filter2 != NULL) && STRING_VALID(_filter2->storage_id))
1223 snprintf(select_query2, sizeof(select_query2), SELECT_MEDIA_FROM_FOLDER, _filter2->storage_id, group_name);
1225 snprintf(select_query2, sizeof(select_query2), SELECT_MEDIA_FROM_FOLDER, DB_VIEW_MEDIA, group_name);
1227 ret = __media_db_make_query(filter2, attr, select_query2, sizeof(select_query2), &condition_query2, &option_query2);
1228 if (ret != MEDIA_CONTENT_ERROR_NONE) {
1229 SAFE_FREE(condition_query1);
1230 SAFE_FREE(option_query1);
1231 SAFE_FREE(condition_query2);
1232 SAFE_FREE(option_query2);
1233 media_content_error("create select_query2 failed");
1237 ret = _content_query_prepare_by_union_select(&stmt, select_query1, condition_query1, option_query1, select_query2, condition_query2, option_query2);
1238 SAFE_FREE(condition_query1);
1239 SAFE_FREE(option_query1);
1240 SAFE_FREE(condition_query2);
1241 SAFE_FREE(option_query2);
1242 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
1244 while (sqlite3_step(stmt) == SQLITE_ROW) {
1245 media_info_s *item = (media_info_s*)calloc(1, sizeof(media_info_s));
1247 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1248 SQLITE3_FINALIZE(stmt);
1249 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1252 _media_info_item_get_detail(stmt, (media_info_h)item);
1254 if (callback((media_info_h)item, user_data) == false) {
1255 media_info_destroy((media_info_h)item);
1259 media_info_destroy((media_info_h)item);
1262 SQLITE3_FINALIZE(stmt);
1268 int _media_db_get_media_group_item_count(const char *group_name, filter_h filter, media_group_e group, int *item_count)
1270 int ret = MEDIA_CONTENT_ERROR_NONE;
1271 sqlite3_stmt *stmt = NULL;
1272 char select_query[MAX_QUERY_SIZE] = {0, };
1273 char *tmp_query = NULL;
1274 char *condition_query = NULL;
1275 char *option_query = NULL;
1276 attribute_h attr = NULL;
1277 filter_s *_filter = (filter_s*)filter;
1279 attr = _content_get_attirbute_handle();
1280 memset(select_query, 0x00, sizeof(select_query));
1281 #ifdef _USE_TVPD_MODE
1282 if (group < MEDIA_PVR_GROUP_DURATION) { /*media content */
1283 if (group_name != NULL) {
1284 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
1285 tmp_query = sqlite3_mprintf(SELECT_MEDIA_COUNT_FROM_GROUP, _filter->storage_id, __media_db_get_group_name(group), group_name);
1287 tmp_query = sqlite3_mprintf(SELECT_MEDIA_COUNT_FROM_GROUP, DB_VIEW_MEDIA, __media_db_get_group_name(group), group_name);
1289 SAFE_STRLCAT(select_query, tmp_query, sizeof(select_query));
1291 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
1292 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_COUNT_FROM_GROUP_NULL, _filter->storage_id, __media_db_get_group_name(group));
1294 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_COUNT_FROM_GROUP_NULL, DB_VIEW_MEDIA, __media_db_get_group_name(group));
1296 } else if (group < MEDIA_UHD_GROUP_CONTENT_TITLE) {/*pvr content*/
1297 if (group_name != NULL) {
1298 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
1299 tmp_query = sqlite3_mprintf(SELECT_PVR_COUNT_FROM_GROUP_BY_STORAGE_ID, _filter->storage_id, __media_db_get_group_name(group), group_name);
1301 tmp_query = sqlite3_mprintf(SELECT_PVR_COUNT_FROM_GROUP, __media_db_get_group_name(group), group_name);
1303 SAFE_STRLCAT(select_query, tmp_query, sizeof(select_query));
1305 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
1306 snprintf(select_query, sizeof(select_query), SELECT_PVR_COUNT_FROM_GROUP_NULL_BY_STORAGE_ID, _filter->storage_id, __media_db_get_group_name(group));
1308 snprintf(select_query, sizeof(select_query), SELECT_PVR_COUNT_FROM_GROUP_NULL, __media_db_get_group_name(group));
1310 } else {/*uhd content*/
1311 if (group_name != NULL) {
1312 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
1313 tmp_query = sqlite3_mprintf(SELECT_UHD_COUNT_FROM_GROUP_BY_STORAGE_ID, _filter->storage_id, __media_db_get_group_name(group), group_name);
1315 tmp_query = sqlite3_mprintf(SELECT_UHD_COUNT_FROM_GROUP, __media_db_get_group_name(group), group_name);
1317 SAFE_STRLCAT(select_query, tmp_query, sizeof(select_query));
1319 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
1320 snprintf(select_query, sizeof(select_query), SELECT_UHD_COUNT_FROM_GROUP_NULL_BY_STORAGE_ID, _filter->storage_id, __media_db_get_group_name(group));
1322 snprintf(select_query, sizeof(select_query), SELECT_UHD_COUNT_FROM_GROUP_NULL, __media_db_get_group_name(group));
1326 if (group_name != NULL) {
1327 if ((_filter != NULL) && STRING_VALID(_filter->storage_id)) {
1328 tmp_query = sqlite3_mprintf(SELECT_MEDIA_COUNT_FROM_GROUP, _filter->storage_id, __media_db_get_group_name(group), group_name);
1329 SAFE_STRLCAT(select_query, tmp_query, sizeof(select_query));
1331 tmp_query = sqlite3_mprintf(SELECT_MEDIA_COUNT_FROM_GROUP, DB_VIEW_MEDIA, __media_db_get_group_name(group), group_name);
1332 SAFE_STRLCAT(select_query, tmp_query, sizeof(select_query));
1335 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
1336 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_COUNT_FROM_GROUP_NULL, _filter->storage_id, __media_db_get_group_name(group));
1338 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_COUNT_FROM_GROUP_NULL, DB_VIEW_MEDIA, __media_db_get_group_name(group));
1341 ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query);
1342 if (ret != MEDIA_CONTENT_ERROR_NONE) {
1343 if (tmp_query != NULL)
1344 SQLITE3_SAFE_FREE(tmp_query);
1348 SAFE_STRLCAT(select_query, QUERY_KEYWORD_SPACE, sizeof(select_query));
1349 if (STRING_VALID(condition_query))
1350 SAFE_STRLCAT(select_query, condition_query, sizeof(select_query));
1351 if (STRING_VALID(option_query))
1352 SAFE_STRLCAT(select_query, option_query, sizeof(select_query));
1353 SAFE_STRLCAT(select_query, QUERY_KEYWORD_BRACKET, sizeof(select_query));
1355 SAFE_FREE(condition_query);
1356 SAFE_FREE(option_query);
1358 ret = _content_query_prepare(&stmt, select_query, condition_query, option_query);
1359 if (tmp_query != NULL)
1360 SQLITE3_SAFE_FREE(tmp_query);
1361 SAFE_FREE(condition_query);
1362 SAFE_FREE(option_query);
1363 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
1365 if (sqlite3_step(stmt) == SQLITE_ROW)
1366 *item_count = (int)sqlite3_column_int(stmt, 0);
1368 SQLITE3_FINALIZE(stmt);
1373 int _media_db_get_media_group_item(const char *group_name, filter_h filter, media_group_e group, media_info_cb callback, void *user_data)
1375 int ret = MEDIA_CONTENT_ERROR_NONE;
1376 char select_query[MAX_QUERY_SIZE] = {0, };
1377 char *tmp_query = NULL;
1378 char *condition_query = NULL;
1379 char *option_query = NULL;
1380 sqlite3_stmt *stmt = NULL;
1381 attribute_h attr = NULL;
1382 filter_s *_filter = (filter_s*)filter;
1384 attr = _content_get_attirbute_handle();
1385 memset(select_query, 0x00, sizeof(select_query));
1387 if (group_name != NULL) {
1388 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
1389 tmp_query = sqlite3_mprintf(SELECT_MEDIA_FROM_GROUP, _filter->storage_id, __media_db_get_group_name(group), group_name);
1391 tmp_query = sqlite3_mprintf(SELECT_MEDIA_FROM_GROUP, DB_VIEW_MEDIA, __media_db_get_group_name(group), group_name);
1393 SAFE_STRLCAT(select_query, tmp_query, sizeof(select_query));
1395 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
1396 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_GROUP_NULL, _filter->storage_id, __media_db_get_group_name(group));
1398 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_GROUP_NULL, DB_VIEW_MEDIA, __media_db_get_group_name(group));
1401 ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query);
1402 if (ret != MEDIA_CONTENT_ERROR_NONE) {
1403 if (tmp_query != NULL)
1404 SQLITE3_SAFE_FREE(tmp_query);
1408 ret = _content_query_prepare(&stmt, select_query, condition_query, option_query);
1409 if (tmp_query != NULL)
1410 SQLITE3_SAFE_FREE(tmp_query);
1411 SAFE_FREE(condition_query);
1412 SAFE_FREE(option_query);
1413 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
1415 while (sqlite3_step(stmt) == SQLITE_ROW) {
1416 media_info_s *item = (media_info_s*)calloc(1, sizeof(media_info_s));
1418 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1419 SQLITE3_FINALIZE(stmt);
1420 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1423 _media_info_item_get_detail(stmt, (media_info_h)item);
1425 if (callback((media_info_h)item, user_data) == false) {
1426 media_info_destroy((media_info_h)item);
1430 media_info_destroy((media_info_h)item);
1433 SQLITE3_FINALIZE(stmt);
1438 int _media_db_get_storage(filter_h filter, media_storage_cb callback, void *user_data)
1440 int ret = MEDIA_CONTENT_ERROR_NONE;
1441 char select_query[DEFAULT_QUERY_SIZE] = {0, };
1442 char *condition_query = NULL;
1443 char *option_query = NULL;
1444 sqlite3_stmt *stmt = NULL;
1445 attribute_h attr = NULL;
1447 attr = _content_get_attirbute_handle();
1448 memset(select_query, 0x00, sizeof(select_query));
1450 if (!SAFE_STRLCPY(select_query, SELECT_STORAGE_LIST, sizeof(select_query))) {
1451 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1452 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1455 ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query);
1456 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
1458 ret = _content_query_prepare(&stmt, select_query, condition_query, option_query);
1459 SAFE_FREE(condition_query);
1460 SAFE_FREE(option_query);
1461 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
1463 while (sqlite3_step(stmt) == SQLITE_ROW) {
1464 media_storage_s *_storage = (media_storage_s*)calloc(1, sizeof(media_storage_s));
1466 if (_storage == NULL) {
1467 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1468 SQLITE3_FINALIZE(stmt);
1469 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1472 _storage->storage_id = g_strdup((const char *)sqlite3_column_text(stmt, 0));
1473 _storage->storage_path = g_strdup((const char *)sqlite3_column_text(stmt, 1));
1474 _storage->storage_type = (int)sqlite3_column_int(stmt, 2);
1476 if (callback((media_storage_h)_storage, user_data) == false) {
1477 media_storage_destroy((media_storage_h) _storage);
1481 media_storage_destroy((media_storage_h) _storage);
1484 SQLITE3_FINALIZE(stmt);
1488 #ifdef _USE_TVPD_MODE
1489 int _media_db_get_pvr_group_item(const char *group_name, filter_h filter, media_group_e group, media_pvr_cb callback, void *user_data)
1491 int ret = MEDIA_CONTENT_ERROR_NONE;
1492 char select_query[DEFAULT_QUERY_SIZE] = {0, };
1493 char *tmp_query = NULL;
1494 char *condition_query = NULL;
1495 char *option_query = NULL;
1496 sqlite3_stmt *stmt = NULL;
1497 attribute_h attr = NULL;
1498 filter_s *_filter = (filter_s*)filter;
1500 attr = _content_get_attirbute_handle();
1501 memset(select_query, 0x00, sizeof(select_query));
1503 if (group_name != NULL) {
1504 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
1505 tmp_query = sqlite3_mprintf(SELECT_PVR_FROM_GROUP_BY_STORAGE_ID, _filter->storage_id, __media_db_get_group_name(group), group_name);
1507 tmp_query = sqlite3_mprintf(SELECT_PVR_FROM_GROUP, __media_db_get_group_name(group), group_name);
1509 SAFE_STRLCAT(select_query, tmp_query, sizeof(select_query));
1511 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
1512 snprintf(select_query, sizeof(select_query), SELECT_PVR_FROM_GROUP_NULL_BY_STORAGE_ID, _filter->storage_id, __media_db_get_group_name(group));
1514 snprintf(select_query, sizeof(select_query), SELECT_PVR_FROM_GROUP_NULL, __media_db_get_group_name(group));
1517 ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query);
1518 if (ret != MEDIA_CONTENT_ERROR_NONE) {
1519 if (tmp_query != NULL)
1520 sqlite3_free(tmp_query);
1524 ret = _content_query_prepare(&stmt, select_query, condition_query, option_query);
1525 if (tmp_query != NULL)
1526 sqlite3_free(tmp_query);
1527 SAFE_FREE(condition_query);
1528 SAFE_FREE(option_query);
1529 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
1531 while (sqlite3_step(stmt) == SQLITE_ROW) {
1532 media_pvr_s *item = (media_pvr_s*)calloc(1, sizeof(media_pvr_s));
1534 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1535 SQLITE3_FINALIZE(stmt);
1536 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1539 _media_pvr_item_get_detail(stmt, (media_pvr_h)item);
1541 if (callback((media_pvr_h)item, user_data) == false) {
1542 media_info_destroy((media_pvr_h)item);
1546 media_pvr_destroy((media_pvr_h)item);
1549 SQLITE3_FINALIZE(stmt);
1555 MEDIA_PVR_MEDIA_ID = 0,
1556 MEDIA_PVR_STORAGE_ID,
1560 MEDIA_PVR_TIME_ZONE,
1564 MEDIA_PVR_CHANNEL_TYPE,
1565 MEDIA_PVR_CHANNEL_NAME,
1566 MEDIA_PVR_CHANNEL_NUM,
1567 MEDIA_PVR_PROGRAM_TITLE,
1568 MEDIA_PVR_PROGRAM_NUM,
1569 MEDIA_PVR_PROGRAM_CRID,
1574 MEDIA_PVR_EMBARGO_TIME,
1575 MEDIA_PVR_EXPIRY_TIME,
1576 MEDIA_PVR_START_TIME,
1577 MEDIA_PVR_PROGRAM_START_TIME,
1578 MEDIA_PVR_PROGRAM_END_TIME,
1579 MEDIA_PVR_PROGRAM_DATE,
1580 MEDIA_PVR_PARENTAL_RATING,
1581 MEDIA_PVR_TIMER_RECORD,
1582 MEDIA_PVR_SERIES_RECORD,
1587 MEDIA_PVR_HARDOF_HEARINGRADIO,
1588 MEDIA_PVR_DATA_SERVICE,
1589 MEDIA_PVR_CONTENT_LOCK,
1590 MEDIA_PVR_CONTENT_WATCH,
1591 MEDIA_PVR_HAS_AUDIO_ONLY,
1592 MEDIA_PVR_IS_LOCAL_RECORDED,
1593 MEDIA_PVR_RESOLUTION,
1594 MEDIA_PVR_ASPECTRATIO,
1595 MEDIA_PVR_MODIFIED_MONTH,
1596 MEDIA_PVR_SPORTS_TYPE,
1597 MEDIA_PVR_GUIDANCE_LENGTH,
1599 MEDIA_PVR_PLAY_COUNT,
1600 MEDIA_PVR_PRIVATE_DATA,
1601 MEDIA_PVR_HIGHLIGHT,
1602 } media_pvr_field_e;
1604 void _media_pvr_item_get_detail(sqlite3_stmt* stmt, media_pvr_h pvr)
1606 media_pvr_s *_pvr = (media_pvr_s*)pvr;
1608 if (STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_PVR_MEDIA_ID)))
1609 _pvr->media_id = strdup((const char *)sqlite3_column_text(stmt, MEDIA_PVR_MEDIA_ID));
1611 if (STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_PVR_STORAGE_ID)))
1612 _pvr->storage_id = strdup((const char *)sqlite3_column_text(stmt, MEDIA_PVR_STORAGE_ID));
1614 if (STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_PVR_PATH)))
1615 _pvr->path = strdup((const char *)sqlite3_column_text(stmt, MEDIA_PVR_PATH));
1617 _pvr->size = (unsigned long long)sqlite3_column_int64(stmt, MEDIA_PVR_SIZE);
1619 _pvr->duration = (int)sqlite3_column_int(stmt, MEDIA_PVR_DURATION);
1621 _pvr->timezone = (int)sqlite3_column_int(stmt, MEDIA_PVR_TIME_ZONE);
1623 _pvr->ptc = (int)sqlite3_column_int(stmt, MEDIA_PVR_PTC);
1625 _pvr->major = (int)sqlite3_column_int(stmt, MEDIA_PVR_MAJOR);
1627 _pvr->minor = (int)sqlite3_column_int(stmt, MEDIA_PVR_MINOR);
1629 _pvr->channel_type = (int)sqlite3_column_int(stmt, MEDIA_PVR_CHANNEL_TYPE);
1631 if (STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_PVR_CHANNEL_NAME)))
1632 _pvr->channel_name = strdup((const char *)sqlite3_column_text(stmt, MEDIA_PVR_CHANNEL_NAME));
1634 if (STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_PVR_CHANNEL_NUM)))
1635 _pvr->channel_num = strdup((const char *)sqlite3_column_text(stmt, MEDIA_PVR_CHANNEL_NUM));
1637 if (STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_PVR_PROGRAM_TITLE)))
1638 _pvr->program_title = strdup((const char *)sqlite3_column_text(stmt, MEDIA_PVR_PROGRAM_TITLE));
1640 _pvr->program_num = (int)sqlite3_column_int(stmt, MEDIA_PVR_PROGRAM_NUM);
1642 if (STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_PVR_PROGRAM_CRID)))
1643 _pvr->program_crid = strdup((const char *)sqlite3_column_text(stmt, MEDIA_PVR_PROGRAM_CRID));
1645 if (STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_PVR_GUIDANCE)))
1646 _pvr->guidance = strdup((const char *)sqlite3_column_text(stmt, MEDIA_PVR_GUIDANCE));
1648 if (STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_PVR_SYNOPSIS)))
1649 _pvr->synopsis = strdup((const char *)sqlite3_column_text(stmt, MEDIA_PVR_SYNOPSIS));
1651 if (STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_PVR_GENRE)))
1652 _pvr->genre = strdup((const char *)sqlite3_column_text(stmt, MEDIA_PVR_GENRE));
1654 if (STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_PVR_LANGUAGE)))
1655 _pvr->language = strdup((const char *)sqlite3_column_text(stmt, MEDIA_PVR_LANGUAGE));
1657 if (STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_PVR_MODIFIED_MONTH)))
1658 _pvr->modified_month = strdup((const char *)sqlite3_column_text(stmt, MEDIA_PVR_MODIFIED_MONTH));
1660 if (STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_PVR_PRIVATE_DATA)))
1661 _pvr->private_data = strdup((const char *)sqlite3_column_text(stmt, MEDIA_PVR_PRIVATE_DATA));
1663 _pvr->embargo_time = (int)sqlite3_column_int(stmt, MEDIA_PVR_EMBARGO_TIME);
1665 _pvr->expiry_time = (int)sqlite3_column_int(stmt, MEDIA_PVR_EXPIRY_TIME);
1667 _pvr->start_time = (int)sqlite3_column_int(stmt, MEDIA_PVR_START_TIME);
1669 _pvr->program_start_time = (int)sqlite3_column_int(stmt, MEDIA_PVR_PROGRAM_START_TIME);
1671 _pvr->program_end_time = (int)sqlite3_column_int(stmt, MEDIA_PVR_PROGRAM_END_TIME);
1673 _pvr->program_date = (int)sqlite3_column_int(stmt, MEDIA_PVR_PROGRAM_DATE);
1675 _pvr->parental_rating = (int)sqlite3_column_int(stmt, MEDIA_PVR_PARENTAL_RATING);
1677 _pvr->timer_record = (int)sqlite3_column_int(stmt, MEDIA_PVR_TIMER_RECORD);
1679 _pvr->series_record = (int)sqlite3_column_int(stmt, MEDIA_PVR_SERIES_RECORD);
1681 _pvr->hd = (int)sqlite3_column_int(stmt, MEDIA_PVR_HD);
1683 _pvr->subtitle = (int)sqlite3_column_int(stmt, MEDIA_PVR_SUBTITLE);
1685 _pvr->ttx = (int)sqlite3_column_int(stmt, MEDIA_PVR_TTX);
1687 _pvr->ad = (int)sqlite3_column_int(stmt, MEDIA_PVR_AD);
1689 _pvr->hard_of_hearing_radio = (int)sqlite3_column_int(stmt, MEDIA_PVR_HARDOF_HEARINGRADIO);
1691 _pvr->data_service = (int)sqlite3_column_int(stmt, MEDIA_PVR_DATA_SERVICE);
1693 _pvr->content_lock = (int)sqlite3_column_int(stmt, MEDIA_PVR_CONTENT_LOCK);
1695 _pvr->content_watch = (int)sqlite3_column_int(stmt, MEDIA_PVR_CONTENT_WATCH);
1697 _pvr->has_audio_only = (int)sqlite3_column_int(stmt, MEDIA_PVR_HAS_AUDIO_ONLY);
1699 _pvr->is_local_record = (int)sqlite3_column_int(stmt, MEDIA_PVR_IS_LOCAL_RECORDED);
1701 _pvr->resolution = (int)sqlite3_column_int(stmt, MEDIA_PVR_RESOLUTION);
1703 _pvr->aspectratio = (int)sqlite3_column_int(stmt, MEDIA_PVR_ASPECTRATIO);
1705 _pvr->sports_type = (int)sqlite3_column_int(stmt, MEDIA_PVR_SPORTS_TYPE);
1707 _pvr->guidance_length = (int)sqlite3_column_int(stmt, MEDIA_PVR_GUIDANCE_LENGTH);
1709 _pvr->tvmode = (int)sqlite3_column_int(stmt, MEDIA_PVR_TVMODE);
1711 _pvr->play_count = (int)sqlite3_column_int(stmt, MEDIA_PVR_PLAY_COUNT);
1713 _pvr->highlight = (int)sqlite3_column_int(stmt, MEDIA_PVR_HIGHLIGHT);
1718 int _media_db_get_pvr(filter_h filter, media_pvr_cb callback, void *user_data)
1720 int ret = MEDIA_CONTENT_ERROR_NONE;
1721 char select_query[DEFAULT_QUERY_SIZE] = {0, };
1722 char *condition_query = NULL;
1723 char *option_query = NULL;
1724 sqlite3_stmt *stmt = NULL;
1725 attribute_h attr = NULL;
1726 filter_s *_filter = (filter_s*)filter;
1728 attr = _content_get_attirbute_handle();
1729 memset(select_query, 0x00, sizeof(select_query));
1731 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
1732 snprintf(select_query, sizeof(select_query), SELECT_PVR_LIST_BY_STORAGE_ID, _filter->storage_id);
1734 SAFE_STRLCAT(select_query, SELECT_PVR_LIST, sizeof(select_query));
1736 ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query);
1737 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
1739 ret = _content_query_prepare(&stmt, select_query, condition_query, option_query);
1740 SAFE_FREE(condition_query);
1741 SAFE_FREE(option_query);
1742 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
1744 while (sqlite3_step(stmt) == SQLITE_ROW) {
1745 media_pvr_s *_pvr = (media_pvr_s*)calloc(1, sizeof(media_pvr_s));
1748 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1749 SQLITE3_FINALIZE(stmt);
1750 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1753 _media_pvr_item_get_detail(stmt, (media_pvr_h)_pvr);
1755 if (callback((media_pvr_h)_pvr, user_data) == false) {
1756 media_pvr_destroy((media_pvr_h) _pvr);
1760 media_pvr_destroy((media_pvr_h) _pvr);
1763 SQLITE3_FINALIZE(stmt);
1769 int _media_db_get_storage_id_by_media_id(const char *media_id, char *storage_id)
1771 int ret = MEDIA_CONTENT_ERROR_NONE;
1772 sqlite3_stmt *stmt = NULL;
1773 char *select_query = NULL;
1775 select_query = sqlite3_mprintf(SELECT_MEDIA_STORAGE_ID_BY_ID, media_id);
1777 ret = _content_query_prepare(&stmt, select_query, NULL, NULL);
1778 SQLITE3_SAFE_FREE(select_query);
1779 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
1781 if (sqlite3_step(stmt) == SQLITE_ROW) {
1782 if (STRING_VALID((const char *)sqlite3_column_text(stmt, 0))) {
1783 if (!SAFE_STRLCPY(storage_id, (const char *)sqlite3_column_text(stmt, 0), MEDIA_CONTENT_UUID_SIZE+1)) {
1784 media_content_error("Storage id copy fail");
1785 ret = MEDIA_CONTENT_ERROR_INVALID_OPERATION;
1789 media_content_error("There's no media!!");
1790 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1793 SQLITE3_FINALIZE(stmt);
1798 #ifdef _USE_TVPD_MODE
1800 MEDIA_UHD_MEDIA_ID = 0,
1801 MEDIA_UHD_STORAGE_ID,
1804 MEDIA_UHD_CONTENT_ID,
1805 MEDIA_UHD_CONTENT_TITLE,
1806 MEDIA_UHD_FILE_NAME,
1807 MEDIA_UHD_FOLDER_ID,
1808 MEDIA_UHD_RELEASE_DATE,
1809 MEDIA_UHD_MODIFIED_TIME,
1810 MEDIA_UHD_PLAYED_POSITION,
1812 MEDIA_UHD_PLAYED_COUNT,
1813 } media_uhd_field_e;
1815 void _media_uhd_item_get_detail(sqlite3_stmt* stmt, media_uhd_h uhd)
1817 media_uhd_s *_uhd = (media_uhd_s*)uhd;
1819 if (STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_UHD_MEDIA_ID)))
1820 _uhd->media_id = strdup((const char *)sqlite3_column_text(stmt, MEDIA_UHD_MEDIA_ID));
1822 if (STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_UHD_STORAGE_ID)))
1823 _uhd->storage_id = strdup((const char *)sqlite3_column_text(stmt, MEDIA_UHD_STORAGE_ID));
1825 if (STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_UHD_PATH)))
1826 _uhd->path = strdup((const char *)sqlite3_column_text(stmt, MEDIA_UHD_PATH));
1828 _uhd->size = (unsigned long long)sqlite3_column_int64(stmt, MEDIA_UHD_SIZE);
1830 if (STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_UHD_CONTENT_ID)))
1831 _uhd->content_id = strdup((const char *)sqlite3_column_text(stmt, MEDIA_UHD_CONTENT_ID));
1833 if (STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_UHD_CONTENT_TITLE)))
1834 _uhd->content_title = strdup((const char *)sqlite3_column_text(stmt, MEDIA_UHD_CONTENT_TITLE));
1836 if (STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_UHD_FILE_NAME)))
1837 _uhd->file_name = strdup((const char *)sqlite3_column_text(stmt, MEDIA_UHD_FILE_NAME));
1839 if (STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_UHD_RELEASE_DATE)))
1840 _uhd->release_date = strdup((const char *)sqlite3_column_text(stmt, MEDIA_UHD_RELEASE_DATE));
1842 _uhd->modified_time = (int)sqlite3_column_int(stmt, MEDIA_UHD_MODIFIED_TIME);
1843 _uhd->played_position = (int)sqlite3_column_int(stmt, MEDIA_UHD_PLAYED_POSITION);
1844 _uhd->sub_type = (int)sqlite3_column_int(stmt, MEDIA_UHD_SUB_TYPE);
1845 _uhd->played_count = (int)sqlite3_column_int(stmt, MEDIA_UHD_PLAYED_COUNT);
1850 int _media_db_get_uhd(filter_h filter, media_uhd_cb callback, void *user_data)
1852 int ret = MEDIA_CONTENT_ERROR_NONE;
1853 char select_query[DEFAULT_QUERY_SIZE] = {0, };
1854 char *condition_query = NULL;
1855 char *option_query = NULL;
1856 sqlite3_stmt *stmt = NULL;
1857 attribute_h attr = NULL;
1858 filter_s *_filter = (filter_s*)filter;
1860 attr = _content_get_attirbute_handle();
1861 memset(select_query, 0x00, sizeof(select_query));
1863 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
1864 snprintf(select_query, sizeof(select_query), SELECT_UHD_LIST_BY_STORAGE_ID, _filter->storage_id);
1866 SAFE_STRLCAT(select_query, SELECT_UHD_LIST, sizeof(select_query));
1868 ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query);
1869 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
1871 ret = _content_query_prepare(&stmt, select_query, condition_query, option_query);
1872 SAFE_FREE(condition_query);
1873 SAFE_FREE(option_query);
1874 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
1876 while (sqlite3_step(stmt) == SQLITE_ROW) {
1877 media_uhd_s *_uhd = (media_uhd_s*)calloc(1, sizeof(media_uhd_s));
1880 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1881 SQLITE3_FINALIZE(stmt);
1882 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1885 _media_uhd_item_get_detail(stmt, (media_uhd_h)_uhd);
1887 if (callback((media_uhd_h)_uhd, user_data) == false) {
1888 media_uhd_destroy((media_uhd_h) _uhd);
1891 media_uhd_destroy((media_uhd_h) _uhd);
1894 SQLITE3_FINALIZE(stmt);