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_BURST_IMAGE:
67 return (char *) DB_FIELD_MEDIA_BURST_ID;
68 case MEDIA_CONTENT_GROUP_RATING:
69 return (char *) DB_FIELD_MEDIA_RATING;
70 case MEDIA_CONTENT_GROUP_AUTHOR:
71 return (char *) DB_FIELD_MEDIA_AUTHOR;
72 case MEDIA_CONTENT_GROUP_PROVIDER:
73 return (char *) DB_FIELD_MEDIA_PROVIDER;
74 case MEDIA_CONTENT_GROUP_CONTENT_NAME:
75 return (char *) DB_FIELD_MEDIA_CONTENT_NAME;
76 case MEDIA_CONTENT_GROUP_CATEGORY:
77 return (char *) DB_FIELD_MEDIA_CATEGORY;
78 case MEDIA_CONTENT_GROUP_LOCATION_TAG:
79 return (char *) DB_FIELD_MEDIA_LOCATION_TAG;
80 case MEDIA_CONTENT_GROUP_AGE_RATING:
81 return (char *) DB_FIELD_MEDIA_AGE_RATING;
82 case MEDIA_CONTENT_GROUP_KEYWORD:
83 return (char *) DB_FIELD_MEDIA_KEYWORD;
84 case MEDIA_CONTENT_GROUP_WEATHER:
85 return (char *) DB_FIELD_MEDIA_WEATHER;
86 #ifdef _USE_TV_PROFILE
87 case MEDIA_CONTENT_GROUP_MODIFIED_MONTH:
88 return (char *) DB_FIELD_MEDIA_MODIFIED_DATE;
89 case MEDIA_CONTENT_GROUP_MODIFIED_DATE:
90 return (char *) DB_FIELD_MEDIA_MODIFIED_DATE;
92 #ifdef _USE_SENIOR_MODE
93 case MEDIA_CONTENT_GROUP_CONTACT:
94 return (char *) DB_FIELD_MEDIA_CONTACT;
96 #ifdef _USE_TV_PROFILE
97 case MEDIA_CONTENT_GROUP_ALBUM:
98 return (char *) DB_FIELD_MEDIA_ALBUM;
99 case MEDIA_PVR_GROUP_DURATION:
100 return (char *) DB_FIELD_PVR_DURATION;
101 case MEDIA_PVR_GROUP_TIME_ZONE:
102 return (char *) DB_FIELD_PVR_TIME_ZONE;
103 case MEDIA_PVR_GROUP_PTC:
104 return (char *) DB_FIELD_PVR_PTC;
105 case MEDIA_PVR_GROUP_MAJOR:
106 return (char *) DB_FIELD_PVR_MAJOR;
107 case MEDIA_PVR_GROUP_MINOR:
108 return (char *) DB_FIELD_PVR_MINOR;
109 case MEDIA_PVR_GROUP_CHANNEL_TYPE:
110 return (char *) DB_FIELD_PVR_CHANNEL_TYPE;
111 case MEDIA_PVR_GROUP_CHANNEL_NAME:
112 return (char *) DB_FIELD_PVR_CHANNEL_NAME;
113 case MEDIA_PVR_GROUP_CHANNEL_NUM:
114 return (char *) DB_FIELD_PVR_CHANNEL_NUM;
115 case MEDIA_PVR_GROUP_PROGRAM_TITLE:
116 return (char *) DB_FIELD_PVR_PROGRAM_TITLE;
117 case MEDIA_PVR_GROUP_PROGRAM_NUM:
118 return (char *) DB_FIELD_PVR_PROGRAM_NUM;
119 case MEDIA_PVR_GROUP_PROGRAM_CRID:
120 return (char *) DB_FIELD_PVR_PROGRAM_CRID;
121 case MEDIA_PVR_GROUP_GUIDANCE:
122 return (char *) DB_FIELD_PVR_GUIDANCE;
123 case MEDIA_PVR_GROUP_SYNOPSIS:
124 return (char *) DB_FIELD_PVR_SYNOPSIS;
125 case MEDIA_PVR_GROUP_GENRE:
126 return (char *) DB_FIELD_PVR_GENRE;
127 case MEDIA_PVR_GROUP_LANGUAGE:
128 return (char *) DB_FIELD_PVR_LANGUAGE;
129 case MEDIA_PVR_GROUP_EMBARGO_TIME:
130 return (char *) DB_FIELD_PVR_EMBARGO_TIME;
131 case MEDIA_PVR_GROUP_EXPIRY_TIME:
132 return (char *) DB_FIELD_PVR_EXPIRY_TIME;
133 case MEDIA_PVR_GROUP_START_TIME:
134 return (char *) DB_FIELD_PVR_START_TIME;
135 case MEDIA_PVR_GROUP_PROGRAM_START_TIME:
136 return (char *) DB_FIELD_PVR_PROGRAM_START_TIME;
137 case MEDIA_PVR_GROUP_PROGRAM_END_TIME:
138 return (char *) DB_FIELD_PVR_PROGRAM_END_TIME;
139 case MEDIA_PVR_GROUP_PROGRAM_DATE:
140 return (char *) DB_FIELD_PVR_PROGRAM_DATE;
141 case MEDIA_PVR_GROUP_PARENTAL_RATING:
142 return (char *) DB_FIELD_PVR_PARENTAL_RATING;
143 case MEDIA_PVR_GROUP_TIMER_RECORD:
144 return (char *) DB_FIELD_PVR_TIMER_RECORD;
145 case MEDIA_PVR_GROUP_SERIES_RECORD:
146 return (char *) DB_FIELD_PVR_SERIES_RECORD;
147 case MEDIA_PVR_GROUP_HD:
148 return (char *) DB_FIELD_PVR_HD;
149 case MEDIA_PVR_GROUP_SUBTITLE:
150 return (char *) DB_FIELD_PVR_SUBTITLE;
151 case MEDIA_PVR_GROUP_TTX:
152 return (char *) DB_FIELD_PVR_TTX;
153 case MEDIA_PVR_GROUP_AD:
154 return (char *) DB_FIELD_PVR_AD;
155 case MEDIA_PVR_GROUP_HARDOF_HEARINGRADIO:
156 return (char *) DB_FIELD_PVR_HARDOF_HEARINGRADIO;
157 case MEDIA_PVR_GROUP_DATA_SERVICE:
158 return (char *) DB_FIELD_PVR_DATA_SERVICE;
159 case MEDIA_PVR_GROUP_CONTENT_LOCK:
160 return (char *) DB_FIELD_PVR_CONTENT_LOCK;
161 case MEDIA_PVR_GROUP_CONTENT_WATCH:
162 return (char *) DB_FIELD_PVR_CONTENT_WATCH;
163 case MEDIA_PVR_GROUP_HAS_AUDIO_ONLY:
164 return (char *) DB_FIELD_PVR_HAS_AUDIO_ONLY;
165 case MEDIA_PVR_GROUP_IS_LOCAL_RECORDED:
166 return (char *) DB_FIELD_PVR_IS_LOCAL_RECORD;
167 case MEDIA_PVR_GROUP_RESOLUTION:
168 return (char *) DB_FIELD_PVR_RESOLUTION;
169 case MEDIA_PVR_GROUP_ASPECTRATIO:
170 return (char *) DB_FIELD_PVR_ASPECTRATIO;
171 case MEDIA_PVR_GROUP_MODIFIED_MONTH:
172 return (char *) DB_FIELD_PVR_MODIFIED_DATE;
173 case MEDIA_PVR_GROUP_MODIFIED_DATE:
174 return (char *) DB_FIELD_PVR_MODIFIED_DATE;
175 case MEDIA_PVR_GROUP_SPORTS_TYPE:
176 return (char *) DB_FIELD_PVR_SPORTS_TYPE;
177 case MEDIA_PVR_GROUP_GUIDANCE_LENGTH:
178 return (char *) DB_FIELD_PVR_GUIDANCE_LENGTH;
179 case MEDIA_PVR_GROUP_TVMODE:
180 return (char *) DB_FIELD_PVR_TVMODE;
181 case MEDIA_PVR_GROUP_PLAY_COUNT:
182 return (char *) DB_FIELD_PVR_PLAY_COUNT;
183 case MEDIA_PVR_GROUP_PRIVATE_DATA:
184 return (char *) DB_FIELD_PVR_PRIVATE_DATA;
185 case MEDIA_UHD_GROUP_CONTENT_TITLE:
186 return (char *) DB_FIELD_UHD_CONTENT_TITLE;
187 case MEDIA_UHD_GROUP_RELEASE_DATE:
188 return (char *) DB_FIELD_UHD_RELEASE_DATE;
189 case MEDIA_UHD_GROUP_SUB_TYPE:
190 return (char *) DB_FIELD_UHD_SUB_TYPE;
191 case MEDIA_UHD_GROUP_FILE_NAME:
192 return (char *) DB_FIELD_UHD_FILE_NAME;
193 case MEDIA_UHD_GROUP_PLAYED_COUNT:
194 return (char *) DB_FIELD_UHD_PLAYED_COUNT;
203 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)
205 int ret = MEDIA_CONTENT_ERROR_NONE;
206 filter_s *_filter = NULL;
208 if (filter != NULL) {
209 _filter = (filter_s*)filter;
211 if (STRING_VALID(_filter->condition)) {
212 /*bracket should be added to condition. If application use "OR" condition, F/W restriction condition like "validity=1" is disregared
213 ex) select path from media where validity=1 and media_type=3 or media_type=1;*/
214 char bracket_added_condition[MAX_QUERY_SIZE] = {0, };
215 memset(bracket_added_condition, 0x00, sizeof(bracket_added_condition));
217 SAFE_STRLCAT(bracket_added_condition, QUERY_KEYWORD_OPEN_BRACKET, MAX_QUERY_SIZE);
218 SAFE_STRLCAT(bracket_added_condition, _filter->condition, MAX_QUERY_SIZE);
219 SAFE_STRLCAT(bracket_added_condition, QUERY_KEYWORD_BRACKET, MAX_QUERY_SIZE);
221 ret = _media_filter_attribute_generate(attr, bracket_added_condition, _filter->condition_collate_type, condition_query);
222 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
225 ret = _media_filter_attribute_option_generate(attr, filter, option_query);
226 if (ret != MEDIA_CONTENT_ERROR_NONE) {
227 SAFE_FREE(*condition_query);
231 if (STRING_VALID(*condition_query)) {
232 SAFE_STRLCAT(select_query, QUERY_KEYWORD_SPACE, select_query_size);
233 SAFE_STRLCAT(select_query, QUERY_KEYWORD_AND, select_query_size);
240 int _media_db_get_group_count(filter_h filter, group_list_e group_type, int *group_count)
242 int ret = MEDIA_CONTENT_ERROR_NONE;
243 sqlite3_stmt *stmt = NULL;
244 char select_query[MAX_QUERY_SIZE] = {0, };
245 char *condition_query = NULL;
246 char *option_query = NULL;
247 attribute_h attr = NULL;
248 filter_s *_filter = (filter_s*)filter;
250 attr = _content_get_attirbute_handle();
251 memset(select_query, 0x00, sizeof(select_query));
253 switch (group_type) {
254 case MEDIA_GROUP_NONE:
255 case MEDIA_GROUP_TAG_BY_MEDIA_ID:
256 case MEDIA_GROUP_BOOKMARK_BY_MEDIA_ID:
258 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
259 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
262 case MEDIA_GROUP_ALBUM:
263 attr = _content_get_alias_attirbute_handle();
265 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
266 snprintf(select_query, sizeof(select_query), SELECT_ALBUM_COUNT, _filter->storage_id);
268 snprintf(select_query, sizeof(select_query), SELECT_ALBUM_COUNT, DB_TABLE_MEDIA_VIEW);
271 case MEDIA_GROUP_FOLDER:
272 attr = _content_get_alias_attirbute_handle();
273 if (!SAFE_STRLCPY(select_query, SELECT_FOLDER_COUNT, sizeof(select_query))) {
274 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
275 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
278 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
279 snprintf(select_query, sizeof(select_query), SELECT_FOLDER_COUNT_BY_STORAGE_ID, _filter->storage_id, _filter->storage_id);
281 snprintf(select_query, sizeof(select_query), SELECT_FOLDER_COUNT, DB_TABLE_MEDIA_VIEW);
284 case MEDIA_GROUP_PLAYLIST:
285 if (!SAFE_STRLCPY(select_query, SELECT_PLAYLIST_COUNT, sizeof(select_query))) {
286 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
287 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
290 case MEDIA_GROUP_TAG:
291 if (!SAFE_STRLCPY(select_query, SELECT_TAG_COUNT, sizeof(select_query))) {
292 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
293 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
296 case MEDIA_GROUP_BOOKMARK:
297 attr = _content_get_alias_attirbute_handle();
299 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
300 snprintf(select_query, sizeof(select_query), SELECT_BOOKMARK_COUNT, _filter->storage_id);
302 snprintf(select_query, sizeof(select_query), SELECT_BOOKMARK_COUNT, DB_TABLE_MEDIA_VIEW);
305 case MEDIA_GROUP_STORAGE:
306 if (!SAFE_STRLCPY(select_query, SELECT_STORAGE_COUNT, sizeof(select_query))) {
307 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
308 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
311 #ifdef _USE_TV_PROFILE
312 case MEDIA_GROUP_PVR:
313 case MEDIA_GROUP_UHD:
317 media_content_error("Invalid group type [%d]", group_type);
318 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
323 ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query);
324 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
326 ret = _content_query_prepare(&stmt, select_query, condition_query, option_query);
327 SAFE_FREE(condition_query);
328 SAFE_FREE(option_query);
329 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
331 while (sqlite3_step(stmt) == SQLITE_ROW)
332 *group_count = (int)sqlite3_column_int(stmt, 0);
334 SQLITE3_FINALIZE(stmt);
339 int _media_db_get_media_group_count(media_group_e group, filter_h filter, int *group_count)
341 int ret = MEDIA_CONTENT_ERROR_NONE;
342 sqlite3_stmt *stmt = NULL;
343 char select_query[MAX_QUERY_SIZE] = {0, };
344 char *condition_query = NULL;
345 char *option_query = NULL;
346 attribute_h attr = NULL;
347 filter_s *_filter = (filter_s*)filter;
349 attr = _content_get_attirbute_handle();
350 memset(select_query, 0x00, sizeof(select_query));
351 #ifdef _USE_TV_PROFILE
352 if (group < MEDIA_PVR_GROUP_DURATION) { /*media content*/
353 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
354 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_GROUP_COUNT, __media_db_get_group_name(group), _filter->storage_id);
356 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_GROUP_COUNT, __media_db_get_group_name(group), DB_TABLE_MEDIA_VIEW);
357 } else if (group < MEDIA_UHD_GROUP_CONTENT_TITLE) { /*pvr content*/
358 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
359 snprintf(select_query, sizeof(select_query), SELECT_PVR_GROUP_COUNT_BY_STORAGE_ID, __media_db_get_group_name(group), _filter->storage_id);
361 snprintf(select_query, sizeof(select_query), SELECT_PVR_GROUP_COUNT, __media_db_get_group_name(group));
362 } else { /*uhd content*/
363 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
364 snprintf(select_query, sizeof(select_query), SELECT_UHD_GROUP_COUNT_BY_STORAGE_ID, __media_db_get_group_name(group), _filter->storage_id);
366 snprintf(select_query, sizeof(select_query), SELECT_UHD_GROUP_COUNT, __media_db_get_group_name(group));
369 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
370 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_GROUP_COUNT, __media_db_get_group_name(group), _filter->storage_id);
372 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_GROUP_COUNT, __media_db_get_group_name(group), DB_TABLE_MEDIA_VIEW);
374 ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query);
375 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
377 SAFE_STRLCAT(select_query, QUERY_KEYWORD_SPACE, sizeof(select_query));
378 if (STRING_VALID(condition_query))
379 SAFE_STRLCAT(select_query, condition_query, sizeof(select_query));
380 if (STRING_VALID(option_query))
381 SAFE_STRLCAT(select_query, option_query, sizeof(select_query));
382 SAFE_STRLCAT(select_query, QUERY_KEYWORD_BRACKET, sizeof(select_query));
384 SAFE_FREE(condition_query);
385 SAFE_FREE(option_query);
387 ret = _content_query_prepare(&stmt, select_query, condition_query, option_query);
388 SAFE_FREE(condition_query);
389 SAFE_FREE(option_query);
390 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
392 while (sqlite3_step(stmt) == SQLITE_ROW)
393 *group_count = (int)sqlite3_column_int(stmt, 0);
395 SQLITE3_FINALIZE(stmt);
400 int _media_db_get_media_group(media_group_e group, filter_h filter, media_group_cb callback, void *user_data)
402 int ret = MEDIA_CONTENT_ERROR_NONE;
403 char select_query[MAX_QUERY_SIZE] = {0, };
404 char *condition_query = NULL;
405 char *option_query = NULL;
407 sqlite3_stmt *stmt = NULL;
408 attribute_h attr = NULL;
409 filter_s *_filter = (filter_s*)filter;
411 attr = _content_get_attirbute_handle();
412 memset(select_query, 0x00, sizeof(select_query));
413 #ifdef _USE_TV_PROFILE
414 if (group < MEDIA_PVR_GROUP_DURATION) { /*media content */
415 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
416 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_GROUP_LIST, __media_db_get_group_name(group), _filter->storage_id);
418 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_GROUP_LIST, __media_db_get_group_name(group), DB_TABLE_MEDIA_VIEW);
419 } else if (group < MEDIA_UHD_GROUP_CONTENT_TITLE) { /*pvr content */
420 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
421 snprintf(select_query, sizeof(select_query), SELECT_PVR_GROUP_LIST_BY_STORAGE_ID, __media_db_get_group_name(group), _filter->storage_id);
423 snprintf(select_query, sizeof(select_query), SELECT_PVR_GROUP_LIST, __media_db_get_group_name(group));
424 } else { /* uhd content */
425 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
426 snprintf(select_query, sizeof(select_query), SELECT_UHD_GROUP_LIST_BY_STORAGE_ID, __media_db_get_group_name(group), _filter->storage_id);
428 snprintf(select_query, sizeof(select_query), SELECT_UHD_GROUP_LIST, __media_db_get_group_name(group));
431 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
432 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_GROUP_LIST, __media_db_get_group_name(group), _filter->storage_id);
434 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_GROUP_LIST, __media_db_get_group_name(group), DB_TABLE_MEDIA_VIEW);
436 ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query);
437 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
439 ret = _content_query_prepare(&stmt, select_query, condition_query, option_query);
440 SAFE_FREE(condition_query);
441 SAFE_FREE(option_query);
442 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
444 while (sqlite3_step(stmt) == SQLITE_ROW) {
445 name = g_strdup((const char *)sqlite3_column_text(stmt, 0));
447 if (callback(name, user_data) == false) {
455 SQLITE3_FINALIZE(stmt);
459 #ifdef _USE_TV_PROFILE
460 int _media_db_get_media_group_and_count(media_group_e group, filter_h filter, media_group_and_count_cb callback, void *user_data)
462 int ret = MEDIA_CONTENT_ERROR_NONE;
463 char select_query[DEFAULT_QUERY_SIZE];
464 char group_query[DEFAULT_QUERY_SIZE];
465 char *condition_query = NULL;
466 char *option_query = NULL;
468 sqlite3_stmt *stmt = NULL;
469 attribute_h attr = NULL;
470 filter_s *_filter = (filter_s*)filter;
472 attr = _content_get_attirbute_handle();
473 memset(select_query, 0x00, sizeof(select_query));
474 memset(group_query, 0x00, sizeof(group_query));
476 char* group_name = __media_db_get_group_name(group);
477 if (!STRING_VALID(group_name)) {
478 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
479 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
482 if (group < MEDIA_PVR_GROUP_DURATION) { /*media content*/
483 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
484 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_GROUP_AND_COUNT, group_name, _filter->storage_id);
486 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_GROUP_AND_COUNT, group_name, DB_TABLE_MEDIA_VIEW);
487 } else if (group < MEDIA_UHD_GROUP_CONTENT_TITLE) {/*pvr content*/
488 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
489 snprintf(select_query, sizeof(select_query), SELECT_PVR_GROUP_AND_COUNT_BY_STORAGE_ID, group_name, _filter->storage_id);
491 snprintf(select_query, sizeof(select_query), SELECT_PVR_GROUP_AND_COUNT, group_name);
492 } else {/*uhd content*/
493 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
494 snprintf(select_query, sizeof(select_query), SELECT_UHD_GROUP_AND_COUNT_BY_STORAGE_ID, group_name, _filter->storage_id);
496 snprintf(select_query, sizeof(select_query), SELECT_UHD_GROUP_AND_COUNT, group_name);
499 ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query);
500 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
502 if (STRING_VALID(option_query))
503 snprintf(group_query, sizeof(group_query), "GROUP BY %s %s", group_name, option_query);
505 snprintf(group_query, sizeof(group_query), "GROUP BY %s", group_name);
507 ret = _content_query_prepare(&stmt, select_query, condition_query, group_query);
508 SAFE_FREE(condition_query);
509 SAFE_FREE(option_query);
510 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
512 while (sqlite3_step(stmt) == SQLITE_ROW) {
513 if (STRING_VALID((const char *)sqlite3_column_text(stmt, 0)))
514 name = strdup((const char *)sqlite3_column_text(stmt, 0));
516 if (callback(name, sqlite3_column_int(stmt, 1), user_data) == false) {
524 SQLITE3_FINALIZE(stmt);
529 int _media_db_get_album(filter_h filter, media_album_cb callback, void *user_data)
531 int ret = MEDIA_CONTENT_ERROR_NONE;
532 char select_query[MAX_QUERY_SIZE] = {0, };
533 char *condition_query = NULL;
534 char *option_query = NULL;
535 sqlite3_stmt *stmt = NULL;
536 attribute_h attr = NULL;
537 filter_s *_filter = (filter_s*)filter;
539 attr = _content_get_alias_attirbute_handle();
540 memset(select_query, 0x00, sizeof(select_query));
542 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
543 snprintf(select_query, sizeof(select_query), SELECT_ALBUM_LIST, _filter->storage_id);
545 snprintf(select_query, sizeof(select_query), SELECT_ALBUM_LIST, DB_TABLE_MEDIA_VIEW);
547 ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query);
548 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
550 ret = _content_query_prepare(&stmt, select_query, condition_query, option_query);
551 SAFE_FREE(condition_query);
552 SAFE_FREE(option_query);
553 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
555 while (sqlite3_step(stmt) == SQLITE_ROW) {
556 media_album_s *album = (media_album_s*)calloc(1, sizeof(media_album_s));
559 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
560 SQLITE3_FINALIZE(stmt);
561 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
564 album->album_id = (int)sqlite3_column_int(stmt, 0);
565 album->name = g_strdup((const char *)sqlite3_column_text(stmt, 1));
566 album->artist = g_strdup((const char *)sqlite3_column_text(stmt, 2));
567 album->album_art_path = g_strdup((const char *)sqlite3_column_text(stmt, 3));
569 if (callback((media_album_h)album, user_data) == false) {
570 media_album_destroy((media_album_h)album);
574 media_album_destroy((media_album_h)album);
577 SQLITE3_FINALIZE(stmt);
582 int _media_db_get_folder(filter_h filter, media_folder_cb callback, void *user_data)
584 int ret = MEDIA_CONTENT_ERROR_NONE;
585 char select_query[MAX_QUERY_SIZE] = {0, };
586 char *condition_query = NULL;
587 char *option_query = NULL;
588 sqlite3_stmt *stmt = NULL;
589 attribute_h attr = NULL;
590 filter_s *_filter = (filter_s*)filter;
591 char *tmp_path = NULL;
592 char repl_path[MAX_QUERY_SIZE] = {0, };
594 attr = _content_get_alias_attirbute_handle();
595 memset(select_query, 0x00, sizeof(select_query));
597 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
598 snprintf(select_query, sizeof(select_query), SELECT_FOLDER_LIST_BY_STORAGE_ID, _filter->storage_id, _filter->storage_id);
600 snprintf(select_query, sizeof(select_query), SELECT_FOLDER_LIST, DB_TABLE_MEDIA_VIEW);
602 ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query);
603 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
605 ret = _content_query_prepare(&stmt, select_query, condition_query, option_query);
607 SAFE_FREE(condition_query);
608 SAFE_FREE(option_query);
609 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
611 while (sqlite3_step(stmt) == SQLITE_ROW) {
612 media_folder_s *_folder = (media_folder_s*)calloc(1, sizeof(media_folder_s));
614 if (_folder == NULL) {
615 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
616 SQLITE3_FINALIZE(stmt);
617 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
620 _folder->folder_id = g_strdup((const char *)sqlite3_column_text(stmt, 0));
622 tmp_path = g_strdup((const char *)sqlite3_column_text(stmt, 1));
623 _media_content_rollback_path(tmp_path, repl_path);
624 _folder->path = g_strdup(repl_path);
627 _folder->name = g_strdup((const char *)sqlite3_column_text(stmt, 2));
628 _folder->storage_type = (int)sqlite3_column_int(stmt, 3);
629 _folder->modified_time = (int)sqlite3_column_int(stmt, 4);
630 _folder->storage_uuid = g_strdup((const char *)sqlite3_column_text(stmt, 5));
631 _folder->folder_order = (int)sqlite3_column_int(stmt, 6);
632 _folder->parent_folder_id = g_strdup((const char *)sqlite3_column_text(stmt, 7));
634 if (callback((media_folder_h)_folder, user_data) == false) {
635 media_folder_destroy((media_folder_h) _folder);
639 media_folder_destroy((media_folder_h) _folder);
642 SQLITE3_FINALIZE(stmt);
647 int _media_db_get_playlist(filter_h filter, media_playlist_cb callback, void *user_data)
649 int ret = MEDIA_CONTENT_ERROR_NONE;
650 char select_query[MAX_QUERY_SIZE] = {0, };
651 char *condition_query = NULL;
652 char *option_query = NULL;
653 sqlite3_stmt *stmt = NULL;
654 attribute_h attr = NULL;
655 char *tmp_path = NULL;
656 char repl_path[MAX_QUERY_SIZE] = {0, };
658 attr = _content_get_attirbute_handle();
659 memset(select_query, 0x00, sizeof(select_query));
661 if (!SAFE_STRLCPY(select_query, SELECT_PLAYLIST_LIST, sizeof(select_query))) {
662 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
663 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
666 ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query);
667 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
669 ret = _content_query_prepare(&stmt, select_query, condition_query, option_query);
670 SAFE_FREE(condition_query);
671 SAFE_FREE(option_query);
672 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
674 while (sqlite3_step(stmt) == SQLITE_ROW) {
675 media_playlist_s *_playlist = (media_playlist_s*)calloc(1, sizeof(media_playlist_s));
677 if (_playlist == NULL) {
678 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
679 SQLITE3_FINALIZE(stmt);
680 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
683 _playlist->playlist_id = (int)sqlite3_column_int(stmt, 0);
684 _playlist->name = g_strdup((const char *)sqlite3_column_text(stmt, 1));
686 memset(repl_path, 0x00, sizeof(repl_path));
687 tmp_path = g_strdup((const char *)sqlite3_column_text(stmt, 2));
688 if (STRING_VALID(tmp_path)) {
689 _media_content_rollback_path(tmp_path, repl_path);
690 _playlist->thumbnail_path = g_strdup(repl_path);
693 _playlist->thumbnail_path = NULL;
696 if (callback((media_playlist_h)_playlist, user_data) == false) {
697 media_playlist_destroy((media_playlist_h)_playlist);
700 media_playlist_destroy((media_playlist_h)_playlist);
703 SQLITE3_FINALIZE(stmt);
708 int _media_db_get_playlist_item(int playlist_id, filter_h filter, playlist_member_cb callback, void *user_data)
710 int ret = MEDIA_CONTENT_ERROR_NONE;
711 char select_query[MAX_QUERY_SIZE] = {0, };
712 char *condition_query = NULL;
713 char *option_query = NULL;
714 sqlite3_stmt *stmt = NULL;
715 attribute_h attr = NULL;
717 attr = _content_get_attirbute_handle();
718 memset(select_query, 0x00, sizeof(select_query));
720 /*snprintf(select_query, sizeof(select_query), SELECT_PLAYLIST_ITEM_ID_FROM_PLAYLIST_VIEW, playlist_id);*/
721 snprintf(select_query, sizeof(select_query), SELECT_PLAYLIST_ITEM_ALL_FROM_PLAYLIST_VIEW, playlist_id);
723 ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query);
724 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
726 ret = _content_query_prepare(&stmt, select_query, condition_query, option_query);
727 SAFE_FREE(condition_query);
728 SAFE_FREE(option_query);
729 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
731 while (sqlite3_step(stmt) == SQLITE_ROW) {
732 int playlist_member_id = 0;
733 playlist_member_id = (int)sqlite3_column_int(stmt, MEDIA_INFO_ITEM_MAX); /*MEDIA_INFO_ITEM_MAX is pm_id*/
735 media_info_s *_media = (media_info_s*)calloc(1, sizeof(media_info_s));
737 if (_media == NULL) {
738 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
739 SQLITE3_FINALIZE(stmt);
740 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
743 _media_info_item_get_detail(stmt, (media_info_h)_media);
745 if (callback(playlist_member_id, (media_info_h)_media, user_data) == false) {
746 media_info_destroy((media_info_h)_media);
749 media_info_destroy((media_info_h)_media);
753 SQLITE3_FINALIZE(stmt);
758 int _media_db_get_tag(const char *media_id, filter_h filter, media_tag_cb callback, void *user_data)
760 int ret = MEDIA_CONTENT_ERROR_NONE;
761 char select_query[MAX_QUERY_SIZE] = {0, };
762 char *condition_query = NULL;
763 char *option_query = NULL;
764 sqlite3_stmt *stmt = NULL;
765 attribute_h attr = NULL;
767 attr = _content_get_attirbute_handle();
768 memset(select_query, 0x00, sizeof(select_query));
770 if (!STRING_VALID(media_id)) {
771 if (!SAFE_STRLCPY(select_query, SELECT_TAG_LIST, sizeof(select_query))) {
772 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
773 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
776 snprintf(select_query, sizeof(select_query), SELECT_TAG_LIST_BY_MEDIA_ID, media_id);
778 ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query);
779 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
781 SAFE_STRLCAT(select_query, QUERY_KEYWORD_SPACE, sizeof(select_query));
783 ret = _content_query_prepare(&stmt, select_query, condition_query, option_query);
784 SAFE_FREE(condition_query);
785 SAFE_FREE(option_query);
786 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
788 while (sqlite3_step(stmt) == SQLITE_ROW) {
789 media_tag_s *_tag = (media_tag_s*)calloc(1, sizeof(media_tag_s));
792 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
793 SQLITE3_FINALIZE(stmt);
794 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
797 _tag->tag_id = (int)sqlite3_column_int(stmt, 0);
798 _tag->name = g_strdup((const char *)sqlite3_column_text(stmt, 1));
800 if (callback((media_tag_h)_tag, user_data) == false) {
801 media_tag_destroy((media_tag_h)_tag);
804 media_tag_destroy((media_tag_h)_tag);
807 SQLITE3_FINALIZE(stmt);
812 int _media_db_get_bookmark(const char *media_id, filter_h filter, media_bookmark_cb callback, void *user_data)
814 int ret = MEDIA_CONTENT_ERROR_NONE;
815 char select_query[MAX_QUERY_SIZE] = {0, };
816 char *condition_query = NULL;
817 char *option_query = NULL;
818 sqlite3_stmt *stmt = NULL;
819 attribute_h attr = NULL;
820 filter_s *_filter = (filter_s*)filter;
822 attr = _content_get_attirbute_handle();
824 memset(select_query, 0x00, sizeof(select_query));
826 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
827 snprintf(select_query, sizeof(select_query), SELECT_BOOKMARK_LIST_BY_MEDIA_ID, _filter->storage_id, media_id);
829 snprintf(select_query, sizeof(select_query), SELECT_BOOKMARK_LIST_BY_MEDIA_ID, DB_TABLE_MEDIA_VIEW, media_id);
831 ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query);
832 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
834 ret = _content_query_prepare(&stmt, select_query, condition_query, option_query);
835 SAFE_FREE(condition_query);
836 SAFE_FREE(option_query);
837 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
839 while (sqlite3_step(stmt) == SQLITE_ROW) {
840 media_bookmark_s *bookmark = (media_bookmark_s*)calloc(1, sizeof(media_bookmark_s));
842 if (bookmark == NULL) {
843 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
844 SQLITE3_FINALIZE(stmt);
845 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
848 bookmark->bookmark_id = (int)sqlite3_column_int(stmt, 0);
849 bookmark->media_id = g_strdup((const char *)sqlite3_column_text(stmt, 1));
850 bookmark->marked_time = (int)sqlite3_column_int(stmt, 2);
851 bookmark->thumbnail_path = g_strdup((const char *)sqlite3_column_text(stmt, 3));
852 bookmark->name = g_strdup((const char *)sqlite3_column_text(stmt, 4));
854 if (callback((media_bookmark_h)bookmark, user_data) == false) {
855 media_bookmark_destroy((media_bookmark_h)bookmark);
859 media_bookmark_destroy((media_bookmark_h)bookmark);
862 SQLITE3_FINALIZE(stmt);
868 int _media_db_get_face(const char *media_id, filter_h filter, media_face_cb callback, void *user_data)
870 int ret = MEDIA_CONTENT_ERROR_NONE;
871 char select_query[MAX_QUERY_SIZE] = {0, };
872 char *condition_query = NULL;
873 char *option_query = NULL;
874 sqlite3_stmt *stmt = NULL;
875 attribute_h attr = NULL;
876 filter_s *_filter = (filter_s*)filter;
878 attr = _content_get_attirbute_handle();
880 memset(select_query, 0x00, sizeof(select_query));
882 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
883 snprintf(select_query, sizeof(select_query), SELECT_FACE_LIST_BY_MEDIA_ID, _filter->storage_id, media_id);
885 snprintf(select_query, sizeof(select_query), SELECT_FACE_LIST_BY_MEDIA_ID, DB_TABLE_MEDIA_VIEW, media_id);
887 ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query);
888 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
890 ret = _content_query_prepare(&stmt, select_query, condition_query, option_query);
891 SAFE_FREE(condition_query);
892 SAFE_FREE(option_query);
893 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
895 while (sqlite3_step(stmt) == SQLITE_ROW) {
896 media_face_s *face = (media_face_s*)calloc(1, sizeof(media_face_s));
899 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
900 SQLITE3_FINALIZE(stmt);
901 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
904 face->face_id = g_strdup((const char *)sqlite3_column_text(stmt, 0));
905 face->media_id = g_strdup((const char *)sqlite3_column_text(stmt, 1));
906 face->face_rect_x = (int)sqlite3_column_int(stmt, 2);
907 face->face_rect_y = (int)sqlite3_column_int(stmt, 3);
908 face->face_rect_w = (int)sqlite3_column_int(stmt, 4);
909 face->face_rect_h = (int)sqlite3_column_int(stmt, 5);
910 face->orientation = (int)sqlite3_column_int(stmt, 6);
911 face->face_tag = g_strdup((const char *)sqlite3_column_text(stmt, 7));
913 if (callback((media_face_h)face, user_data) == false) {
914 media_face_destroy((media_face_h)face);
918 media_face_destroy((media_face_h)face);
921 SQLITE3_FINALIZE(stmt);
927 int _media_db_get_group_item_count_by_id(int group_id, filter_h filter, group_list_e group_type, int *item_count)
929 int ret = MEDIA_CONTENT_ERROR_NONE;
930 sqlite3_stmt *stmt = NULL;
931 char select_query[MAX_QUERY_SIZE] = {0, };
932 char *condition_query = NULL;
933 char *option_query = NULL;
934 attribute_h attr = NULL;
935 filter_s *_filter = (filter_s*)filter;
937 attr = _content_get_attirbute_handle();
938 memset(select_query, 0x00, sizeof(select_query));
940 if (group_type == MEDIA_GROUP_ALBUM) {
941 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
942 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_COUNT_FROM_ALBUM, _filter->storage_id, group_id);
944 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_COUNT_FROM_ALBUM, DB_TABLE_MEDIA_VIEW, group_id);
945 } else if (group_type == MEDIA_GROUP_PLAYLIST) {
946 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_COUNT_FROM_PLAYLIST, group_id);
947 } else if (group_type == MEDIA_GROUP_TAG) {
948 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_COUNT_FROM_TAG, group_id);
950 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
951 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
954 ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query);
955 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
957 ret = _content_query_prepare(&stmt, select_query, condition_query, option_query);
958 SAFE_FREE(condition_query);
959 SAFE_FREE(option_query);
960 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
962 while (sqlite3_step(stmt) == SQLITE_ROW)
963 *item_count = (int)sqlite3_column_int(stmt, 0);
965 SQLITE3_FINALIZE(stmt);
970 int _media_db_get_group_item_count(const char *group_name, filter_h filter, group_list_e group_type, int *item_count)
972 int ret = MEDIA_CONTENT_ERROR_NONE;
973 sqlite3_stmt *stmt = NULL;
974 char select_query[MAX_QUERY_SIZE] = {0, };
975 char *tmp_query = NULL;
976 char *condition_query = NULL;
977 char *option_query = NULL;
978 bool is_simple = FALSE;
979 attribute_h attr = NULL;
980 filter_s *_filter = (filter_s*)filter;
982 attr = _content_get_attirbute_handle();
983 memset(select_query, 0x00, sizeof(select_query));
985 if (group_type == MEDIA_GROUP_NONE) {
986 /* There are 2 ways to get count for media table for performance
987 If user wants to set offset and count, use SQL SELECT_MEDIA_COUNT_FROM_MEDIA.
988 If user wants to get count without setting count, SELECT_MEDIA_COUNT_FROM_MEDIA_SIMPLE */
989 if (_filter && ((_filter->offset < 0) && (_filter->count < 0))) {
990 if (STRING_VALID(_filter->storage_id))
991 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_COUNT_FROM_MEDIA_SIMPLE, _filter->storage_id);
993 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_COUNT_FROM_MEDIA_SIMPLE, DB_TABLE_MEDIA_VIEW);
996 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_COUNT_FROM_MEDIA, DB_TABLE_MEDIA_VIEW);
998 } else if (group_type == MEDIA_GROUP_FOLDER) {
999 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
1000 tmp_query = sqlite3_mprintf(SELECT_MEDIA_COUNT_FROM_FOLDER, _filter->storage_id, group_name);
1002 tmp_query = sqlite3_mprintf(SELECT_MEDIA_COUNT_FROM_FOLDER, DB_TABLE_MEDIA_VIEW, group_name);
1004 SAFE_STRLCAT(select_query, tmp_query, sizeof(select_query));
1005 } else if (group_type == MEDIA_GROUP_TAG_BY_MEDIA_ID) {
1006 snprintf(select_query, sizeof(select_query), SELECT_TAG_COUNT_BY_MEDIA_ID, group_name);
1007 } else if (group_type == MEDIA_GROUP_BOOKMARK_BY_MEDIA_ID) {
1008 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
1009 tmp_query = sqlite3_mprintf(SELECT_BOOKMARK_COUNT_BY_MEDIA_ID, _filter->storage_id, group_name);
1011 tmp_query = sqlite3_mprintf(SELECT_BOOKMARK_COUNT_BY_MEDIA_ID, DB_TABLE_MEDIA_VIEW, group_name);
1013 SAFE_STRLCAT(select_query, tmp_query, sizeof(select_query));
1014 } else if (group_type == MEDIA_GROUP_STORAGE) {
1015 tmp_query = sqlite3_mprintf(SELECT_MEDIA_COUNT_FROM_STORAGE, group_name, group_name);
1017 SAFE_STRLCAT(select_query, tmp_query, sizeof(select_query));
1018 } else if (group_type == MEDIA_GROUP_FACE_BY_MEDIA_ID) {
1019 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
1020 tmp_query = sqlite3_mprintf(SELECT_FACE_COUNT_BY_MEDIA_ID, _filter->storage_id, group_name);
1022 tmp_query = sqlite3_mprintf(SELECT_FACE_COUNT_BY_MEDIA_ID, DB_TABLE_MEDIA_VIEW, group_name);
1024 SAFE_STRLCAT(select_query, tmp_query, sizeof(select_query));
1025 #ifdef _USE_TV_PROFILE
1026 } else if (group_type == MEDIA_GROUP_PVR) {
1027 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
1028 snprintf(select_query, sizeof(select_query), SELECT_PVR_COUNT_BY_STORAGE_ID, _filter->storage_id);
1030 SAFE_STRLCAT(select_query, SELECT_PVR_COUNT, sizeof(select_query));
1031 } else if (group_type == MEDIA_GROUP_UHD) {
1032 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
1033 snprintf(select_query, sizeof(select_query), SELECT_UHD_COUNT_BY_STORAGE_ID, _filter->storage_id);
1035 SAFE_STRLCAT(select_query, SELECT_UHD_COUNT, sizeof(select_query));
1038 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1039 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1042 ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query);
1043 if (ret != MEDIA_CONTENT_ERROR_NONE) {
1044 if (tmp_query != NULL)
1045 SQLITE3_SAFE_FREE(tmp_query);
1049 if (group_type == MEDIA_GROUP_NONE) {
1050 SAFE_STRLCAT(select_query, QUERY_KEYWORD_SPACE, sizeof(select_query));
1051 if (STRING_VALID(condition_query))
1052 SAFE_STRLCAT(select_query, condition_query, sizeof(select_query));
1053 if (STRING_VALID(option_query))
1054 SAFE_STRLCAT(select_query, option_query, sizeof(select_query));
1057 SAFE_STRLCAT(select_query, QUERY_KEYWORD_BRACKET, sizeof(select_query));
1059 SAFE_FREE(condition_query);
1060 SAFE_FREE(option_query);
1063 ret = _content_query_prepare(&stmt, select_query, condition_query, option_query);
1064 if (tmp_query != NULL)
1065 SQLITE3_SAFE_FREE(tmp_query);
1066 SAFE_FREE(condition_query);
1067 SAFE_FREE(option_query);
1068 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
1070 while (sqlite3_step(stmt) == SQLITE_ROW)
1071 *item_count = (int)sqlite3_column_int(stmt, 0);
1073 SQLITE3_FINALIZE(stmt);
1078 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)
1080 int ret = MEDIA_CONTENT_ERROR_NONE;
1081 char select_query[MAX_QUERY_SIZE] = {0, };
1082 char *condition_query = NULL;
1083 char *option_query = NULL;
1084 sqlite3_stmt *stmt = NULL;
1085 attribute_h attr = NULL;
1086 filter_s *_filter = (filter_s*)filter;
1088 attr = _content_get_attirbute_handle();
1089 memset(select_query, 0x00, sizeof(select_query));
1091 if (group_type == MEDIA_GROUP_ALBUM) {
1092 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
1093 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_ALBUM, _filter->storage_id, group_id);
1095 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_ALBUM, DB_TABLE_MEDIA_VIEW, group_id);
1096 } else if (group_type == MEDIA_GROUP_PLAYLIST) {
1097 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
1098 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_PLAYLIST, _filter->storage_id, group_id);
1100 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_PLAYLIST, DB_TABLE_MEDIA_VIEW, group_id);
1101 } else if (group_type == MEDIA_GROUP_TAG) {
1102 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
1103 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_TAG, _filter->storage_id, group_id);
1105 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_TAG, DB_TABLE_MEDIA_VIEW, group_id);
1107 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1108 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1111 ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query);
1112 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
1114 ret = _content_query_prepare(&stmt, select_query, condition_query, option_query);
1115 SAFE_FREE(condition_query);
1116 SAFE_FREE(option_query);
1117 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
1119 while (sqlite3_step(stmt) == SQLITE_ROW) {
1120 media_info_s *item = (media_info_s*)calloc(1, sizeof(media_info_s));
1122 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1123 SQLITE3_FINALIZE(stmt);
1124 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1127 _media_info_item_get_detail(stmt, (media_info_h)item);
1129 if (callback((media_info_h)item, user_data) == false) {
1130 media_info_destroy((media_info_h)item);
1134 media_info_destroy((media_info_h)item);
1137 SQLITE3_FINALIZE(stmt);
1142 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)
1144 int ret = MEDIA_CONTENT_ERROR_NONE;
1145 char select_query[MAX_QUERY_SIZE] = {0, };
1146 char *condition_query = NULL;
1147 char *option_query = NULL;
1148 sqlite3_stmt *stmt = NULL;
1149 attribute_h attr = NULL;
1150 filter_s *_filter = (filter_s*)filter;
1152 attr = _content_get_attirbute_handle();
1153 memset(select_query, 0x00, sizeof(select_query));
1155 if (group_type == MEDIA_GROUP_NONE) {
1156 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
1157 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_ITEM, _filter->storage_id);
1159 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_ITEM, DB_TABLE_MEDIA_VIEW);
1160 } else if (group_type == MEDIA_GROUP_FOLDER) {
1161 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
1162 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_FOLDER, _filter->storage_id, group_name);
1164 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_FOLDER, DB_TABLE_MEDIA_VIEW, group_name);
1165 } else if (group_type == MEDIA_GROUP_STORAGE) {
1166 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_STORAGE, group_name, group_name);
1168 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1169 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1172 ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query);
1173 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
1175 ret = _content_query_prepare(&stmt, select_query, condition_query, option_query);
1176 SAFE_FREE(condition_query);
1177 SAFE_FREE(option_query);
1178 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
1180 while (sqlite3_step(stmt) == SQLITE_ROW) {
1181 media_info_s *item = (media_info_s*)calloc(1, sizeof(media_info_s));
1183 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1184 SQLITE3_FINALIZE(stmt);
1185 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1188 _media_info_item_get_detail(stmt, (media_info_h)item);
1190 if (callback((media_info_h)item, user_data) == false) {
1191 media_info_destroy((media_info_h)item);
1195 media_info_destroy((media_info_h)item);
1198 SQLITE3_FINALIZE(stmt);
1203 #ifdef _USE_SENIOR_MODE
1204 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)
1206 int ret = MEDIA_CONTENT_ERROR_NONE;
1207 char select_query1[MAX_QUERY_SIZE] = {0, };
1208 char *condition_query1 = NULL;
1209 char *option_query1 = NULL;
1210 char select_query2[MAX_QUERY_SIZE] = {0, };
1211 char *condition_query2 = NULL;
1212 char *option_query2 = NULL;
1213 sqlite3_stmt *stmt = NULL;
1214 attribute_h attr = NULL;
1215 filter_s *_filter1 = (filter_s*)filter1;
1216 filter_s *_filter2 = (filter_s*)filter2;
1218 attr = _content_get_attirbute_handle();
1220 memset(select_query1, 0x00, sizeof(select_query1));
1222 if ((_filter1 != NULL) && STRING_VALID(_filter1->storage_id))
1223 snprintf(select_query1, sizeof(select_query1), SELECT_MEDIA_FROM_FOLDER, _filter1->storage_id, group_name);
1225 snprintf(select_query1, sizeof(select_query1), SELECT_MEDIA_FROM_FOLDER, DB_TABLE_MEDIA_VIEW, group_name);
1227 ret = __media_db_make_query(filter1, attr, select_query1, sizeof(select_query1), &condition_query1, &option_query1);
1228 if (ret != MEDIA_CONTENT_ERROR_NONE) {
1229 SAFE_FREE(condition_query1);
1230 SAFE_FREE(option_query1);
1231 media_content_error("create select_query1 failed");
1235 memset(select_query2, 0x00, sizeof(select_query2));
1237 if ((_filter2 != NULL) && STRING_VALID(_filter2->storage_id))
1238 snprintf(select_query2, sizeof(select_query2), SELECT_MEDIA_FROM_FOLDER, _filter2->storage_id, group_name);
1240 snprintf(select_query2, sizeof(select_query2), SELECT_MEDIA_FROM_FOLDER, DB_TABLE_MEDIA_VIEW, group_name);
1242 ret = __media_db_make_query(filter2, attr, select_query2, sizeof(select_query2), &condition_query2, &option_query2);
1243 if (ret != MEDIA_CONTENT_ERROR_NONE) {
1244 SAFE_FREE(condition_query1);
1245 SAFE_FREE(option_query1);
1246 SAFE_FREE(condition_query2);
1247 SAFE_FREE(option_query2);
1248 media_content_error("create select_query2 failed");
1252 ret = _content_query_prepare_by_union_select(&stmt, select_query1, condition_query1, option_query1, select_query2, condition_query2, option_query2);
1253 SAFE_FREE(condition_query1);
1254 SAFE_FREE(option_query1);
1255 SAFE_FREE(condition_query2);
1256 SAFE_FREE(option_query2);
1257 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
1259 while (sqlite3_step(stmt) == SQLITE_ROW) {
1260 media_info_s *item = (media_info_s*)calloc(1, sizeof(media_info_s));
1262 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1263 SQLITE3_FINALIZE(stmt);
1264 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1267 _media_info_item_get_detail(stmt, (media_info_h)item);
1269 if (callback((media_info_h)item, user_data) == false) {
1270 media_info_destroy((media_info_h)item);
1274 media_info_destroy((media_info_h)item);
1277 SQLITE3_FINALIZE(stmt);
1283 int _media_db_get_media_group_item_count(const char *group_name, filter_h filter, media_group_e group, int *item_count)
1285 int ret = MEDIA_CONTENT_ERROR_NONE;
1286 sqlite3_stmt *stmt = NULL;
1287 char select_query[MAX_QUERY_SIZE] = {0, };
1288 char *tmp_query = NULL;
1289 char *condition_query = NULL;
1290 char *option_query = NULL;
1291 attribute_h attr = NULL;
1292 filter_s *_filter = (filter_s*)filter;
1294 attr = _content_get_attirbute_handle();
1295 memset(select_query, 0x00, sizeof(select_query));
1296 #ifdef _USE_TV_PROFILE
1297 if (group < MEDIA_PVR_GROUP_DURATION) { /*media content */
1298 if (group_name != NULL) {
1299 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
1300 tmp_query = sqlite3_mprintf(SELECT_MEDIA_COUNT_FROM_GROUP, _filter->storage_id, __media_db_get_group_name(group), group_name);
1302 tmp_query = sqlite3_mprintf(SELECT_MEDIA_COUNT_FROM_GROUP, DB_TABLE_MEDIA_VIEW, __media_db_get_group_name(group), group_name);
1304 SAFE_STRLCAT(select_query, tmp_query, sizeof(select_query));
1306 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
1307 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_COUNT_FROM_GROUP_NULL, _filter->storage_id, __media_db_get_group_name(group));
1309 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_COUNT_FROM_GROUP_NULL, DB_TABLE_MEDIA_VIEW, __media_db_get_group_name(group));
1311 } else if (group < MEDIA_UHD_GROUP_CONTENT_TITLE) {/*pvr content*/
1312 if (group_name != NULL) {
1313 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
1314 tmp_query = sqlite3_mprintf(SELECT_PVR_COUNT_FROM_GROUP_BY_STORAGE_ID, _filter->storage_id, __media_db_get_group_name(group), group_name);
1316 tmp_query = sqlite3_mprintf(SELECT_PVR_COUNT_FROM_GROUP, __media_db_get_group_name(group), group_name);
1318 SAFE_STRLCAT(select_query, tmp_query, sizeof(select_query));
1320 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
1321 snprintf(select_query, sizeof(select_query), SELECT_PVR_COUNT_FROM_GROUP_NULL_BY_STORAGE_ID, _filter->storage_id, __media_db_get_group_name(group));
1323 snprintf(select_query, sizeof(select_query), SELECT_PVR_COUNT_FROM_GROUP_NULL, __media_db_get_group_name(group));
1325 } else {/*uhd content*/
1326 if (group_name != NULL) {
1327 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
1328 tmp_query = sqlite3_mprintf(SELECT_UHD_COUNT_FROM_GROUP_BY_STORAGE_ID, _filter->storage_id, __media_db_get_group_name(group), group_name);
1330 tmp_query = sqlite3_mprintf(SELECT_UHD_COUNT_FROM_GROUP, __media_db_get_group_name(group), group_name);
1332 SAFE_STRLCAT(select_query, tmp_query, sizeof(select_query));
1334 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
1335 snprintf(select_query, sizeof(select_query), SELECT_UHD_COUNT_FROM_GROUP_NULL_BY_STORAGE_ID, _filter->storage_id, __media_db_get_group_name(group));
1337 snprintf(select_query, sizeof(select_query), SELECT_UHD_COUNT_FROM_GROUP_NULL, __media_db_get_group_name(group));
1341 if (group_name != NULL) {
1342 if ((_filter != NULL) && STRING_VALID(_filter->storage_id)) {
1343 tmp_query = sqlite3_mprintf(SELECT_MEDIA_COUNT_FROM_GROUP, _filter->storage_id, __media_db_get_group_name(group), group_name);
1344 SAFE_STRLCAT(select_query, tmp_query, sizeof(select_query));
1346 tmp_query = sqlite3_mprintf(SELECT_MEDIA_COUNT_FROM_GROUP, DB_TABLE_MEDIA_VIEW, __media_db_get_group_name(group), group_name);
1347 SAFE_STRLCAT(select_query, tmp_query, sizeof(select_query));
1350 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
1351 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_COUNT_FROM_GROUP_NULL, _filter->storage_id, __media_db_get_group_name(group));
1353 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_COUNT_FROM_GROUP_NULL, DB_TABLE_MEDIA_VIEW, __media_db_get_group_name(group));
1356 ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query);
1357 if (ret != MEDIA_CONTENT_ERROR_NONE) {
1358 if (tmp_query != NULL)
1359 SQLITE3_SAFE_FREE(tmp_query);
1363 SAFE_STRLCAT(select_query, QUERY_KEYWORD_SPACE, sizeof(select_query));
1364 if (STRING_VALID(condition_query))
1365 SAFE_STRLCAT(select_query, condition_query, sizeof(select_query));
1366 if (STRING_VALID(option_query))
1367 SAFE_STRLCAT(select_query, option_query, sizeof(select_query));
1368 SAFE_STRLCAT(select_query, QUERY_KEYWORD_BRACKET, sizeof(select_query));
1370 SAFE_FREE(condition_query);
1371 SAFE_FREE(option_query);
1373 ret = _content_query_prepare(&stmt, select_query, condition_query, option_query);
1374 if (tmp_query != NULL)
1375 SQLITE3_SAFE_FREE(tmp_query);
1376 SAFE_FREE(condition_query);
1377 SAFE_FREE(option_query);
1378 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
1380 while (sqlite3_step(stmt) == SQLITE_ROW)
1381 *item_count = (int)sqlite3_column_int(stmt, 0);
1383 SQLITE3_FINALIZE(stmt);
1388 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)
1390 int ret = MEDIA_CONTENT_ERROR_NONE;
1391 char select_query[MAX_QUERY_SIZE] = {0, };
1392 char *tmp_query = NULL;
1393 char *condition_query = NULL;
1394 char *option_query = NULL;
1395 sqlite3_stmt *stmt = NULL;
1396 attribute_h attr = NULL;
1397 filter_s *_filter = (filter_s*)filter;
1399 attr = _content_get_attirbute_handle();
1400 memset(select_query, 0x00, sizeof(select_query));
1402 if (group_name != NULL) {
1403 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
1404 tmp_query = sqlite3_mprintf(SELECT_MEDIA_FROM_GROUP, _filter->storage_id, __media_db_get_group_name(group), group_name);
1406 tmp_query = sqlite3_mprintf(SELECT_MEDIA_FROM_GROUP, DB_TABLE_MEDIA_VIEW, __media_db_get_group_name(group), group_name);
1408 SAFE_STRLCAT(select_query, tmp_query, sizeof(select_query));
1410 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
1411 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_GROUP_NULL, _filter->storage_id, __media_db_get_group_name(group));
1413 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_GROUP_NULL, DB_TABLE_MEDIA_VIEW, __media_db_get_group_name(group));
1416 ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query);
1417 if (ret != MEDIA_CONTENT_ERROR_NONE) {
1418 if (tmp_query != NULL)
1419 SQLITE3_SAFE_FREE(tmp_query);
1423 ret = _content_query_prepare(&stmt, select_query, condition_query, option_query);
1424 if (tmp_query != NULL)
1425 SQLITE3_SAFE_FREE(tmp_query);
1426 SAFE_FREE(condition_query);
1427 SAFE_FREE(option_query);
1428 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
1430 while (sqlite3_step(stmt) == SQLITE_ROW) {
1431 media_info_s *item = (media_info_s*)calloc(1, sizeof(media_info_s));
1433 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1434 SQLITE3_FINALIZE(stmt);
1435 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1438 _media_info_item_get_detail(stmt, (media_info_h)item);
1440 if (callback((media_info_h)item, user_data) == false) {
1441 media_info_destroy((media_info_h)item);
1445 media_info_destroy((media_info_h)item);
1448 SQLITE3_FINALIZE(stmt);
1453 int _media_db_get_storage(filter_h filter, media_storage_cb callback, void *user_data)
1455 int ret = MEDIA_CONTENT_ERROR_NONE;
1456 char select_query[DEFAULT_QUERY_SIZE];
1457 char *condition_query = NULL;
1458 char *option_query = NULL;
1459 sqlite3_stmt *stmt = NULL;
1460 attribute_h attr = NULL;
1462 attr = _content_get_attirbute_handle();
1463 memset(select_query, 0x00, sizeof(select_query));
1465 if (!SAFE_STRLCPY(select_query, SELECT_STORAGE_LIST, sizeof(select_query))) {
1466 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1467 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1470 ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query);
1471 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
1473 ret = _content_query_prepare(&stmt, select_query, condition_query, option_query);
1474 SAFE_FREE(condition_query);
1475 SAFE_FREE(option_query);
1476 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
1478 while (sqlite3_step(stmt) == SQLITE_ROW) {
1479 media_storage_s *_storage = (media_storage_s*)calloc(1, sizeof(media_storage_s));
1481 if (_storage == NULL) {
1482 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1483 SQLITE3_FINALIZE(stmt);
1484 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1487 _storage->storage_id = g_strdup((const char *)sqlite3_column_text(stmt, 0));
1488 _storage->storage_name = g_strdup((const char *)sqlite3_column_text(stmt, 1));
1489 _storage->storage_path = g_strdup((const char *)sqlite3_column_text(stmt, 2));
1490 _storage->storage_account = g_strdup((const char *)sqlite3_column_text(stmt, 3));
1491 _storage->storage_type = (int)sqlite3_column_int(stmt, 4);
1493 if (callback((media_storage_h)_storage, user_data) == false) {
1494 media_storage_destroy((media_storage_h) _storage);
1498 media_storage_destroy((media_storage_h) _storage);
1501 SQLITE3_FINALIZE(stmt);
1505 #ifdef _USE_TV_PROFILE
1506 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)
1508 int ret = MEDIA_CONTENT_ERROR_NONE;
1509 char select_query[DEFAULT_QUERY_SIZE];
1510 char *tmp_query = NULL;
1511 char *condition_query = NULL;
1512 char *option_query = NULL;
1513 sqlite3_stmt *stmt = NULL;
1514 attribute_h attr = NULL;
1515 filter_s *_filter = (filter_s*)filter;
1517 attr = _content_get_attirbute_handle();
1518 memset(select_query, 0x00, sizeof(select_query));
1520 if (group_name != NULL) {
1521 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
1522 tmp_query = sqlite3_mprintf(SELECT_PVR_FROM_GROUP_BY_STORAGE_ID, _filter->storage_id, __media_db_get_group_name(group), group_name);
1524 tmp_query = sqlite3_mprintf(SELECT_PVR_FROM_GROUP, __media_db_get_group_name(group), group_name);
1526 SAFE_STRLCAT(select_query, tmp_query, sizeof(select_query));
1528 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
1529 snprintf(select_query, sizeof(select_query), SELECT_PVR_FROM_GROUP_NULL_BY_STORAGE_ID, _filter->storage_id, __media_db_get_group_name(group));
1531 snprintf(select_query, sizeof(select_query), SELECT_PVR_FROM_GROUP_NULL, __media_db_get_group_name(group));
1534 ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query);
1535 if (ret != MEDIA_CONTENT_ERROR_NONE) {
1536 if (tmp_query != NULL)
1537 sqlite3_free(tmp_query);
1541 ret = _content_query_prepare(&stmt, select_query, condition_query, option_query);
1542 if (tmp_query != NULL)
1543 sqlite3_free(tmp_query);
1544 SAFE_FREE(condition_query);
1545 SAFE_FREE(option_query);
1546 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
1548 while (sqlite3_step(stmt) == SQLITE_ROW) {
1549 media_pvr_s *item = (media_pvr_s*)calloc(1, sizeof(media_pvr_s));
1551 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1552 SQLITE3_FINALIZE(stmt);
1553 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1556 _media_pvr_item_get_detail(stmt, (media_pvr_h)item);
1558 if (callback((media_pvr_h)item, user_data) == false) {
1559 media_info_destroy((media_pvr_h)item);
1563 media_pvr_destroy((media_pvr_h)item);
1566 SQLITE3_FINALIZE(stmt);
1572 MEDIA_PVR_MEDIA_ID = 0,
1573 MEDIA_PVR_STORAGE_ID,
1577 MEDIA_PVR_TIME_ZONE,
1581 MEDIA_PVR_CHANNEL_TYPE,
1582 MEDIA_PVR_CHANNEL_NAME,
1583 MEDIA_PVR_CHANNEL_NUM,
1584 MEDIA_PVR_PROGRAM_TITLE,
1585 MEDIA_PVR_PROGRAM_NUM,
1586 MEDIA_PVR_PROGRAM_CRID,
1591 MEDIA_PVR_EMBARGO_TIME,
1592 MEDIA_PVR_EXPIRY_TIME,
1593 MEDIA_PVR_START_TIME,
1594 MEDIA_PVR_PROGRAM_START_TIME,
1595 MEDIA_PVR_PROGRAM_END_TIME,
1596 MEDIA_PVR_PROGRAM_DATE,
1597 MEDIA_PVR_PARENTAL_RATING,
1598 MEDIA_PVR_TIMER_RECORD,
1599 MEDIA_PVR_SERIES_RECORD,
1604 MEDIA_PVR_HARDOF_HEARINGRADIO,
1605 MEDIA_PVR_DATA_SERVICE,
1606 MEDIA_PVR_CONTENT_LOCK,
1607 MEDIA_PVR_CONTENT_WATCH,
1608 MEDIA_PVR_HAS_AUDIO_ONLY,
1609 MEDIA_PVR_IS_LOCAL_RECORDED,
1610 MEDIA_PVR_RESOLUTION,
1611 MEDIA_PVR_ASPECTRATIO,
1612 MEDIA_PVR_MODIFIED_MONTH,
1613 MEDIA_PVR_SPORTS_TYPE,
1614 MEDIA_PVR_GUIDANCE_LENGTH,
1616 MEDIA_PVR_PLAY_COUNT,
1617 MEDIA_PVR_PRIVATE_DATA,
1618 MEDIA_PVR_HIGHLIGHT,
1619 } media_pvr_field_e;
1621 void _media_pvr_item_get_detail(sqlite3_stmt* stmt, media_pvr_h pvr)
1623 media_pvr_s *_pvr = (media_pvr_s*)pvr;
1625 if (STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_PVR_MEDIA_ID)))
1626 _pvr->media_id = strdup((const char *)sqlite3_column_text(stmt, MEDIA_PVR_MEDIA_ID));
1628 if (STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_PVR_STORAGE_ID)))
1629 _pvr->storage_id = strdup((const char *)sqlite3_column_text(stmt, MEDIA_PVR_STORAGE_ID));
1631 if (STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_PVR_PATH)))
1632 _pvr->path = strdup((const char *)sqlite3_column_text(stmt, MEDIA_PVR_PATH));
1634 _pvr->size = (unsigned long long)sqlite3_column_int64(stmt, MEDIA_PVR_SIZE);
1636 _pvr->duration = (int)sqlite3_column_int(stmt, MEDIA_PVR_DURATION);
1638 _pvr->timezone = (int)sqlite3_column_int(stmt, MEDIA_PVR_TIME_ZONE);
1640 _pvr->ptc = (int)sqlite3_column_int(stmt, MEDIA_PVR_PTC);
1642 _pvr->major = (int)sqlite3_column_int(stmt, MEDIA_PVR_MAJOR);
1644 _pvr->minor = (int)sqlite3_column_int(stmt, MEDIA_PVR_MINOR);
1646 _pvr->channel_type = (int)sqlite3_column_int(stmt, MEDIA_PVR_CHANNEL_TYPE);
1648 if (STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_PVR_CHANNEL_NAME)))
1649 _pvr->channel_name = strdup((const char *)sqlite3_column_text(stmt, MEDIA_PVR_CHANNEL_NAME));
1651 if (STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_PVR_CHANNEL_NUM)))
1652 _pvr->channel_num = strdup((const char *)sqlite3_column_text(stmt, MEDIA_PVR_CHANNEL_NUM));
1654 if (STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_PVR_PROGRAM_TITLE)))
1655 _pvr->program_title = strdup((const char *)sqlite3_column_text(stmt, MEDIA_PVR_PROGRAM_TITLE));
1657 _pvr->program_num = (int)sqlite3_column_int(stmt, MEDIA_PVR_PROGRAM_NUM);
1659 if (STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_PVR_PROGRAM_CRID)))
1660 _pvr->program_crid = strdup((const char *)sqlite3_column_text(stmt, MEDIA_PVR_PROGRAM_CRID));
1662 if (STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_PVR_GUIDANCE)))
1663 _pvr->guidance = strdup((const char *)sqlite3_column_text(stmt, MEDIA_PVR_GUIDANCE));
1665 if (STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_PVR_SYNOPSIS)))
1666 _pvr->synopsis = strdup((const char *)sqlite3_column_text(stmt, MEDIA_PVR_SYNOPSIS));
1668 if (STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_PVR_GENRE)))
1669 _pvr->genre = strdup((const char *)sqlite3_column_text(stmt, MEDIA_PVR_GENRE));
1671 if (STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_PVR_LANGUAGE)))
1672 _pvr->language = strdup((const char *)sqlite3_column_text(stmt, MEDIA_PVR_LANGUAGE));
1674 if (STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_PVR_MODIFIED_MONTH)))
1675 _pvr->modified_month = strdup((const char *)sqlite3_column_text(stmt, MEDIA_PVR_MODIFIED_MONTH));
1677 if (STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_PVR_PRIVATE_DATA)))
1678 _pvr->private_data = strdup((const char *)sqlite3_column_text(stmt, MEDIA_PVR_PRIVATE_DATA));
1680 _pvr->embargo_time = (int)sqlite3_column_int(stmt, MEDIA_PVR_EMBARGO_TIME);
1682 _pvr->expiry_time = (int)sqlite3_column_int(stmt, MEDIA_PVR_EXPIRY_TIME);
1684 _pvr->start_time = (int)sqlite3_column_int(stmt, MEDIA_PVR_START_TIME);
1686 _pvr->program_start_time = (int)sqlite3_column_int(stmt, MEDIA_PVR_PROGRAM_START_TIME);
1688 _pvr->program_end_time = (int)sqlite3_column_int(stmt, MEDIA_PVR_PROGRAM_END_TIME);
1690 _pvr->program_date = (int)sqlite3_column_int(stmt, MEDIA_PVR_PROGRAM_DATE);
1692 _pvr->parental_rating = (int)sqlite3_column_int(stmt, MEDIA_PVR_PARENTAL_RATING);
1694 _pvr->timer_record = (int)sqlite3_column_int(stmt, MEDIA_PVR_TIMER_RECORD);
1696 _pvr->series_record = (int)sqlite3_column_int(stmt, MEDIA_PVR_SERIES_RECORD);
1698 _pvr->hd = (int)sqlite3_column_int(stmt, MEDIA_PVR_HD);
1700 _pvr->subtitle = (int)sqlite3_column_int(stmt, MEDIA_PVR_SUBTITLE);
1702 _pvr->ttx = (int)sqlite3_column_int(stmt, MEDIA_PVR_TTX);
1704 _pvr->ad = (int)sqlite3_column_int(stmt, MEDIA_PVR_AD);
1706 _pvr->hard_of_hearing_radio = (int)sqlite3_column_int(stmt, MEDIA_PVR_HARDOF_HEARINGRADIO);
1708 _pvr->data_service = (int)sqlite3_column_int(stmt, MEDIA_PVR_DATA_SERVICE);
1710 _pvr->content_lock = (int)sqlite3_column_int(stmt, MEDIA_PVR_CONTENT_LOCK);
1712 _pvr->content_watch = (int)sqlite3_column_int(stmt, MEDIA_PVR_CONTENT_WATCH);
1714 _pvr->has_audio_only = (int)sqlite3_column_int(stmt, MEDIA_PVR_HAS_AUDIO_ONLY);
1716 _pvr->is_local_record = (int)sqlite3_column_int(stmt, MEDIA_PVR_IS_LOCAL_RECORDED);
1718 _pvr->resolution = (int)sqlite3_column_int(stmt, MEDIA_PVR_RESOLUTION);
1720 _pvr->aspectratio = (int)sqlite3_column_int(stmt, MEDIA_PVR_ASPECTRATIO);
1722 _pvr->sports_type = (int)sqlite3_column_int(stmt, MEDIA_PVR_SPORTS_TYPE);
1724 _pvr->guidance_length = (int)sqlite3_column_int(stmt, MEDIA_PVR_GUIDANCE_LENGTH);
1726 _pvr->tvmode = (int)sqlite3_column_int(stmt, MEDIA_PVR_TVMODE);
1728 _pvr->play_count = (int)sqlite3_column_int(stmt, MEDIA_PVR_PLAY_COUNT);
1730 _pvr->highlight = (int)sqlite3_column_int(stmt, MEDIA_PVR_HIGHLIGHT);
1735 int _media_db_get_pvr(filter_h filter, media_pvr_cb callback, void *user_data)
1737 int ret = MEDIA_CONTENT_ERROR_NONE;
1738 char select_query[DEFAULT_QUERY_SIZE];
1739 char *condition_query = NULL;
1740 char *option_query = NULL;
1741 sqlite3_stmt *stmt = NULL;
1742 attribute_h attr = NULL;
1743 filter_s *_filter = (filter_s*)filter;
1745 attr = _content_get_attirbute_handle();
1746 memset(select_query, 0x00, sizeof(select_query));
1748 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
1749 snprintf(select_query, sizeof(select_query), SELECT_PVR_LIST_BY_STORAGE_ID, _filter->storage_id);
1751 SAFE_STRLCAT(select_query, SELECT_PVR_LIST, sizeof(select_query));
1753 ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query);
1754 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
1756 ret = _content_query_prepare(&stmt, select_query, condition_query, option_query);
1757 SAFE_FREE(condition_query);
1758 SAFE_FREE(option_query);
1759 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
1761 while (sqlite3_step(stmt) == SQLITE_ROW) {
1762 media_pvr_s *_pvr = (media_pvr_s*)calloc(1, sizeof(media_pvr_s));
1765 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1766 SQLITE3_FINALIZE(stmt);
1767 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1770 _media_pvr_item_get_detail(stmt, (media_pvr_h)_pvr);
1772 if (callback((media_pvr_h)_pvr, user_data) == false) {
1773 media_pvr_destroy((media_pvr_h) _pvr);
1777 media_pvr_destroy((media_pvr_h) _pvr);
1780 SQLITE3_FINALIZE(stmt);
1786 int _media_db_get_storage_id_by_media_id(const char *media_id, char *storage_id)
1788 int ret = MEDIA_CONTENT_ERROR_NONE;
1789 sqlite3_stmt *stmt = NULL;
1790 char *select_query = NULL;
1792 select_query = sqlite3_mprintf(SELECT_MEDIA_STORAGE_ID_BY_ID, media_id);
1794 ret = _content_query_prepare(&stmt, select_query, NULL, NULL);
1795 SQLITE3_SAFE_FREE(select_query);
1796 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
1798 if (sqlite3_step(stmt) == SQLITE_ROW) {
1799 if (STRING_VALID((const char *)sqlite3_column_text(stmt, 0)))
1800 strncpy(storage_id, (const char *)sqlite3_column_text(stmt, 0), MEDIA_CONTENT_UUID_SIZE);
1802 media_content_error("There's no media!!");
1803 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1806 SQLITE3_FINALIZE(stmt);
1810 #ifdef _USE_TV_PROFILE
1812 MEDIA_UHD_MEDIA_ID = 0,
1813 MEDIA_UHD_STORAGE_ID,
1816 MEDIA_UHD_CONTENT_ID,
1817 MEDIA_UHD_CONTENT_TITLE,
1818 MEDIA_UHD_FILE_NAME,
1819 MEDIA_UHD_FOLDER_ID,
1820 MEDIA_UHD_RELEASE_DATE,
1821 MEDIA_UHD_MODIFIED_TIME,
1822 MEDIA_UHD_PLAYED_POSITION,
1824 MEDIA_UHD_PLAYED_COUNT,
1825 } media_uhd_field_e;
1827 void _media_uhd_item_get_detail(sqlite3_stmt* stmt, media_uhd_h uhd)
1829 media_uhd_s *_uhd = (media_uhd_s*)uhd;
1831 if (STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_UHD_MEDIA_ID)))
1832 _uhd->media_id = strdup((const char *)sqlite3_column_text(stmt, MEDIA_UHD_MEDIA_ID));
1834 if (STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_UHD_STORAGE_ID)))
1835 _uhd->storage_id = strdup((const char *)sqlite3_column_text(stmt, MEDIA_UHD_STORAGE_ID));
1837 if (STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_UHD_PATH)))
1838 _uhd->path = strdup((const char *)sqlite3_column_text(stmt, MEDIA_UHD_PATH));
1840 _uhd->size = (unsigned long long)sqlite3_column_int64(stmt, MEDIA_UHD_SIZE);
1842 if (STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_UHD_CONTENT_ID)))
1843 _uhd->content_id = strdup((const char *)sqlite3_column_text(stmt, MEDIA_UHD_CONTENT_ID));
1845 if (STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_UHD_CONTENT_TITLE)))
1846 _uhd->content_title = strdup((const char *)sqlite3_column_text(stmt, MEDIA_UHD_CONTENT_TITLE));
1848 if (STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_UHD_FILE_NAME)))
1849 _uhd->file_name = strdup((const char *)sqlite3_column_text(stmt, MEDIA_UHD_FILE_NAME));
1851 if (STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_UHD_RELEASE_DATE)))
1852 _uhd->release_date = strdup((const char *)sqlite3_column_text(stmt, MEDIA_UHD_RELEASE_DATE));
1854 _uhd->modified_time = (int)sqlite3_column_int(stmt, MEDIA_UHD_MODIFIED_TIME);
1855 _uhd->played_position = (int)sqlite3_column_int(stmt, MEDIA_UHD_PLAYED_POSITION);
1856 _uhd->sub_type = (int)sqlite3_column_int(stmt, MEDIA_UHD_SUB_TYPE);
1857 _uhd->played_count = (int)sqlite3_column_int(stmt, MEDIA_UHD_PLAYED_COUNT);
1862 int _media_db_get_uhd(filter_h filter, media_uhd_cb callback, void *user_data)
1864 int ret = MEDIA_CONTENT_ERROR_NONE;
1865 char select_query[DEFAULT_QUERY_SIZE];
1866 char *condition_query = NULL;
1867 char *option_query = NULL;
1868 sqlite3_stmt *stmt = NULL;
1869 attribute_h attr = NULL;
1870 filter_s *_filter = (filter_s*)filter;
1872 attr = _content_get_attirbute_handle();
1873 memset(select_query, 0x00, sizeof(select_query));
1875 if ((_filter != NULL) && STRING_VALID(_filter->storage_id))
1876 snprintf(select_query, sizeof(select_query), SELECT_UHD_LIST_BY_STORAGE_ID, _filter->storage_id);
1878 SAFE_STRLCAT(select_query, SELECT_UHD_LIST, sizeof(select_query));
1880 ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query);
1881 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
1883 ret = _content_query_prepare(&stmt, select_query, condition_query, option_query);
1884 SAFE_FREE(condition_query);
1885 SAFE_FREE(option_query);
1886 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
1888 while (sqlite3_step(stmt) == SQLITE_ROW) {
1889 media_uhd_s *_uhd = (media_uhd_s*)calloc(1, sizeof(media_uhd_s));
1892 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1893 SQLITE3_FINALIZE(stmt);
1894 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1897 _media_uhd_item_get_detail(stmt, (media_uhd_h)_uhd);
1899 if (callback((media_uhd_h)_uhd, user_data) == false) {
1900 media_uhd_destroy((media_uhd_h) _uhd);
1903 media_uhd_destroy((media_uhd_h) _uhd);
1906 SQLITE3_FINALIZE(stmt);