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 const char * __media_db_get_group_name(media_group_e group)
25 case MEDIA_CONTENT_GROUP_DISPLAY_NAME:
26 return DB_FIELD_MEDIA_DISPLAY_NAME;
27 case MEDIA_CONTENT_GROUP_TYPE:
28 return DB_FIELD_MEDIA_TYPE;
29 case MEDIA_CONTENT_GROUP_MIME_TYPE:
30 return DB_FIELD_MEDIA_MIME_TYPE;
31 case MEDIA_CONTENT_GROUP_SIZE:
32 return DB_FIELD_MEDIA_SIZE;
33 case MEDIA_CONTENT_GROUP_ADDED_TIME:
34 return DB_FIELD_MEDIA_ADDED_TIME;
35 case MEDIA_CONTENT_GROUP_MODIFIED_TIME:
36 return DB_FIELD_MEDIA_MODIFIED_TIME;
37 case MEDIA_CONTENT_GROUP_TITLE:
38 return DB_FIELD_MEDIA_TITLE;
39 case MEDIA_CONTENT_GROUP_ARTIST:
40 return DB_FIELD_MEDIA_ARTIST;
41 case MEDIA_CONTENT_GROUP_ALBUM_ARTIST:
42 return DB_FIELD_MEDIA_ALBUM_ARTIST;
43 case MEDIA_CONTENT_GROUP_GENRE:
44 return DB_FIELD_MEDIA_GENRE;
45 case MEDIA_CONTENT_GROUP_COMPOSER:
46 return DB_FIELD_MEDIA_COMPOSER;
47 case MEDIA_CONTENT_GROUP_YEAR:
48 return DB_FIELD_MEDIA_YEAR;
49 case MEDIA_CONTENT_GROUP_RECORDED_DATE:
50 return DB_FIELD_MEDIA_RECORDED_DATE;
51 case MEDIA_CONTENT_GROUP_COPYRIGHT:
52 return DB_FIELD_MEDIA_COPYRIGHT;
53 case MEDIA_CONTENT_GROUP_TRACK_NUM:
54 return DB_FIELD_MEDIA_TRACK_NUM;
55 case MEDIA_CONTENT_GROUP_DESCRIPTION:
56 return DB_FIELD_MEDIA_DESCRIPTION;
57 case MEDIA_CONTENT_GROUP_LONGITUDE:
58 return DB_FIELD_MEDIA_LONGITUDE;
59 case MEDIA_CONTENT_GROUP_LATITUDE:
60 return DB_FIELD_MEDIA_LATITUDE;
61 case MEDIA_CONTENT_GROUP_ALTITUDE:
62 return DB_FIELD_MEDIA_ALTITUDE;
63 case MEDIA_CONTENT_GROUP_RATING:
64 return DB_FIELD_MEDIA_RATING;
66 case MEDIA_CONTENT_GROUP_MODIFIED_MONTH:
67 return DB_FIELD_MEDIA_MODIFIED_DATE;
68 case MEDIA_CONTENT_GROUP_MODIFIED_DATE:
69 return DB_FIELD_MEDIA_MODIFIED_DATE;
70 case MEDIA_CONTENT_GROUP_ALBUM:
71 return DB_FIELD_MEDIA_ALBUM;
72 case MEDIA_PVR_GROUP_DURATION:
73 return DB_FIELD_PVR_DURATION;
74 case MEDIA_PVR_GROUP_TIME_ZONE:
75 return DB_FIELD_PVR_TIME_ZONE;
76 case MEDIA_PVR_GROUP_PTC:
77 return DB_FIELD_PVR_PTC;
78 case MEDIA_PVR_GROUP_MAJOR:
79 return DB_FIELD_PVR_MAJOR;
80 case MEDIA_PVR_GROUP_MINOR:
81 return DB_FIELD_PVR_MINOR;
82 case MEDIA_PVR_GROUP_CHANNEL_TYPE:
83 return DB_FIELD_PVR_CHANNEL_TYPE;
84 case MEDIA_PVR_GROUP_CHANNEL_NAME:
85 return DB_FIELD_PVR_CHANNEL_NAME;
86 case MEDIA_PVR_GROUP_CHANNEL_NUM:
87 return DB_FIELD_PVR_CHANNEL_NUM;
88 case MEDIA_PVR_GROUP_PROGRAM_TITLE:
89 return DB_FIELD_PVR_PROGRAM_TITLE;
90 case MEDIA_PVR_GROUP_PROGRAM_NUM:
91 return DB_FIELD_PVR_PROGRAM_NUM;
92 case MEDIA_PVR_GROUP_PROGRAM_CRID:
93 return DB_FIELD_PVR_PROGRAM_CRID;
94 case MEDIA_PVR_GROUP_GUIDANCE:
95 return DB_FIELD_PVR_GUIDANCE;
96 case MEDIA_PVR_GROUP_SYNOPSIS:
97 return DB_FIELD_PVR_SYNOPSIS;
98 case MEDIA_PVR_GROUP_GENRE:
99 return DB_FIELD_PVR_GENRE;
100 case MEDIA_PVR_GROUP_LANGUAGE:
101 return DB_FIELD_PVR_LANGUAGE;
102 case MEDIA_PVR_GROUP_EMBARGO_TIME:
103 return DB_FIELD_PVR_EMBARGO_TIME;
104 case MEDIA_PVR_GROUP_EXPIRY_TIME:
105 return DB_FIELD_PVR_EXPIRY_TIME;
106 case MEDIA_PVR_GROUP_START_TIME:
107 return DB_FIELD_PVR_START_TIME;
108 case MEDIA_PVR_GROUP_PROGRAM_START_TIME:
109 return DB_FIELD_PVR_PROGRAM_START_TIME;
110 case MEDIA_PVR_GROUP_PROGRAM_END_TIME:
111 return DB_FIELD_PVR_PROGRAM_END_TIME;
112 case MEDIA_PVR_GROUP_PROGRAM_DATE:
113 return DB_FIELD_PVR_PROGRAM_DATE;
114 case MEDIA_PVR_GROUP_PARENTAL_RATING:
115 return DB_FIELD_PVR_PARENTAL_RATING;
116 case MEDIA_PVR_GROUP_TIMER_RECORD:
117 return DB_FIELD_PVR_TIMER_RECORD;
118 case MEDIA_PVR_GROUP_SERIES_RECORD:
119 return DB_FIELD_PVR_SERIES_RECORD;
120 case MEDIA_PVR_GROUP_HD:
121 return DB_FIELD_PVR_HD;
122 case MEDIA_PVR_GROUP_SUBTITLE:
123 return DB_FIELD_PVR_SUBTITLE;
124 case MEDIA_PVR_GROUP_TTX:
125 return DB_FIELD_PVR_TTX;
126 case MEDIA_PVR_GROUP_AD:
127 return DB_FIELD_PVR_AD;
128 case MEDIA_PVR_GROUP_HARDOF_HEARINGRADIO:
129 return DB_FIELD_PVR_HARDOF_HEARINGRADIO;
130 case MEDIA_PVR_GROUP_DATA_SERVICE:
131 return DB_FIELD_PVR_DATA_SERVICE;
132 case MEDIA_PVR_GROUP_CONTENT_LOCK:
133 return DB_FIELD_PVR_CONTENT_LOCK;
134 case MEDIA_PVR_GROUP_CONTENT_WATCH:
135 return DB_FIELD_PVR_CONTENT_WATCH;
136 case MEDIA_PVR_GROUP_HAS_AUDIO_ONLY:
137 return DB_FIELD_PVR_HAS_AUDIO_ONLY;
138 case MEDIA_PVR_GROUP_IS_LOCAL_RECORDED:
139 return DB_FIELD_PVR_IS_LOCAL_RECORD;
140 case MEDIA_PVR_GROUP_RESOLUTION:
141 return DB_FIELD_PVR_RESOLUTION;
142 case MEDIA_PVR_GROUP_ASPECTRATIO:
143 return DB_FIELD_PVR_ASPECTRATIO;
144 case MEDIA_PVR_GROUP_MODIFIED_MONTH:
145 return DB_FIELD_PVR_MODIFIED_DATE;
146 case MEDIA_PVR_GROUP_MODIFIED_DATE:
147 return DB_FIELD_PVR_MODIFIED_DATE;
148 case MEDIA_PVR_GROUP_SPORTS_TYPE:
149 return DB_FIELD_PVR_SPORTS_TYPE;
150 case MEDIA_PVR_GROUP_GUIDANCE_LENGTH:
151 return DB_FIELD_PVR_GUIDANCE_LENGTH;
152 case MEDIA_PVR_GROUP_TVMODE:
153 return DB_FIELD_PVR_TVMODE;
154 case MEDIA_PVR_GROUP_PLAY_COUNT:
155 return DB_FIELD_PVR_PLAY_COUNT;
156 case MEDIA_PVR_GROUP_PRIVATE_DATA:
157 return DB_FIELD_PVR_PRIVATE_DATA;
158 case MEDIA_UHD_GROUP_CONTENT_TITLE:
159 return DB_FIELD_UHD_CONTENT_TITLE;
160 case MEDIA_UHD_GROUP_RELEASE_DATE:
161 return DB_FIELD_UHD_RELEASE_DATE;
162 case MEDIA_UHD_GROUP_SUB_TYPE:
163 return DB_FIELD_UHD_SUB_TYPE;
164 case MEDIA_UHD_GROUP_FILE_NAME:
165 return DB_FIELD_UHD_FILE_NAME;
166 case MEDIA_UHD_GROUP_PLAYED_COUNT:
167 return DB_FIELD_UHD_PLAYED_COUNT;
176 static int __media_db_make_query(filter_h filter, char **condition_query, char **option_query)
178 int ret = MEDIA_CONTENT_ERROR_NONE;
179 filter_s *_filter = (filter_s *)filter;
181 content_retv_if(!_filter, MEDIA_CONTENT_ERROR_NONE);
183 if (STRING_VALID(_filter->condition)) {
184 ret = _media_filter_build_condition(_filter->is_full_condition, _filter->condition, _filter->condition_collate_type, condition_query);
185 content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
188 ret = _media_filter_build_option(filter, option_query);
189 if (ret != MEDIA_CONTENT_ERROR_NONE)
190 g_free(*condition_query);
195 #ifdef _USE_TVPD_MODE
196 int _media_db_get_group_count(filter_h filter, group_list_e group_type, int *group_count)
198 int ret = MEDIA_CONTENT_ERROR_NONE;
199 sqlite3_stmt *stmt = NULL;
200 char *select_query = NULL;
201 char *condition_query = NULL;
202 char *option_query = NULL;
203 filter_s *_filter = (filter_s *)filter;
205 switch (group_type) {
206 case MEDIA_GROUP_ALBUM:
207 if (_filter && STRING_VALID(_filter->storage_id))
208 select_query = g_strdup_printf(SELECT_ALBUM_COUNT, _filter->storage_id);
210 select_query = g_strdup_printf(SELECT_ALBUM_COUNT, DB_VIEW_MEDIA);
213 case MEDIA_GROUP_FOLDER:
214 if (_filter && STRING_VALID(_filter->storage_id))
215 select_query = g_strdup_printf(SELECT_FOLDER_COUNT_BY_STORAGE_ID, _filter->storage_id, _filter->storage_id);
217 select_query = g_strdup_printf(SELECT_FOLDER_COUNT, DB_VIEW_MEDIA);
220 case MEDIA_GROUP_PLAYLIST:
221 select_query = g_strdup(SELECT_PLAYLIST_COUNT);
224 case MEDIA_GROUP_TAG:
225 select_query = g_strdup(SELECT_TAG_COUNT);
228 case MEDIA_GROUP_BOOKMARK:
229 if (_filter && STRING_VALID(_filter->storage_id))
230 select_query = g_strdup_printf(SELECT_BOOKMARK_COUNT, _filter->storage_id);
232 select_query = g_strdup_printf(SELECT_BOOKMARK_COUNT, DB_VIEW_MEDIA);
236 case MEDIA_GROUP_STORAGE:
237 select_query = g_strdup(SELECT_STORAGE_COUNT);
240 case MEDIA_GROUP_FACE:
241 if (_filter && STRING_VALID(_filter->storage_id))
242 select_query = g_strdup_printf(SELECT_FACE_COUNT, _filter->storage_id);
244 select_query = g_strdup_printf(SELECT_FACE_COUNT, DB_VIEW_MEDIA);
248 content_error("Invalid group type [%d]", group_type);
249 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
252 ret = __media_db_make_query(filter, &condition_query, &option_query);
253 if (ret != MEDIA_CONTENT_ERROR_NONE) {
254 g_free(select_query);
258 ret = _content_query_prepare(select_query, condition_query, option_query, &stmt);
259 g_free(select_query);
260 g_free(condition_query);
261 g_free(option_query);
262 content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
264 if (sqlite3_step(stmt) == SQLITE_ROW)
265 *group_count = sqlite3_column_int(stmt, 0);
267 SQLITE3_FINALIZE(stmt);
272 int _media_db_get_media_group_count(media_group_e group, filter_h filter, int *group_count)
274 int ret = MEDIA_CONTENT_ERROR_NONE;
275 sqlite3_stmt *stmt = NULL;
276 char select_query[MAX_QUERY_SIZE] = {0, };
277 char *condition_query = NULL;
278 char *option_query = NULL;
279 char *tmp_option = NULL;
280 filter_s *_filter = (filter_s *)filter;
282 if (group < MEDIA_PVR_GROUP_DURATION) { /*media content*/
283 if (_filter && STRING_VALID(_filter->storage_id))
284 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_GROUP_COUNT, __media_db_get_group_name(group), _filter->storage_id);
286 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_GROUP_COUNT, __media_db_get_group_name(group), DB_VIEW_MEDIA);
287 } else if (group < MEDIA_UHD_GROUP_CONTENT_TITLE) { /*pvr content*/
288 if (_filter && STRING_VALID(_filter->storage_id))
289 snprintf(select_query, sizeof(select_query), SELECT_PVR_GROUP_COUNT_BY_STORAGE_ID, __media_db_get_group_name(group), _filter->storage_id);
291 snprintf(select_query, sizeof(select_query), SELECT_PVR_GROUP_COUNT, __media_db_get_group_name(group));
292 } else { /*uhd content*/
293 if (_filter && STRING_VALID(_filter->storage_id))
294 snprintf(select_query, sizeof(select_query), SELECT_UHD_GROUP_COUNT_BY_STORAGE_ID, __media_db_get_group_name(group), _filter->storage_id);
296 snprintf(select_query, sizeof(select_query), SELECT_UHD_GROUP_COUNT, __media_db_get_group_name(group));
298 ret = __media_db_make_query(filter, &condition_query, &option_query);
299 content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
302 tmp_option = g_strconcat(option_query, ")", NULL);
303 g_free(option_query);
304 option_query = tmp_option;
306 SAFE_STRLCAT(select_query, ")", sizeof(select_query));
309 ret = _content_query_prepare(select_query, condition_query, option_query, &stmt);
310 g_free(condition_query);
311 g_free(option_query);
312 content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
314 if (sqlite3_step(stmt) == SQLITE_ROW)
315 *group_count = sqlite3_column_int(stmt, 0);
317 SQLITE3_FINALIZE(stmt);
322 int _media_db_get_media_group(media_group_e group, filter_h filter, media_group_cb callback, void *user_data)
324 int ret = MEDIA_CONTENT_ERROR_NONE;
325 char select_query[MAX_QUERY_SIZE] = {0, };
326 char *condition_query = NULL;
327 char *option_query = NULL;
329 sqlite3_stmt *stmt = NULL;
330 filter_s *_filter = (filter_s *)filter;
332 if (group < MEDIA_PVR_GROUP_DURATION) { /*media content */
333 if (_filter && STRING_VALID(_filter->storage_id))
334 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_GROUP_LIST, __media_db_get_group_name(group), _filter->storage_id);
336 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_GROUP_LIST, __media_db_get_group_name(group), DB_VIEW_MEDIA);
337 } else if (group < MEDIA_UHD_GROUP_CONTENT_TITLE) { /*pvr content */
338 if (_filter && STRING_VALID(_filter->storage_id))
339 snprintf(select_query, sizeof(select_query), SELECT_PVR_GROUP_LIST_BY_STORAGE_ID, __media_db_get_group_name(group), _filter->storage_id);
341 snprintf(select_query, sizeof(select_query), SELECT_PVR_GROUP_LIST, __media_db_get_group_name(group));
342 } else { /* uhd content */
343 if (_filter && STRING_VALID(_filter->storage_id))
344 snprintf(select_query, sizeof(select_query), SELECT_UHD_GROUP_LIST_BY_STORAGE_ID, __media_db_get_group_name(group), _filter->storage_id);
346 snprintf(select_query, sizeof(select_query), SELECT_UHD_GROUP_LIST, __media_db_get_group_name(group));
348 ret = __media_db_make_query(filter, &condition_query, &option_query);
349 content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
351 ret = _content_query_prepare(select_query, condition_query, option_query, &stmt);
352 g_free(condition_query);
353 g_free(option_query);
354 content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
356 while (sqlite3_step(stmt) == SQLITE_ROW) {
357 name = g_strdup((const char *)sqlite3_column_text(stmt, 0));
359 if (callback(name, user_data) == false) {
367 SQLITE3_FINALIZE(stmt);
372 int _media_db_get_media_group_and_count(media_group_e group, filter_h filter, media_group_and_count_cb callback, void *user_data)
374 int ret = MEDIA_CONTENT_ERROR_NONE;
375 char select_query[DEFAULT_QUERY_SIZE] = {0, };
376 char group_query[DEFAULT_QUERY_SIZE] = {0, };
377 char *condition_query = NULL;
378 char *option_query = NULL;
380 sqlite3_stmt *stmt = NULL;
381 filter_s *_filter = (filter_s *)filter;
383 const char* group_name = __media_db_get_group_name(group);
384 content_retip_if_fail(STRING_VALID(group_name));
386 if (group < MEDIA_PVR_GROUP_DURATION) { /*media content*/
387 if (_filter && STRING_VALID(_filter->storage_id))
388 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_GROUP_AND_COUNT, group_name, _filter->storage_id);
390 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_GROUP_AND_COUNT, group_name, DB_VIEW_MEDIA);
391 } else if (group < MEDIA_UHD_GROUP_CONTENT_TITLE) {/*pvr content*/
392 if (_filter && STRING_VALID(_filter->storage_id))
393 snprintf(select_query, sizeof(select_query), SELECT_PVR_GROUP_AND_COUNT_BY_STORAGE_ID, group_name, _filter->storage_id);
395 snprintf(select_query, sizeof(select_query), SELECT_PVR_GROUP_AND_COUNT, group_name);
396 } else {/*uhd content*/
397 if (_filter && STRING_VALID(_filter->storage_id))
398 snprintf(select_query, sizeof(select_query), SELECT_UHD_GROUP_AND_COUNT_BY_STORAGE_ID, group_name, _filter->storage_id);
400 snprintf(select_query, sizeof(select_query), SELECT_UHD_GROUP_AND_COUNT, group_name);
403 ret = __media_db_make_query(filter, &condition_query, &option_query);
404 content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
406 if (STRING_VALID(option_query))
407 snprintf(group_query, sizeof(group_query), "GROUP BY %s %s", group_name, option_query);
409 snprintf(group_query, sizeof(group_query), "GROUP BY %s", group_name);
411 ret = _content_query_prepare(select_query, condition_query, group_query, &stmt);
412 g_free(condition_query);
413 g_free(option_query);
414 content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
416 while (sqlite3_step(stmt) == SQLITE_ROW) {
417 name = g_strdup((const char *)sqlite3_column_text(stmt, 0));
419 if (callback(name, sqlite3_column_int(stmt, 1), user_data) == false) {
427 SQLITE3_FINALIZE(stmt);
432 int _media_db_get_group_count(filter_h filter, group_list_e group_type, int *group_count)
434 int ret = MEDIA_CONTENT_ERROR_NONE;
435 sqlite3_stmt *stmt = NULL;
436 char *select_query = NULL;
437 char *condition_query = NULL;
438 char *option_query = NULL;
439 filter_s *_filter = (filter_s *)filter;
441 switch (group_type) {
442 case MEDIA_GROUP_ALBUM:
443 if (_filter && STRING_VALID(_filter->storage_id))
444 select_query = g_strdup_printf(SELECT_ALBUM_COUNT_BY_STORAGE_ID, _filter->storage_id);
446 select_query = g_strdup(SELECT_ALBUM_COUNT);
449 case MEDIA_GROUP_FOLDER:
450 if (_filter && STRING_VALID(_filter->storage_id))
451 select_query = g_strdup_printf(SELECT_FOLDER_COUNT_BY_STORAGE_ID, _filter->storage_id);
453 select_query = g_strdup(SELECT_FOLDER_COUNT);
456 case MEDIA_GROUP_PLAYLIST:
457 select_query = g_strdup(SELECT_PLAYLIST_COUNT);
460 case MEDIA_GROUP_TAG:
461 select_query = g_strdup(SELECT_TAG_COUNT);
464 case MEDIA_GROUP_BOOKMARK:
465 if (_filter && STRING_VALID(_filter->storage_id))
466 select_query = g_strdup_printf(SELECT_BOOKMARK_COUNT_BY_STORAGE_ID, _filter->storage_id);
468 select_query = g_strdup(SELECT_BOOKMARK_COUNT);
472 case MEDIA_GROUP_STORAGE:
473 select_query = g_strdup(SELECT_STORAGE_COUNT);
476 case MEDIA_GROUP_FACE:
477 if (_filter && STRING_VALID(_filter->storage_id))
478 select_query = g_strdup_printf(SELECT_FACE_COUNT_BY_STORAGE_ID, _filter->storage_id);
480 select_query = g_strdup(SELECT_FACE_COUNT);
484 content_error("Invalid group type [%d]", group_type);
485 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
488 ret = __media_db_make_query(filter, &condition_query, &option_query);
489 if (ret != MEDIA_CONTENT_ERROR_NONE) {
490 g_free(select_query);
494 ret = _content_query_prepare(select_query, condition_query, option_query, &stmt);
495 g_free(select_query);
496 g_free(condition_query);
497 g_free(option_query);
498 content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
500 if (sqlite3_step(stmt) == SQLITE_ROW)
501 *group_count = sqlite3_column_int(stmt, 0);
503 SQLITE3_FINALIZE(stmt);
508 int _media_db_get_media_group_count(media_group_e group, filter_h filter, int *group_count)
510 int ret = MEDIA_CONTENT_ERROR_NONE;
511 sqlite3_stmt *stmt = NULL;
512 char *select_query = NULL;
513 char *condition_query = NULL;
514 char *option_query = NULL;
515 filter_s *_filter = (filter_s *)filter;
517 if (_filter && STRING_VALID(_filter->storage_id))
518 select_query = g_strdup_printf(SELECT_MEDIA_GROUP_COUNT_BY_STORAGE_ID, __media_db_get_group_name(group), __media_db_get_group_name(group), _filter->storage_id);
520 select_query = g_strdup_printf(SELECT_MEDIA_GROUP_COUNT, __media_db_get_group_name(group), __media_db_get_group_name(group));
522 ret = __media_db_make_query(filter, &condition_query, &option_query);
523 if (ret != MEDIA_CONTENT_ERROR_NONE) {
524 g_free(select_query);
528 ret = _content_query_prepare(select_query, condition_query, option_query, &stmt);
529 g_free(select_query);
530 g_free(condition_query);
531 g_free(option_query);
532 content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
534 if (sqlite3_step(stmt) == SQLITE_ROW)
535 *group_count = sqlite3_column_int(stmt, 0);
537 SQLITE3_FINALIZE(stmt);
542 int _media_db_get_media_group(media_group_e group, filter_h filter, media_group_cb callback, void *user_data)
544 int ret = MEDIA_CONTENT_ERROR_NONE;
545 char *select_query = NULL;
546 char *condition_query = NULL;
547 char *option_query = NULL;
549 sqlite3_stmt *stmt = NULL;
550 filter_s *_filter = (filter_s *)filter;
552 if (_filter && STRING_VALID(_filter->storage_id))
553 select_query = g_strdup_printf(SELECT_MEDIA_GROUP_LIST_BY_STORAGE_ID, __media_db_get_group_name(group), _filter->storage_id);
555 select_query = g_strdup_printf(SELECT_MEDIA_GROUP_LIST, __media_db_get_group_name(group));
557 ret = __media_db_make_query(filter, &condition_query, &option_query);
558 if (ret != MEDIA_CONTENT_ERROR_NONE) {
559 g_free(select_query);
563 ret = _content_query_prepare(select_query, condition_query, option_query, &stmt);
564 g_free(select_query);
565 g_free(condition_query);
566 g_free(option_query);
567 content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
569 while (sqlite3_step(stmt) == SQLITE_ROW) {
570 name = g_strdup((const char *)sqlite3_column_text(stmt, 0));
572 if (callback(name, user_data) == false) {
580 SQLITE3_FINALIZE(stmt);
586 int _media_db_get_album(filter_h filter, media_album_cb callback, void *user_data)
588 int ret = MEDIA_CONTENT_ERROR_NONE;
589 char *select_query = NULL;
590 char *condition_query = NULL;
591 char *option_query = NULL;
592 sqlite3_stmt *stmt = NULL;
593 filter_s *_filter = (filter_s *)filter;
595 #ifdef _USE_TVPD_MODE
596 if (_filter && STRING_VALID(_filter->storage_id))
597 select_query = g_strdup_printf(SELECT_ALBUM_LIST, _filter->storage_id);
599 select_query = g_strdup_printf(SELECT_ALBUM_LIST, DB_VIEW_MEDIA);
601 if (_filter && STRING_VALID(_filter->storage_id))
602 select_query = g_strdup_printf(SELECT_ALBUM_LIST_BY_STORAGE_ID, _filter->storage_id);
604 select_query = g_strdup(SELECT_ALBUM_LIST);
606 ret = __media_db_make_query(filter, &condition_query, &option_query);
607 if (ret != MEDIA_CONTENT_ERROR_NONE) {
608 g_free(select_query);
612 ret = _content_query_prepare(select_query, condition_query, option_query, &stmt);
613 g_free(select_query);
614 g_free(condition_query);
615 g_free(option_query);
616 content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
618 while (sqlite3_step(stmt) == SQLITE_ROW) {
619 media_album_s *album = g_new0(media_album_s, 1);
621 album->album_id = sqlite3_column_int(stmt, 0);
622 album->name = g_strdup((const char *)sqlite3_column_text(stmt, 1));
623 album->artist = g_strdup((const char *)sqlite3_column_text(stmt, 2));
624 album->album_art_path = g_strdup((const char *)sqlite3_column_text(stmt, 3));
626 if (callback((media_album_h)album, user_data) == false) {
627 media_album_destroy((media_album_h)album);
631 media_album_destroy((media_album_h)album);
634 SQLITE3_FINALIZE(stmt);
639 int _media_db_get_folder(filter_h filter, media_folder_cb callback, void *user_data)
641 int ret = MEDIA_CONTENT_ERROR_NONE;
642 char *select_query = NULL;
643 char *condition_query = NULL;
644 char *option_query = NULL;
645 sqlite3_stmt *stmt = NULL;
646 filter_s *_filter = (filter_s *)filter;
648 #ifdef _USE_TVPD_MODE
649 if (_filter && STRING_VALID(_filter->storage_id))
650 select_query = g_strdup_printf(SELECT_FOLDER_LIST_BY_STORAGE_ID, _filter->storage_id, _filter->storage_id);
652 select_query = g_strdup_printf(SELECT_FOLDER_LIST, DB_VIEW_MEDIA);
654 if (_filter && STRING_VALID(_filter->storage_id))
655 select_query = g_strdup_printf(SELECT_FOLDER_LIST_BY_STORAGE_ID, _filter->storage_id);
657 select_query = g_strdup(SELECT_FOLDER_LIST);
659 ret = __media_db_make_query(filter, &condition_query, &option_query);
660 if (ret != MEDIA_CONTENT_ERROR_NONE) {
661 g_free(select_query);
665 ret = _content_query_prepare(select_query, condition_query, option_query, &stmt);
666 g_free(select_query);
667 g_free(condition_query);
668 g_free(option_query);
669 content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
671 while (sqlite3_step(stmt) == SQLITE_ROW) {
672 media_folder_s *_folder = g_new0(media_folder_s, 1);
674 _folder->folder_id = g_strdup((const char *)sqlite3_column_text(stmt, 0));
675 _folder->path = g_strdup((const char *)sqlite3_column_text(stmt, 1));
676 _folder->name = g_strdup((const char *)sqlite3_column_text(stmt, 2));
677 _folder->storage_type = sqlite3_column_int(stmt, 3);
678 _folder->storage_uuid = g_strdup((const char *)sqlite3_column_text(stmt, 4));
680 if (callback((media_folder_h)_folder, user_data) == false) {
681 media_folder_destroy((media_folder_h) _folder);
685 media_folder_destroy((media_folder_h) _folder);
688 SQLITE3_FINALIZE(stmt);
693 int _media_db_get_playlist(filter_h filter, media_playlist_cb callback, void *user_data)
695 int ret = MEDIA_CONTENT_ERROR_NONE;
696 char *condition_query = NULL;
697 char *option_query = NULL;
698 sqlite3_stmt *stmt = NULL;
700 ret = __media_db_make_query(filter, &condition_query, &option_query);
701 content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
703 ret = _content_query_prepare(SELECT_PLAYLIST_LIST, condition_query, option_query, &stmt);
704 g_free(condition_query);
705 g_free(option_query);
706 content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
708 while (sqlite3_step(stmt) == SQLITE_ROW) {
709 media_playlist_s *_playlist = g_new0(media_playlist_s, 1);
711 _playlist->playlist_id = sqlite3_column_int(stmt, 0);
712 _playlist->name = g_strdup((const char *)sqlite3_column_text(stmt, 1));
713 _playlist->thumbnail_path = g_strdup((const char *)sqlite3_column_text(stmt, 2));
715 if (callback((media_playlist_h)_playlist, user_data) == false) {
716 media_playlist_destroy((media_playlist_h)_playlist);
719 media_playlist_destroy((media_playlist_h)_playlist);
722 SQLITE3_FINALIZE(stmt);
727 int _media_db_get_playlist_item(int playlist_id, filter_h filter, playlist_member_cb callback, void *user_data)
729 int ret = MEDIA_CONTENT_ERROR_NONE;
730 char *select_query = NULL;
731 char *condition_query = NULL;
732 char *option_query = NULL;
733 sqlite3_stmt *stmt = NULL;
735 select_query = g_strdup_printf(SELECT_PLAYLIST_ITEM_ALL_FROM_PLAYLIST_VIEW, playlist_id);
737 ret = __media_db_make_query(filter, &condition_query, &option_query);
738 if (ret != MEDIA_CONTENT_ERROR_NONE) {
739 g_free(select_query);
743 ret = _content_query_prepare(select_query, condition_query, option_query, &stmt);
744 g_free(select_query);
745 g_free(condition_query);
746 g_free(option_query);
747 content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
749 while (sqlite3_step(stmt) == SQLITE_ROW) {
750 int playlist_member_id = 0;
751 playlist_member_id = sqlite3_column_int(stmt, MEDIA_INFO_ITEM_MAX); /*MEDIA_INFO_ITEM_MAX is pm_id*/
753 media_info_s *_media = g_new0(media_info_s, 1);
755 _media_info_item_get_detail(stmt, (media_info_h)_media);
757 if (callback(playlist_member_id, (media_info_h)_media, user_data) == false) {
758 media_info_destroy((media_info_h)_media);
761 media_info_destroy((media_info_h)_media);
765 SQLITE3_FINALIZE(stmt);
770 int _media_db_get_tag(const char *media_id, filter_h filter, media_tag_cb callback, void *user_data)
772 int ret = MEDIA_CONTENT_ERROR_NONE;
773 char *select_query = NULL;
774 char *condition_query = NULL;
775 char *option_query = NULL;
776 sqlite3_stmt *stmt = NULL;
778 if (STRING_VALID(media_id))
779 select_query = g_strdup_printf(SELECT_TAG_LIST_BY_MEDIA_ID, media_id);
781 select_query = g_strdup(SELECT_TAG_LIST);
783 ret = __media_db_make_query(filter, &condition_query, &option_query);
784 if (ret != MEDIA_CONTENT_ERROR_NONE) {
785 g_free(select_query);
789 ret = _content_query_prepare(select_query, condition_query, option_query, &stmt);
790 g_free(select_query);
791 g_free(condition_query);
792 g_free(option_query);
793 content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
795 while (sqlite3_step(stmt) == SQLITE_ROW) {
796 media_tag_s *_tag = g_new0(media_tag_s, 1);
798 _tag->tag_id = sqlite3_column_int(stmt, 0);
799 _tag->name = g_strdup((const char *)sqlite3_column_text(stmt, 1));
801 if (callback((media_tag_h)_tag, user_data) == false) {
802 media_tag_destroy((media_tag_h)_tag);
805 media_tag_destroy((media_tag_h)_tag);
808 SQLITE3_FINALIZE(stmt);
813 int _media_db_get_bookmark(const char *media_id, filter_h filter, media_bookmark_cb callback, void *user_data)
815 int ret = MEDIA_CONTENT_ERROR_NONE;
816 char *select_query = NULL;
817 char *condition_query = NULL;
818 char *option_query = NULL;
819 sqlite3_stmt *stmt = NULL;
820 filter_s *_filter = (filter_s *)filter;
822 #ifdef _USE_TVPD_MODE
823 if (STRING_VALID(media_id)) { //get bookmark by media_id
824 if (_filter && STRING_VALID(_filter->storage_id))
825 select_query = g_strdup_printf(SELECT_BOOKMARK_LIST_BY_MEDIA_ID, _filter->storage_id, media_id);
827 select_query = g_strdup_printf(SELECT_BOOKMARK_LIST_BY_MEDIA_ID, DB_VIEW_MEDIA, media_id);
829 if (_filter && STRING_VALID(_filter->storage_id))
830 select_query = g_strdup_printf(SELECT_BOOKMARK_LIST, _filter->storage_id);
832 select_query = g_strdup_printf(SELECT_BOOKMARK_LIST, DB_VIEW_MEDIA);
835 if (STRING_VALID(media_id)) { //get bookmark by media_id
836 select_query = g_strdup_printf(SELECT_BOOKMARK_LIST_BY_MEDIA_ID, media_id);
838 if (_filter && STRING_VALID(_filter->storage_id))
839 select_query = g_strdup_printf(SELECT_BOOKMARK_LIST_BY_STORAGE_ID, _filter->storage_id);
841 select_query = g_strdup(SELECT_BOOKMARK_LIST);
845 ret = __media_db_make_query(filter, &condition_query, &option_query);
846 if (ret != MEDIA_CONTENT_ERROR_NONE) {
847 g_free(select_query);
851 ret = _content_query_prepare(select_query, condition_query, option_query, &stmt);
852 g_free(select_query);
853 g_free(condition_query);
854 g_free(option_query);
855 content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
857 while (sqlite3_step(stmt) == SQLITE_ROW) {
858 media_bookmark_s *bookmark = g_new0(media_bookmark_s, 1);
860 bookmark->bookmark_id = sqlite3_column_int(stmt, 0);
861 bookmark->media_id = g_strdup((const char *)sqlite3_column_text(stmt, 1));
862 bookmark->marked_time = sqlite3_column_int(stmt, 2);
863 bookmark->thumbnail_path = g_strdup((const char *)sqlite3_column_text(stmt, 3));
864 bookmark->name = g_strdup((const char *)sqlite3_column_text(stmt, 4));
866 if (callback((media_bookmark_h)bookmark, user_data) == false) {
867 media_bookmark_destroy((media_bookmark_h)bookmark);
871 media_bookmark_destroy((media_bookmark_h)bookmark);
874 SQLITE3_FINALIZE(stmt);
880 int _media_db_get_face(const char *media_id, filter_h filter, media_face_cb callback, void *user_data)
882 int ret = MEDIA_CONTENT_ERROR_NONE;
883 char *select_query = NULL;
884 char *condition_query = NULL;
885 char *option_query = NULL;
886 sqlite3_stmt *stmt = NULL;
887 filter_s *_filter = (filter_s *)filter;
889 #ifdef _USE_TVPD_MODE
890 if (STRING_VALID(media_id)) { //get face by media_id
891 if (_filter && STRING_VALID(_filter->storage_id))
892 select_query = g_strdup_printf(SELECT_FACE_LIST_BY_MEDIA_ID, _filter->storage_id, media_id);
894 select_query = g_strdup_printf(SELECT_FACE_LIST_BY_MEDIA_ID, DB_VIEW_MEDIA, media_id);
896 if (_filter && STRING_VALID(_filter->storage_id))
897 select_query = g_strdup_printf(SELECT_FACE_LIST, _filter->storage_id);
899 select_query = g_strdup_printf(SELECT_FACE_LIST, DB_VIEW_MEDIA);
902 if (STRING_VALID(media_id)) { //get face by media_id
903 select_query = g_strdup_printf(SELECT_FACE_LIST_BY_MEDIA_ID, media_id);
905 if (_filter && STRING_VALID(_filter->storage_id))
906 select_query = g_strdup_printf(SELECT_FACE_LIST_BY_STORAGE_ID, _filter->storage_id);
908 select_query = g_strdup(SELECT_FACE_LIST);
911 ret = __media_db_make_query(filter, &condition_query, &option_query);
912 if (ret != MEDIA_CONTENT_ERROR_NONE) {
913 g_free(select_query);
917 ret = _content_query_prepare(select_query, condition_query, option_query, &stmt);
918 g_free(select_query);
919 g_free(condition_query);
920 g_free(option_query);
921 content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
923 while (sqlite3_step(stmt) == SQLITE_ROW) {
924 media_face_s *face = g_new0(media_face_s, 1);
926 face->face_id = sqlite3_column_int(stmt, 0);
927 face->media_id = g_strdup((const char *)sqlite3_column_text(stmt, 1));
928 face->face_rect_x = sqlite3_column_int(stmt, 2);
929 face->face_rect_y = sqlite3_column_int(stmt, 3);
930 face->face_rect_w = sqlite3_column_int(stmt, 4);
931 face->face_rect_h = sqlite3_column_int(stmt, 5);
932 face->orientation = sqlite3_column_int(stmt, 6);
933 face->face_tag = g_strdup((const char *)sqlite3_column_text(stmt, 7));
935 if (callback((media_face_h)face, user_data) == false) {
936 media_face_destroy((media_face_h)face);
940 media_face_destroy((media_face_h)face);
943 SQLITE3_FINALIZE(stmt);
949 int _media_db_get_group_item_count_by_id(int group_id, filter_h filter, group_list_e group_type, int *item_count)
951 int ret = MEDIA_CONTENT_ERROR_NONE;
952 sqlite3_stmt *stmt = NULL;
953 char *select_query = NULL;
954 char *condition_query = NULL;
955 char *option_query = NULL;
956 filter_s *_filter = (filter_s *)filter;
958 switch (group_type) {
959 case MEDIA_GROUP_ALBUM:
960 #ifdef _USE_TVPD_MODE
961 if (_filter && STRING_VALID(_filter->storage_id))
962 select_query = g_strdup_printf(SELECT_MEDIA_COUNT_FROM_ALBUM, _filter->storage_id, group_id);
964 select_query = g_strdup_printf(SELECT_MEDIA_COUNT_FROM_ALBUM, DB_VIEW_MEDIA, group_id);
966 if (_filter && STRING_VALID(_filter->storage_id))
967 select_query = g_strdup_printf(SELECT_MEDIA_COUNT_FROM_ALBUM_BY_STORAGE_ID, group_id, _filter->storage_id);
969 select_query = g_strdup_printf(SELECT_MEDIA_COUNT_FROM_ALBUM, group_id);
973 case MEDIA_GROUP_PLAYLIST:
974 select_query = g_strdup_printf(SELECT_MEDIA_COUNT_FROM_PLAYLIST, group_id);
977 case MEDIA_GROUP_TAG:
978 select_query = g_strdup_printf(SELECT_MEDIA_COUNT_FROM_TAG, group_id);
982 content_error("INVALID_PARAMETER");
983 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
986 ret = __media_db_make_query(filter, &condition_query, &option_query);
987 if (ret != MEDIA_CONTENT_ERROR_NONE) {
988 g_free(select_query);
992 ret = _content_query_prepare(select_query, condition_query, option_query, &stmt);
993 g_free(select_query);
994 g_free(condition_query);
995 g_free(option_query);
996 content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
998 if (sqlite3_step(stmt) == SQLITE_ROW)
999 *item_count = sqlite3_column_int(stmt, 0);
1001 SQLITE3_FINALIZE(stmt);
1006 int _media_db_get_group_item_count(const char *group_name, filter_h filter, group_list_e group_type, int *item_count)
1008 int ret = MEDIA_CONTENT_ERROR_NONE;
1009 sqlite3_stmt *stmt = NULL;
1010 char *select_query = NULL;
1011 char *condition_query = NULL;
1012 char *option_query = NULL;
1013 char *tmp_option = NULL;
1014 bool need_bracket = false;
1015 filter_s *_filter = (filter_s *)filter;
1017 switch (group_type) {
1018 case MEDIA_GROUP_NONE:
1020 #ifdef _USE_TVPD_MODE
1021 select_query = g_strdup_printf(SELECT_MEDIA_COUNT_FROM_MEDIA_SIMPLE, DB_VIEW_MEDIA);
1023 select_query = g_strdup(SELECT_MEDIA_COUNT_FROM_MEDIA_SIMPLE);
1028 if (_filter->offset < 0 && _filter->count < 0) {
1029 #ifdef _USE_TVPD_MODE
1030 if (STRING_VALID(_filter->storage_id))
1031 select_query = g_strdup_printf(SELECT_MEDIA_COUNT_FROM_MEDIA_SIMPLE, _filter->storage_id);
1033 select_query = g_strdup_printf(SELECT_MEDIA_COUNT_FROM_MEDIA_SIMPLE, DB_VIEW_MEDIA);
1035 if (STRING_VALID(_filter->storage_id))
1036 select_query = g_strdup_printf(SELECT_MEDIA_COUNT_FROM_MEDIA_SIMPLE_BY_STORAGE_ID, _filter->storage_id);
1038 select_query = g_strdup(SELECT_MEDIA_COUNT_FROM_MEDIA_SIMPLE);
1041 #ifdef _USE_TVPD_MODE
1042 if (STRING_VALID(_filter->storage_id))
1043 select_query = g_strdup_printf(SELECT_MEDIA_COUNT_FROM_MEDIA, _filter->storage_id);
1045 select_query = g_strdup_printf(SELECT_MEDIA_COUNT_FROM_MEDIA, DB_VIEW_MEDIA);
1047 if (STRING_VALID(_filter->storage_id))
1048 select_query = g_strdup_printf(SELECT_MEDIA_COUNT_FROM_MEDIA_BY_STORAGE_ID, _filter->storage_id);
1050 select_query = g_strdup(SELECT_MEDIA_COUNT_FROM_MEDIA);
1052 need_bracket = true;
1056 case MEDIA_GROUP_FOLDER:
1057 #ifdef _USE_TVPD_MODE
1058 if (_filter && STRING_VALID(_filter->storage_id))
1059 select_query = g_strdup_printf(SELECT_MEDIA_COUNT_FROM_FOLDER, _filter->storage_id, group_name);
1061 select_query = g_strdup_printf(SELECT_MEDIA_COUNT_FROM_FOLDER, DB_VIEW_MEDIA, group_name);
1063 if (_filter && STRING_VALID(_filter->storage_id))
1064 select_query = g_strdup_printf(SELECT_MEDIA_COUNT_FROM_FOLDER_BY_STORAGE_ID, group_name, _filter->storage_id);
1066 select_query = g_strdup_printf(SELECT_MEDIA_COUNT_FROM_FOLDER, group_name);
1070 case MEDIA_GROUP_TAG_BY_MEDIA_ID:
1071 select_query = g_strdup_printf(SELECT_TAG_COUNT_BY_MEDIA_ID, group_name);
1074 case MEDIA_GROUP_BOOKMARK_BY_MEDIA_ID:
1075 #ifdef _USE_TVPD_MODE
1076 if (_filter && STRING_VALID(_filter->storage_id))
1077 select_query = g_strdup_printf(SELECT_BOOKMARK_COUNT_BY_MEDIA_ID, _filter->storage_id, group_name);
1079 select_query = g_strdup_printf(SELECT_BOOKMARK_COUNT_BY_MEDIA_ID, DB_VIEW_MEDIA, group_name);
1081 select_query = g_strdup_printf(SELECT_BOOKMARK_COUNT_BY_MEDIA_ID, group_name);
1085 case MEDIA_GROUP_STORAGE:
1086 #ifdef _USE_TVPD_MODE
1087 select_query = g_strdup_printf(SELECT_MEDIA_COUNT_FROM_STORAGE, group_name, group_name);
1089 select_query = g_strdup_printf(SELECT_MEDIA_COUNT_FROM_STORAGE, group_name);
1093 case MEDIA_GROUP_FACE_BY_MEDIA_ID:
1094 #ifdef _USE_TVPD_MODE
1095 if (_filter && STRING_VALID(_filter->storage_id))
1096 select_query = g_strdup_printf(SELECT_FACE_COUNT_BY_MEDIA_ID, _filter->storage_id, group_name);
1098 select_query = g_strdup_printf(SELECT_FACE_COUNT_BY_MEDIA_ID, DB_VIEW_MEDIA, group_name);
1100 select_query = g_strdup_printf(SELECT_FACE_COUNT_BY_MEDIA_ID, group_name);
1104 #ifdef _USE_TVPD_MODE
1105 case MEDIA_GROUP_PVR:
1106 if (_filter && STRING_VALID(_filter->storage_id))
1107 select_query = g_strdup_printf(SELECT_PVR_COUNT_BY_STORAGE_ID, _filter->storage_id);
1109 select_query = g_strdup(SELECT_PVR_COUNT);
1112 case MEDIA_GROUP_UHD:
1113 if (_filter && STRING_VALID(_filter->storage_id))
1114 select_query = g_strdup_printf(SELECT_UHD_COUNT_BY_STORAGE_ID, _filter->storage_id);
1116 select_query = g_strdup(SELECT_UHD_COUNT);
1120 content_error("INVALID_PARAMETER");
1121 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1124 ret = __media_db_make_query(filter, &condition_query, &option_query);
1125 if (ret != MEDIA_CONTENT_ERROR_NONE) {
1126 g_free(select_query);
1131 tmp_option = g_strconcat(option_query, ")", NULL);
1132 g_free(option_query);
1133 option_query = tmp_option;
1136 ret = _content_query_prepare(select_query, condition_query, option_query, &stmt);
1137 g_free(select_query);
1138 g_free(condition_query);
1139 g_free(option_query);
1140 content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
1142 if (sqlite3_step(stmt) == SQLITE_ROW)
1143 *item_count = sqlite3_column_int(stmt, 0);
1145 SQLITE3_FINALIZE(stmt);
1150 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)
1152 int ret = MEDIA_CONTENT_ERROR_NONE;
1153 char *select_query = NULL;
1154 char *condition_query = NULL;
1155 char *option_query = NULL;
1156 sqlite3_stmt *stmt = NULL;
1157 filter_s *_filter = (filter_s *)filter;
1159 switch (group_type) {
1160 case MEDIA_GROUP_ALBUM:
1161 #ifdef _USE_TVPD_MODE
1162 if (_filter && STRING_VALID(_filter->storage_id))
1163 select_query = g_strdup_printf(SELECT_MEDIA_FROM_ALBUM, _filter->storage_id, group_id);
1165 select_query = g_strdup_printf(SELECT_MEDIA_FROM_ALBUM, DB_VIEW_MEDIA, group_id);
1167 if (_filter && STRING_VALID(_filter->storage_id))
1168 select_query = g_strdup_printf(SELECT_MEDIA_FROM_ALBUM_BY_STORAGE_ID, group_id, _filter->storage_id);
1170 select_query = g_strdup_printf(SELECT_MEDIA_FROM_ALBUM, group_id);
1174 case MEDIA_GROUP_PLAYLIST:
1175 #ifdef _USE_TVPD_MODE
1176 if (_filter && STRING_VALID(_filter->storage_id))
1177 select_query = g_strdup_printf(SELECT_MEDIA_FROM_PLAYLIST, _filter->storage_id, group_id);
1179 select_query = g_strdup_printf(SELECT_MEDIA_FROM_PLAYLIST, DB_VIEW_MEDIA, group_id);
1181 if (_filter && STRING_VALID(_filter->storage_id))
1182 select_query = g_strdup_printf(SELECT_MEDIA_FROM_PLAYLIST_BY_STORAGE_ID, group_id, _filter->storage_id);
1184 select_query = g_strdup_printf(SELECT_MEDIA_FROM_PLAYLIST, group_id);
1188 case MEDIA_GROUP_TAG:
1189 #ifdef _USE_TVPD_MODE
1190 if (_filter && STRING_VALID(_filter->storage_id))
1191 select_query = g_strdup_printf(SELECT_MEDIA_FROM_TAG, _filter->storage_id, group_id);
1193 select_query = g_strdup_printf(SELECT_MEDIA_FROM_TAG, DB_VIEW_MEDIA, group_id);
1195 if (_filter && STRING_VALID(_filter->storage_id))
1196 select_query = g_strdup_printf(SELECT_MEDIA_FROM_TAG_BY_STORAGE_ID, group_id, _filter->storage_id);
1198 select_query = g_strdup_printf(SELECT_MEDIA_FROM_TAG, group_id);
1203 content_error("INVALID_PARAMETER");
1204 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1207 ret = __media_db_make_query(filter, &condition_query, &option_query);
1208 if (ret != MEDIA_CONTENT_ERROR_NONE) {
1209 g_free(select_query);
1213 ret = _content_query_prepare(select_query, condition_query, option_query, &stmt);
1214 g_free(select_query);
1215 g_free(condition_query);
1216 g_free(option_query);
1217 content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
1219 while (sqlite3_step(stmt) == SQLITE_ROW) {
1220 media_info_s *item = g_new0(media_info_s, 1);
1222 _media_info_item_get_detail(stmt, (media_info_h)item);
1224 if (callback((media_info_h)item, user_data) == false) {
1225 media_info_destroy((media_info_h)item);
1229 media_info_destroy((media_info_h)item);
1232 SQLITE3_FINALIZE(stmt);
1237 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)
1239 int ret = MEDIA_CONTENT_ERROR_NONE;
1240 char *select_query = NULL;
1241 char *condition_query = NULL;
1242 char *option_query = NULL;
1243 sqlite3_stmt *stmt = NULL;
1244 filter_s *_filter = (filter_s *)filter;
1246 switch (group_type) {
1247 case MEDIA_GROUP_NONE:
1248 #ifdef _USE_TVPD_MODE
1249 if (_filter && STRING_VALID(_filter->storage_id))
1250 select_query = g_strdup_printf(SELECT_MEDIA_ITEM, _filter->storage_id);
1252 select_query = g_strdup_printf(SELECT_MEDIA_ITEM, DB_VIEW_MEDIA);
1254 if (_filter && STRING_VALID(_filter->storage_id))
1255 select_query = g_strdup_printf(SELECT_MEDIA_ITEM_BY_STORAGE_ID, _filter->storage_id);
1257 select_query = g_strdup(SELECT_MEDIA_ITEM);
1261 case MEDIA_GROUP_FOLDER:
1262 #ifdef _USE_TVPD_MODE
1263 if (_filter && STRING_VALID(_filter->storage_id))
1264 select_query = g_strdup_printf(SELECT_MEDIA_FROM_FOLDER, _filter->storage_id, group_name);
1266 select_query = g_strdup_printf(SELECT_MEDIA_FROM_FOLDER, DB_VIEW_MEDIA, group_name);
1268 select_query = g_strdup_printf(SELECT_MEDIA_FROM_FOLDER, group_name);
1272 case MEDIA_GROUP_STORAGE:
1273 #ifdef _USE_TVPD_MODE
1274 select_query = g_strdup_printf(SELECT_MEDIA_FROM_STORAGE, group_name, group_name);
1276 select_query = g_strdup_printf(SELECT_MEDIA_FROM_STORAGE, group_name);
1281 content_error("INVALID_PARAMETER");
1282 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1285 ret = __media_db_make_query(filter, &condition_query, &option_query);
1286 if (ret != MEDIA_CONTENT_ERROR_NONE) {
1287 g_free(select_query);
1291 ret = _content_query_prepare(select_query, condition_query, option_query, &stmt);
1292 g_free(select_query);
1293 g_free(condition_query);
1294 g_free(option_query);
1295 content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
1297 while (sqlite3_step(stmt) == SQLITE_ROW) {
1298 media_info_s *item = g_new0(media_info_s, 1);
1300 _media_info_item_get_detail(stmt, (media_info_h)item);
1302 if (callback((media_info_h)item, user_data) == false) {
1303 media_info_destroy((media_info_h)item);
1307 media_info_destroy((media_info_h)item);
1310 SQLITE3_FINALIZE(stmt);
1315 int _media_db_get_media_group_item_count(const char *group_name, filter_h filter, media_group_e group, int *item_count)
1317 int ret = MEDIA_CONTENT_ERROR_NONE;
1318 sqlite3_stmt *stmt = NULL;
1319 char select_query[MAX_QUERY_SIZE] = {0, };
1320 char *tmp_option = NULL;
1321 char *condition_query = NULL;
1322 char *option_query = NULL;
1323 filter_s *_filter = (filter_s *)filter;
1325 #ifdef _USE_TVPD_MODE
1326 if (group < MEDIA_PVR_GROUP_DURATION) { /*media content */
1328 if (_filter && STRING_VALID(_filter->storage_id))
1329 sqlite3_snprintf(sizeof(select_query), select_query, SELECT_MEDIA_COUNT_FROM_GROUP, _filter->storage_id, __media_db_get_group_name(group), group_name);
1331 sqlite3_snprintf(sizeof(select_query), select_query, SELECT_MEDIA_COUNT_FROM_GROUP, DB_VIEW_MEDIA, __media_db_get_group_name(group), group_name);
1333 if (_filter && STRING_VALID(_filter->storage_id))
1334 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_COUNT_FROM_GROUP_NULL, _filter->storage_id, __media_db_get_group_name(group));
1336 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_COUNT_FROM_GROUP_NULL, DB_VIEW_MEDIA, __media_db_get_group_name(group));
1338 } else if (group < MEDIA_UHD_GROUP_CONTENT_TITLE) {/*pvr content*/
1340 if (_filter && STRING_VALID(_filter->storage_id))
1341 sqlite3_snprintf(sizeof(select_query), select_query, SELECT_PVR_COUNT_FROM_GROUP_BY_STORAGE_ID, _filter->storage_id, __media_db_get_group_name(group), group_name);
1343 sqlite3_snprintf(sizeof(select_query), select_query, SELECT_PVR_COUNT_FROM_GROUP, __media_db_get_group_name(group), group_name);
1345 if (_filter && STRING_VALID(_filter->storage_id))
1346 snprintf(select_query, sizeof(select_query), SELECT_PVR_COUNT_FROM_GROUP_NULL_BY_STORAGE_ID, _filter->storage_id, __media_db_get_group_name(group));
1348 snprintf(select_query, sizeof(select_query), SELECT_PVR_COUNT_FROM_GROUP_NULL, __media_db_get_group_name(group));
1350 } else {/*uhd content*/
1352 if (_filter && STRING_VALID(_filter->storage_id))
1353 sqlite3_snprintf(sizeof(select_query), select_query, SELECT_UHD_COUNT_FROM_GROUP_BY_STORAGE_ID, _filter->storage_id, __media_db_get_group_name(group), group_name);
1355 sqlite3_snprintf(sizeof(select_query), select_query, SELECT_UHD_COUNT_FROM_GROUP, __media_db_get_group_name(group), group_name);
1357 if (_filter && STRING_VALID(_filter->storage_id))
1358 snprintf(select_query, sizeof(select_query), SELECT_UHD_COUNT_FROM_GROUP_NULL_BY_STORAGE_ID, _filter->storage_id, __media_db_get_group_name(group));
1360 snprintf(select_query, sizeof(select_query), SELECT_UHD_COUNT_FROM_GROUP_NULL, __media_db_get_group_name(group));
1365 if (_filter && STRING_VALID(_filter->storage_id))
1366 sqlite3_snprintf(sizeof(select_query), select_query, SELECT_MEDIA_COUNT_FROM_GROUP_BY_STORAGE_ID, __media_db_get_group_name(group), group_name, _filter->storage_id);
1368 sqlite3_snprintf(sizeof(select_query), select_query, SELECT_MEDIA_COUNT_FROM_GROUP, __media_db_get_group_name(group), group_name);
1370 if (_filter && STRING_VALID(_filter->storage_id))
1371 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_COUNT_FROM_GROUP_NULL_BY_STORAGE_ID, __media_db_get_group_name(group), _filter->storage_id);
1373 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_COUNT_FROM_GROUP_NULL, __media_db_get_group_name(group));
1376 ret = __media_db_make_query(filter, &condition_query, &option_query);
1377 content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
1379 /* If 'filter' is not NULL, 'option_query' must be created. */
1381 tmp_option = g_strconcat(option_query, ")", NULL);
1382 g_free(option_query);
1383 option_query = tmp_option;
1385 SAFE_STRLCAT(select_query, ")", sizeof(select_query));
1388 ret = _content_query_prepare(select_query, condition_query, option_query, &stmt);
1389 g_free(condition_query);
1390 g_free(option_query);
1391 content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
1393 if (sqlite3_step(stmt) == SQLITE_ROW)
1394 *item_count = sqlite3_column_int(stmt, 0);
1396 SQLITE3_FINALIZE(stmt);
1401 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)
1403 int ret = MEDIA_CONTENT_ERROR_NONE;
1404 char select_query[MAX_QUERY_SIZE] = {0, };
1405 char *condition_query = NULL;
1406 char *option_query = NULL;
1407 sqlite3_stmt *stmt = NULL;
1408 filter_s *_filter = (filter_s *)filter;
1410 #ifdef _USE_TVPD_MODE
1412 if (_filter && STRING_VALID(_filter->storage_id))
1413 sqlite3_snprintf(sizeof(select_query), select_query, SELECT_MEDIA_FROM_GROUP, _filter->storage_id, __media_db_get_group_name(group), group_name);
1415 sqlite3_snprintf(sizeof(select_query), select_query, SELECT_MEDIA_FROM_GROUP, DB_VIEW_MEDIA, __media_db_get_group_name(group), group_name);
1417 if (_filter && STRING_VALID(_filter->storage_id))
1418 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_GROUP_NULL, _filter->storage_id, __media_db_get_group_name(group));
1420 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_GROUP_NULL, DB_VIEW_MEDIA, __media_db_get_group_name(group));
1424 if (_filter && STRING_VALID(_filter->storage_id))
1425 sqlite3_snprintf(sizeof(select_query), select_query, SELECT_MEDIA_FROM_GROUP_BY_STORAGE_ID, __media_db_get_group_name(group), group_name, _filter->storage_id);
1427 sqlite3_snprintf(sizeof(select_query), select_query, SELECT_MEDIA_FROM_GROUP, __media_db_get_group_name(group), group_name);
1429 if (_filter && STRING_VALID(_filter->storage_id))
1430 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_GROUP_NULL_BY_STORAGE_ID, __media_db_get_group_name(group), _filter->storage_id);
1432 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_GROUP_NULL, __media_db_get_group_name(group));
1435 ret = __media_db_make_query(filter, &condition_query, &option_query);
1436 content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
1438 ret = _content_query_prepare(select_query, condition_query, option_query, &stmt);
1439 g_free(condition_query);
1440 g_free(option_query);
1441 content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
1443 while (sqlite3_step(stmt) == SQLITE_ROW) {
1444 media_info_s *item = g_new0(media_info_s, 1);
1446 _media_info_item_get_detail(stmt, (media_info_h)item);
1448 if (callback((media_info_h)item, user_data) == false) {
1449 media_info_destroy((media_info_h)item);
1453 media_info_destroy((media_info_h)item);
1456 SQLITE3_FINALIZE(stmt);
1461 int _media_db_get_storage(filter_h filter, media_storage_cb callback, void *user_data)
1463 int ret = MEDIA_CONTENT_ERROR_NONE;
1464 char *condition_query = NULL;
1465 char *option_query = NULL;
1466 sqlite3_stmt *stmt = NULL;
1468 ret = __media_db_make_query(filter, &condition_query, &option_query);
1469 content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
1471 ret = _content_query_prepare(SELECT_STORAGE_LIST, condition_query, option_query, &stmt);
1472 g_free(condition_query);
1473 g_free(option_query);
1474 content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
1476 while (sqlite3_step(stmt) == SQLITE_ROW) {
1477 media_storage_s *_storage = g_new0(media_storage_s, 1);
1479 _storage->storage_id = g_strdup((const char *)sqlite3_column_text(stmt, 0));
1480 _storage->storage_path = g_strdup((const char *)sqlite3_column_text(stmt, 1));
1481 _storage->storage_type = sqlite3_column_int(stmt, 2);
1483 if (callback((media_storage_h)_storage, user_data) == false) {
1484 media_storage_destroy((media_storage_h) _storage);
1488 media_storage_destroy((media_storage_h) _storage);
1491 SQLITE3_FINALIZE(stmt);
1496 int _media_db_get_storage_id_by_media_id(const char *media_id, char **storage_id)
1498 int ret = MEDIA_CONTENT_ERROR_NONE;
1499 sqlite3_stmt *stmt = NULL;
1500 char *select_query = NULL;
1502 select_query = sqlite3_mprintf(SELECT_MEDIA_STORAGE_ID_BY_ID, media_id);
1504 ret = _content_get_result(select_query, &stmt);
1505 SQLITE3_SAFE_FREE(select_query);
1506 content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
1508 if (sqlite3_step(stmt) == SQLITE_ROW) {
1509 *storage_id = g_strdup((const char *)sqlite3_column_text(stmt, 0));
1511 content_error("Invalid media_id[%s]", media_id);
1512 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1515 SQLITE3_FINALIZE(stmt);
1520 #ifdef _USE_TVPD_MODE
1521 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)
1523 int ret = MEDIA_CONTENT_ERROR_NONE;
1524 char select_query[DEFAULT_QUERY_SIZE] = {0, };
1525 char *condition_query = NULL;
1526 char *option_query = NULL;
1527 sqlite3_stmt *stmt = NULL;
1528 filter_s *_filter = (filter_s *)filter;
1531 if (_filter && STRING_VALID(_filter->storage_id))
1532 sqlite3_snprintf(sizeof(select_query), select_query, SELECT_PVR_FROM_GROUP_BY_STORAGE_ID, _filter->storage_id, __media_db_get_group_name(group), group_name);
1534 sqlite3_snprintf(sizeof(select_query), select_query, SELECT_PVR_FROM_GROUP, __media_db_get_group_name(group), group_name);
1536 if (_filter && STRING_VALID(_filter->storage_id))
1537 snprintf(select_query, sizeof(select_query), SELECT_PVR_FROM_GROUP_NULL_BY_STORAGE_ID, _filter->storage_id, __media_db_get_group_name(group));
1539 snprintf(select_query, sizeof(select_query), SELECT_PVR_FROM_GROUP_NULL, __media_db_get_group_name(group));
1542 ret = __media_db_make_query(filter, &condition_query, &option_query);
1543 content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
1545 ret = _content_query_prepare(select_query, condition_query, option_query, &stmt);
1546 g_free(condition_query);
1547 g_free(option_query);
1548 content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
1550 while (sqlite3_step(stmt) == SQLITE_ROW) {
1551 media_pvr_s *item = g_new0(media_pvr_s, 1);
1553 _media_pvr_item_get_detail(stmt, (media_pvr_h)item);
1555 if (callback((media_pvr_h)item, user_data) == false) {
1556 media_info_destroy((media_pvr_h)item);
1560 media_pvr_destroy((media_pvr_h)item);
1563 SQLITE3_FINALIZE(stmt);
1569 MEDIA_PVR_MEDIA_ID = 0,
1570 MEDIA_PVR_STORAGE_ID,
1574 MEDIA_PVR_TIME_ZONE,
1578 MEDIA_PVR_CHANNEL_TYPE,
1579 MEDIA_PVR_CHANNEL_NAME,
1580 MEDIA_PVR_CHANNEL_NUM,
1581 MEDIA_PVR_SERVICE_PROFILE,
1582 MEDIA_PVR_PROGRAM_TITLE,
1583 MEDIA_PVR_PROGRAM_NUM,
1584 MEDIA_PVR_PROGRAM_CRID,
1589 MEDIA_PVR_EMBARGO_TIME,
1590 MEDIA_PVR_EXPIRY_TIME,
1591 MEDIA_PVR_START_TIME,
1592 MEDIA_PVR_PROGRAM_START_TIME,
1593 MEDIA_PVR_PROGRAM_END_TIME,
1594 MEDIA_PVR_PROGRAM_DATE,
1595 MEDIA_PVR_PARENTAL_RATING,
1596 MEDIA_PVR_TIMER_RECORD,
1597 MEDIA_PVR_SERIES_RECORD,
1602 MEDIA_PVR_HARDOF_HEARINGRADIO,
1603 MEDIA_PVR_DATA_SERVICE,
1604 MEDIA_PVR_CONTENT_LOCK,
1605 MEDIA_PVR_CONTENT_WATCH,
1606 MEDIA_PVR_HAS_AUDIO_ONLY,
1607 MEDIA_PVR_IS_LOCAL_RECORDED,
1608 MEDIA_PVR_RESOLUTION,
1609 MEDIA_PVR_ASPECTRATIO,
1610 MEDIA_PVR_MODIFIED_MONTH,
1611 MEDIA_PVR_SPORTS_TYPE,
1612 MEDIA_PVR_GUIDANCE_LENGTH,
1614 MEDIA_PVR_PLAY_COUNT,
1615 MEDIA_PVR_PRIVATE_DATA,
1616 MEDIA_PVR_HIGHLIGHT,
1617 } media_pvr_field_e;
1619 void _media_pvr_item_get_detail(sqlite3_stmt* stmt, media_pvr_h pvr)
1621 media_pvr_s *_pvr = (media_pvr_s*)pvr;
1623 _pvr->media_id = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_PVR_MEDIA_ID));
1624 _pvr->storage_id = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_PVR_STORAGE_ID));
1625 _pvr->path = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_PVR_PATH));
1626 _pvr->size = (unsigned long long)sqlite3_column_int64(stmt, MEDIA_PVR_SIZE);
1627 _pvr->duration = sqlite3_column_int(stmt, MEDIA_PVR_DURATION);
1628 _pvr->timezone = sqlite3_column_int(stmt, MEDIA_PVR_TIME_ZONE);
1629 _pvr->ptc = sqlite3_column_int(stmt, MEDIA_PVR_PTC);
1630 _pvr->major = sqlite3_column_int(stmt, MEDIA_PVR_MAJOR);
1631 _pvr->minor = sqlite3_column_int(stmt, MEDIA_PVR_MINOR);
1632 _pvr->channel_type = sqlite3_column_int(stmt, MEDIA_PVR_CHANNEL_TYPE);
1633 _pvr->service_profile = (unsigned int)sqlite3_column_int(stmt, MEDIA_PVR_SERVICE_PROFILE);
1634 _pvr->channel_name = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_PVR_CHANNEL_NAME));
1635 _pvr->channel_num = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_PVR_CHANNEL_NUM));
1636 _pvr->program_title = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_PVR_PROGRAM_TITLE));
1637 _pvr->program_num = sqlite3_column_int(stmt, MEDIA_PVR_PROGRAM_NUM);
1638 _pvr->program_crid = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_PVR_PROGRAM_CRID));
1639 _pvr->guidance = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_PVR_GUIDANCE));
1640 _pvr->synopsis = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_PVR_SYNOPSIS));
1641 _pvr->genre = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_PVR_GENRE));
1642 _pvr->language = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_PVR_LANGUAGE));
1643 _pvr->modified_month = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_PVR_MODIFIED_MONTH));
1644 _pvr->private_data = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_PVR_PRIVATE_DATA));
1645 _pvr->embargo_time = sqlite3_column_int(stmt, MEDIA_PVR_EMBARGO_TIME);
1646 _pvr->expiry_time = sqlite3_column_int(stmt, MEDIA_PVR_EXPIRY_TIME);
1647 _pvr->start_time = sqlite3_column_int(stmt, MEDIA_PVR_START_TIME);
1648 _pvr->program_start_time = sqlite3_column_int(stmt, MEDIA_PVR_PROGRAM_START_TIME);
1649 _pvr->program_end_time = sqlite3_column_int(stmt, MEDIA_PVR_PROGRAM_END_TIME);
1650 _pvr->program_date = sqlite3_column_int(stmt, MEDIA_PVR_PROGRAM_DATE);
1651 _pvr->parental_rating = sqlite3_column_int(stmt, MEDIA_PVR_PARENTAL_RATING);
1652 _pvr->timer_record = sqlite3_column_int(stmt, MEDIA_PVR_TIMER_RECORD);
1653 _pvr->series_record = sqlite3_column_int(stmt, MEDIA_PVR_SERIES_RECORD);
1654 _pvr->hd = sqlite3_column_int(stmt, MEDIA_PVR_HD);
1655 _pvr->subtitle = sqlite3_column_int(stmt, MEDIA_PVR_SUBTITLE);
1656 _pvr->ttx = sqlite3_column_int(stmt, MEDIA_PVR_TTX);
1657 _pvr->ad = sqlite3_column_int(stmt, MEDIA_PVR_AD);
1658 _pvr->hard_of_hearing_radio = sqlite3_column_int(stmt, MEDIA_PVR_HARDOF_HEARINGRADIO);
1659 _pvr->data_service = sqlite3_column_int(stmt, MEDIA_PVR_DATA_SERVICE);
1660 _pvr->content_lock = sqlite3_column_int(stmt, MEDIA_PVR_CONTENT_LOCK);
1661 _pvr->content_watch = sqlite3_column_int(stmt, MEDIA_PVR_CONTENT_WATCH);
1662 _pvr->has_audio_only = sqlite3_column_int(stmt, MEDIA_PVR_HAS_AUDIO_ONLY);
1663 _pvr->is_local_record = sqlite3_column_int(stmt, MEDIA_PVR_IS_LOCAL_RECORDED);
1664 _pvr->resolution = sqlite3_column_int(stmt, MEDIA_PVR_RESOLUTION);
1665 _pvr->aspectratio = sqlite3_column_int(stmt, MEDIA_PVR_ASPECTRATIO);
1666 _pvr->sports_type = sqlite3_column_int(stmt, MEDIA_PVR_SPORTS_TYPE);
1667 _pvr->guidance_length = sqlite3_column_int(stmt, MEDIA_PVR_GUIDANCE_LENGTH);
1668 _pvr->tvmode = sqlite3_column_int(stmt, MEDIA_PVR_TVMODE);
1669 _pvr->play_count = sqlite3_column_int(stmt, MEDIA_PVR_PLAY_COUNT);
1670 _pvr->highlight = sqlite3_column_int(stmt, MEDIA_PVR_HIGHLIGHT);
1675 int _media_db_get_pvr(filter_h filter, media_pvr_cb callback, void *user_data)
1677 int ret = MEDIA_CONTENT_ERROR_NONE;
1678 char select_query[DEFAULT_QUERY_SIZE] = {0, };
1679 char *condition_query = NULL;
1680 char *option_query = NULL;
1681 sqlite3_stmt *stmt = NULL;
1682 filter_s *_filter = (filter_s *)filter;
1684 if (_filter && STRING_VALID(_filter->storage_id))
1685 snprintf(select_query, sizeof(select_query), SELECT_PVR_LIST_BY_STORAGE_ID, _filter->storage_id);
1687 SAFE_STRLCAT(select_query, SELECT_PVR_LIST, sizeof(select_query));
1689 ret = __media_db_make_query(filter, &condition_query, &option_query);
1690 content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
1692 ret = _content_query_prepare(select_query, condition_query, option_query, &stmt);
1693 g_free(condition_query);
1694 g_free(option_query);
1695 content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
1697 while (sqlite3_step(stmt) == SQLITE_ROW) {
1698 media_pvr_s *_pvr = g_new0(media_pvr_s, 1);
1700 _media_pvr_item_get_detail(stmt, (media_pvr_h)_pvr);
1702 if (callback((media_pvr_h)_pvr, user_data) == false) {
1703 media_pvr_destroy((media_pvr_h) _pvr);
1707 media_pvr_destroy((media_pvr_h) _pvr);
1710 SQLITE3_FINALIZE(stmt);
1716 MEDIA_UHD_MEDIA_ID = 0,
1717 MEDIA_UHD_STORAGE_ID,
1720 MEDIA_UHD_CONTENT_ID,
1721 MEDIA_UHD_CONTENT_TITLE,
1722 MEDIA_UHD_FILE_NAME,
1723 MEDIA_UHD_FOLDER_ID,
1724 MEDIA_UHD_RELEASE_DATE,
1725 MEDIA_UHD_MODIFIED_TIME,
1726 MEDIA_UHD_PLAYED_POSITION,
1728 MEDIA_UHD_PLAYED_COUNT,
1729 } media_uhd_field_e;
1731 void _media_uhd_item_get_detail(sqlite3_stmt* stmt, media_uhd_h uhd)
1733 media_uhd_s *_uhd = (media_uhd_s*)uhd;
1735 _uhd->media_id = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_UHD_MEDIA_ID));
1736 _uhd->storage_id = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_UHD_STORAGE_ID));
1737 _uhd->path = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_UHD_PATH));
1738 _uhd->size = (unsigned long long)sqlite3_column_int64(stmt, MEDIA_UHD_SIZE);
1739 _uhd->content_id = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_UHD_CONTENT_ID));
1740 _uhd->content_title = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_UHD_CONTENT_TITLE));
1741 _uhd->file_name = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_UHD_FILE_NAME));
1742 _uhd->release_date = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_UHD_RELEASE_DATE));
1743 _uhd->modified_time = sqlite3_column_int(stmt, MEDIA_UHD_MODIFIED_TIME);
1744 _uhd->played_position = sqlite3_column_int(stmt, MEDIA_UHD_PLAYED_POSITION);
1745 _uhd->sub_type = sqlite3_column_int(stmt, MEDIA_UHD_SUB_TYPE);
1746 _uhd->played_count = sqlite3_column_int(stmt, MEDIA_UHD_PLAYED_COUNT);
1751 int _media_db_get_uhd(filter_h filter, media_uhd_cb callback, void *user_data)
1753 int ret = MEDIA_CONTENT_ERROR_NONE;
1754 char select_query[DEFAULT_QUERY_SIZE] = {0, };
1755 char *condition_query = NULL;
1756 char *option_query = NULL;
1757 sqlite3_stmt *stmt = NULL;
1758 filter_s *_filter = (filter_s *)filter;
1760 if (_filter && STRING_VALID(_filter->storage_id))
1761 snprintf(select_query, sizeof(select_query), SELECT_UHD_LIST_BY_STORAGE_ID, _filter->storage_id);
1763 SAFE_STRLCAT(select_query, SELECT_UHD_LIST, sizeof(select_query));
1765 ret = __media_db_make_query(filter, &condition_query, &option_query);
1766 content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
1768 ret = _content_query_prepare(select_query, condition_query, option_query, &stmt);
1769 g_free(condition_query);
1770 g_free(option_query);
1771 content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
1773 while (sqlite3_step(stmt) == SQLITE_ROW) {
1774 media_uhd_s *_uhd = g_new0(media_uhd_s, 1);
1776 _media_uhd_item_get_detail(stmt, (media_uhd_h)_uhd);
1778 if (callback((media_uhd_h)_uhd, user_data) == false) {
1779 media_uhd_destroy((media_uhd_h) _uhd);
1782 media_uhd_destroy((media_uhd_h) _uhd);
1785 SQLITE3_FINALIZE(stmt);