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>
21 static char * __media_db_get_group_name(media_group_e group);
22 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);
24 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;
93 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)
95 int ret = MEDIA_CONTENT_ERROR_NONE;
96 filter_s *_filter = NULL;
100 _filter = (filter_s*)filter;
102 if(STRING_VALID(_filter->condition))
104 /*bracket should be added to condition. If application use "OR" condition, F/W restriction condition like "validity=1" is disregared
105 ex) select path from media where validity=1 and media_type=3 or media_type=1;*/
106 char bracket_added_condition[MAX_QUERY_SIZE] = {0, };
107 memset(bracket_added_condition, 0x00, sizeof(bracket_added_condition));
109 SAFE_STRLCAT(bracket_added_condition, QUERY_KEYWORD_OPEN_BRACKET, MAX_QUERY_SIZE);
110 SAFE_STRLCAT(bracket_added_condition, _filter->condition, MAX_QUERY_SIZE);
111 SAFE_STRLCAT(bracket_added_condition, QUERY_KEYWORD_BRACKET, MAX_QUERY_SIZE);
113 ret = _media_filter_attribute_generate(attr, bracket_added_condition, _filter->condition_collate_type, condition_query);
114 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
117 ret = _media_filter_attribute_option_generate(attr, filter, option_query);
118 if(ret != MEDIA_CONTENT_ERROR_NONE)
120 SAFE_FREE(*condition_query);
124 if(STRING_VALID(*condition_query))
126 SAFE_STRLCAT(select_query, QUERY_KEYWORD_SPACE, select_query_size);
127 SAFE_STRLCAT(select_query, QUERY_KEYWORD_AND, select_query_size);
134 int _media_db_get_group_count(filter_h filter, group_list_e group_type, int *group_count)
136 int ret = MEDIA_CONTENT_ERROR_NONE;
137 sqlite3_stmt *stmt = NULL;
138 char select_query[MAX_QUERY_SIZE] = {0, };
139 char *condition_query = NULL;
140 char *option_query = NULL;
141 attribute_h attr = NULL;
142 filter_s *_filter = (filter_s*)filter;
144 attr = _content_get_attirbute_handle();
145 memset(select_query, 0x00, sizeof(select_query));
148 case MEDIA_GROUP_NONE:
149 case MEDIA_GROUP_TAG_BY_MEDIA_ID:
150 case MEDIA_GROUP_BOOKMARK_BY_MEDIA_ID:
152 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
153 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
156 case MEDIA_GROUP_ALBUM:
157 attr = _content_get_alias_attirbute_handle();
159 if((_filter != NULL) && STRING_VALID(_filter->storage_id))
160 snprintf(select_query, sizeof(select_query), SELECT_ALBUM_COUNT, _filter->storage_id);
162 snprintf(select_query, sizeof(select_query), SELECT_ALBUM_COUNT, DB_TABLE_MEDIA_VIEW);
165 case MEDIA_GROUP_FOLDER:
166 attr = _content_get_alias_attirbute_handle();
167 if(!SAFE_STRLCPY(select_query, SELECT_FOLDER_COUNT, sizeof(select_query)))
169 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
170 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
173 if((_filter != NULL) && STRING_VALID(_filter->storage_id))
174 snprintf(select_query, sizeof(select_query), SELECT_FOLDER_COUNT_BY_STORAGE_ID, _filter->storage_id, _filter->storage_id);
176 snprintf(select_query, sizeof(select_query), SELECT_FOLDER_COUNT, DB_TABLE_MEDIA_VIEW);
179 case MEDIA_GROUP_PLAYLIST:
180 if(!SAFE_STRLCPY(select_query, SELECT_PLAYLIST_COUNT, sizeof(select_query)))
182 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
183 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
186 case MEDIA_GROUP_TAG:
187 if(!SAFE_STRLCPY(select_query, SELECT_TAG_COUNT, sizeof(select_query)))
189 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
190 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
193 case MEDIA_GROUP_BOOKMARK:
194 attr = _content_get_alias_attirbute_handle();
196 if((_filter != NULL) && STRING_VALID(_filter->storage_id))
197 snprintf(select_query, sizeof(select_query), SELECT_BOOKMARK_COUNT, _filter->storage_id);
199 snprintf(select_query, sizeof(select_query), SELECT_BOOKMARK_COUNT, DB_TABLE_MEDIA_VIEW);
202 case MEDIA_GROUP_STORAGE:
203 if(!SAFE_STRLCPY(select_query, SELECT_STORAGE_COUNT, sizeof(select_query)))
205 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
206 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
211 media_content_error("Invalid group type [%d]", group_type);
212 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
217 ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query);
218 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
220 ret = _content_query_prepare(&stmt, select_query, condition_query, option_query);
221 SAFE_FREE(condition_query);
222 SAFE_FREE(option_query);
223 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
225 while(sqlite3_step(stmt) == SQLITE_ROW)
227 *group_count = (int)sqlite3_column_int(stmt, 0);
230 SQLITE3_FINALIZE(stmt);
235 int _media_db_get_media_group_count(media_group_e group, filter_h filter, int *group_count)
237 int ret = MEDIA_CONTENT_ERROR_NONE;
238 sqlite3_stmt *stmt = NULL;
239 char select_query[MAX_QUERY_SIZE] = {0, };
240 char *condition_query = NULL;
241 char *option_query = NULL;
242 attribute_h attr = NULL;
243 filter_s *_filter = (filter_s*)filter;
245 attr = _content_get_attirbute_handle();
246 memset(select_query, 0x00, sizeof(select_query));
248 if((_filter != NULL) && STRING_VALID(_filter->storage_id))
249 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_GROUP_COUNT, __media_db_get_group_name(group), _filter->storage_id);
251 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_GROUP_COUNT, __media_db_get_group_name(group), DB_TABLE_MEDIA_VIEW);
253 ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query);
254 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
256 SAFE_STRLCAT(select_query, QUERY_KEYWORD_SPACE, sizeof(select_query));
257 if(STRING_VALID(condition_query))
258 SAFE_STRLCAT(select_query, condition_query, sizeof(select_query));
259 if(STRING_VALID(option_query))
260 SAFE_STRLCAT(select_query, option_query, sizeof(select_query));
261 SAFE_STRLCAT(select_query, QUERY_KEYWORD_BRACKET, sizeof(select_query));
263 SAFE_FREE(condition_query);
264 SAFE_FREE(option_query);
266 ret = _content_query_prepare(&stmt, select_query, condition_query, option_query);
267 SAFE_FREE(condition_query);
268 SAFE_FREE(option_query);
269 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
271 while(sqlite3_step(stmt) == SQLITE_ROW)
273 *group_count = (int)sqlite3_column_int(stmt, 0);
276 SQLITE3_FINALIZE(stmt);
281 int _media_db_get_media_group(media_group_e group, filter_h filter, media_group_cb callback, void *user_data)
283 int ret = MEDIA_CONTENT_ERROR_NONE;
284 char select_query[MAX_QUERY_SIZE] = {0, };
285 char *condition_query = NULL;
286 char *option_query = NULL;
288 sqlite3_stmt *stmt = NULL;
289 attribute_h attr = NULL;
290 filter_s *_filter = (filter_s*)filter;
292 attr = _content_get_attirbute_handle();
293 memset(select_query, 0x00, sizeof(select_query));
295 if((_filter != NULL) && STRING_VALID(_filter->storage_id))
296 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_GROUP_LIST, __media_db_get_group_name(group), _filter->storage_id);
298 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_GROUP_LIST, __media_db_get_group_name(group), DB_TABLE_MEDIA_VIEW);
300 ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query);
301 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
303 ret = _content_query_prepare(&stmt, select_query, condition_query, option_query);
304 SAFE_FREE(condition_query);
305 SAFE_FREE(option_query);
306 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
308 while(sqlite3_step(stmt) == SQLITE_ROW)
310 if(STRING_VALID((const char *)sqlite3_column_text(stmt, 0)))
312 name = strdup((const char *)sqlite3_column_text(stmt, 0));
315 if(callback(name, user_data) == false)
324 SQLITE3_FINALIZE(stmt);
329 int _media_db_get_album(filter_h filter, media_album_cb callback, void *user_data)
331 int ret = MEDIA_CONTENT_ERROR_NONE;
332 char select_query[MAX_QUERY_SIZE] = {0, };
333 char *condition_query = NULL;
334 char *option_query = NULL;
335 sqlite3_stmt *stmt = NULL;
336 attribute_h attr = NULL;
337 filter_s *_filter = (filter_s*)filter;
339 attr = _content_get_alias_attirbute_handle();
340 memset(select_query, 0x00, sizeof(select_query));
342 if((_filter != NULL) && STRING_VALID(_filter->storage_id))
343 snprintf(select_query, sizeof(select_query), SELECT_ALBUM_LIST, _filter->storage_id);
345 snprintf(select_query, sizeof(select_query), SELECT_ALBUM_LIST, DB_TABLE_MEDIA_VIEW);
347 ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query);
348 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
350 ret = _content_query_prepare(&stmt, select_query, condition_query, option_query);
351 SAFE_FREE(condition_query);
352 SAFE_FREE(option_query);
353 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
355 while(sqlite3_step(stmt) == SQLITE_ROW)
357 media_album_s *album = (media_album_s*)calloc(1, sizeof(media_album_s));
361 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
362 SQLITE3_FINALIZE(stmt);
363 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
366 album->album_id = (int)sqlite3_column_int(stmt, 0);
368 if(STRING_VALID((const char *)sqlite3_column_text(stmt, 1)))
369 album->name = strdup((const char *)sqlite3_column_text(stmt, 1));
371 if(STRING_VALID((const char *)sqlite3_column_text(stmt, 2)))
372 album->artist = strdup((const char *)sqlite3_column_text(stmt, 2));
374 if(STRING_VALID((const char *)sqlite3_column_text(stmt, 3)))
375 album->album_art_path = strdup((const char *)sqlite3_column_text(stmt, 3));
377 if(callback((media_album_h)album, user_data) == false)
379 media_album_destroy((media_album_h)album);
383 media_album_destroy((media_album_h)album);
386 SQLITE3_FINALIZE(stmt);
391 int _media_db_get_folder(filter_h filter, media_folder_cb callback, void *user_data)
393 int ret = MEDIA_CONTENT_ERROR_NONE;
394 char select_query[MAX_QUERY_SIZE] = {0, };
395 char *condition_query = NULL;
396 char *option_query = NULL;
397 sqlite3_stmt *stmt = NULL;
398 attribute_h attr = NULL;
399 filter_s *_filter = (filter_s*)filter;
401 attr = _content_get_alias_attirbute_handle();
402 memset(select_query, 0x00, sizeof(select_query));
404 if((_filter != NULL) && STRING_VALID(_filter->storage_id))
405 snprintf(select_query, sizeof(select_query), SELECT_FOLDER_LIST_BY_STORAGE_ID, _filter->storage_id, _filter->storage_id);
407 snprintf(select_query, sizeof(select_query), SELECT_FOLDER_LIST, DB_TABLE_MEDIA_VIEW);
409 ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query);
410 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
412 ret = _content_query_prepare(&stmt, select_query, condition_query, option_query);
414 SAFE_FREE(condition_query);
415 SAFE_FREE(option_query);
416 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
418 while(sqlite3_step(stmt) == SQLITE_ROW)
420 media_folder_s *_folder = (media_folder_s*)calloc(1, sizeof(media_folder_s));
424 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
425 SQLITE3_FINALIZE(stmt);
426 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
429 if(STRING_VALID((const char *)sqlite3_column_text(stmt, 0)))
430 _folder->folder_id = strdup((const char *)sqlite3_column_text(stmt, 0));
432 if(STRING_VALID((const char *)sqlite3_column_text(stmt, 1)))
433 _folder->path = strdup((const char *)sqlite3_column_text(stmt, 1));
435 if(STRING_VALID((const char *)sqlite3_column_text(stmt, 2)))
436 _folder->name = strdup((const char *)sqlite3_column_text(stmt, 2));
438 _folder->storage_type = (int)sqlite3_column_int(stmt, 3);
440 _folder->modified_time = (int)sqlite3_column_int(stmt, 4);
442 if(STRING_VALID((const char *)sqlite3_column_text(stmt, 5)))
443 _folder->storage_uuid = strdup((const char *)sqlite3_column_text(stmt, 5));
445 _folder->folder_order = (int)sqlite3_column_int(stmt, 6);
447 if(STRING_VALID((const char *)sqlite3_column_text(stmt, 7)))
448 _folder->parent_folder_id= strdup((const char *)sqlite3_column_text(stmt, 7));
450 if(callback((media_folder_h)_folder, user_data) == false)
452 media_folder_destroy((media_folder_h) _folder);
456 media_folder_destroy((media_folder_h) _folder);
459 SQLITE3_FINALIZE(stmt);
464 int _media_db_get_playlist(filter_h filter, media_playlist_cb callback, void *user_data)
466 int ret = MEDIA_CONTENT_ERROR_NONE;
467 char select_query[MAX_QUERY_SIZE] = {0, };
468 char *condition_query = NULL;
469 char *option_query = NULL;
470 sqlite3_stmt *stmt = NULL;
471 attribute_h attr = NULL;
473 attr = _content_get_attirbute_handle();
474 memset(select_query, 0x00, sizeof(select_query));
476 if(!SAFE_STRLCPY(select_query, SELECT_PLAYLIST_LIST, sizeof(select_query)))
478 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
479 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
482 ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query);
483 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
485 ret = _content_query_prepare(&stmt, select_query, condition_query, option_query);
486 SAFE_FREE(condition_query);
487 SAFE_FREE(option_query);
488 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
490 while(sqlite3_step(stmt) == SQLITE_ROW)
492 media_playlist_s *_playlist = (media_playlist_s*)calloc(1, sizeof(media_playlist_s));
494 if(_playlist == NULL)
496 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
497 SQLITE3_FINALIZE(stmt);
498 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
501 _playlist->playlist_id = (int)sqlite3_column_int(stmt, 0);
503 if(STRING_VALID((const char *)sqlite3_column_text(stmt, 1)))
504 _playlist->name = strdup((const char *)sqlite3_column_text(stmt, 1));
506 if(STRING_VALID((const char *)sqlite3_column_text(stmt, 2)))
507 _playlist->thumbnail_path = strdup((const char *)sqlite3_column_text(stmt, 2));
509 if(callback((media_playlist_h)_playlist, user_data) == false)
511 media_playlist_destroy((media_playlist_h)_playlist);
514 media_playlist_destroy((media_playlist_h)_playlist);
517 SQLITE3_FINALIZE(stmt);
522 int _media_db_get_playlist_item(int playlist_id, filter_h filter, playlist_member_cb callback, void *user_data)
524 int ret = MEDIA_CONTENT_ERROR_NONE;
525 char select_query[MAX_QUERY_SIZE] = {0, };
526 char *condition_query = NULL;
527 char *option_query = NULL;
528 sqlite3_stmt *stmt = NULL;
529 attribute_h attr = NULL;
531 attr = _content_get_attirbute_handle();
532 memset(select_query, 0x00, sizeof(select_query));
534 //snprintf(select_query, sizeof(select_query), SELECT_PLAYLIST_ITEM_ID_FROM_PLAYLIST_VIEW, playlist_id);
535 snprintf(select_query, sizeof(select_query), SELECT_PLAYLIST_ITEM_ALL_FROM_PLAYLIST_VIEW, playlist_id);
537 ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query);
538 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
540 ret = _content_query_prepare(&stmt, select_query, condition_query, option_query);
541 SAFE_FREE(condition_query);
542 SAFE_FREE(option_query);
543 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
545 while(sqlite3_step(stmt) == SQLITE_ROW)
547 int playlist_member_id = 0;
548 playlist_member_id = (int)sqlite3_column_int(stmt, MEDIA_INFO_ITEM_MAX); //MEDIA_INFO_ITEM_MAX is pm_id
550 media_info_s *_media = (media_info_s*)calloc(1, sizeof(media_info_s));
554 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
555 SQLITE3_FINALIZE(stmt);
556 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
559 _media_info_item_get_detail(stmt, (media_info_h)_media);
561 if(callback(playlist_member_id, (media_info_h)_media, user_data) == false)
563 media_info_destroy((media_info_h)_media);
566 media_info_destroy((media_info_h)_media);
570 SQLITE3_FINALIZE(stmt);
575 int _media_db_get_tag(const char *media_id, filter_h filter, media_tag_cb callback, void *user_data)
577 int ret = MEDIA_CONTENT_ERROR_NONE;
578 char select_query[MAX_QUERY_SIZE] = {0, };
579 char *condition_query = NULL;
580 char *option_query = NULL;
581 sqlite3_stmt *stmt = NULL;
582 attribute_h attr = NULL;
584 attr = _content_get_attirbute_handle();
585 memset(select_query, 0x00, sizeof(select_query));
587 if(!STRING_VALID(media_id))
589 if(!SAFE_STRLCPY(select_query, SELECT_TAG_LIST, sizeof(select_query)))
591 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
592 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
597 snprintf(select_query, sizeof(select_query), SELECT_TAG_LIST_BY_MEDIA_ID, media_id);
600 ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query);
601 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
603 SAFE_STRLCAT(select_query, QUERY_KEYWORD_SPACE, sizeof(select_query));
605 ret = _content_query_prepare(&stmt, select_query, condition_query, option_query);
606 SAFE_FREE(condition_query);
607 SAFE_FREE(option_query);
608 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
610 while(sqlite3_step(stmt) == SQLITE_ROW)
612 media_tag_s *_tag = (media_tag_s*)calloc(1, sizeof(media_tag_s));
616 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
617 SQLITE3_FINALIZE(stmt);
618 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
621 _tag->tag_id = (int)sqlite3_column_int(stmt, 0);
623 if(STRING_VALID((const char *)sqlite3_column_text(stmt, 1)))
624 _tag->name = strdup((const char *)sqlite3_column_text(stmt, 1));
626 if(callback((media_tag_h)_tag, user_data) == false)
628 media_tag_destroy((media_tag_h)_tag);
631 media_tag_destroy((media_tag_h)_tag);
634 SQLITE3_FINALIZE(stmt);
639 int _media_db_get_bookmark(const char *media_id, filter_h filter, media_bookmark_cb callback, void *user_data)
641 int ret = MEDIA_CONTENT_ERROR_NONE;
642 char select_query[MAX_QUERY_SIZE] = {0, };
643 char *condition_query = NULL;
644 char *option_query = NULL;
645 sqlite3_stmt *stmt = NULL;
646 attribute_h attr = NULL;
647 filter_s *_filter = (filter_s*)filter;
649 attr = _content_get_attirbute_handle();
651 memset(select_query, 0x00, sizeof(select_query));
653 if((_filter != NULL) && STRING_VALID(_filter->storage_id))
654 snprintf(select_query, sizeof(select_query), SELECT_BOOKMARK_LIST_BY_MEDIA_ID, _filter->storage_id, media_id);
656 snprintf(select_query, sizeof(select_query), SELECT_BOOKMARK_LIST_BY_MEDIA_ID, DB_TABLE_MEDIA_VIEW, media_id);
658 ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query);
659 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
661 ret = _content_query_prepare(&stmt, select_query, condition_query, option_query);
662 SAFE_FREE(condition_query);
663 SAFE_FREE(option_query);
664 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
666 while(sqlite3_step(stmt) == SQLITE_ROW)
668 media_bookmark_s *bookmark = (media_bookmark_s*)calloc(1, sizeof(media_bookmark_s));
672 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
673 SQLITE3_FINALIZE(stmt);
674 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
677 bookmark->bookmark_id = (int)sqlite3_column_int(stmt, 0);
679 if(STRING_VALID((const char *)sqlite3_column_text(stmt, 1)))
680 bookmark->media_id = strdup((const char *)sqlite3_column_text(stmt, 1));
682 bookmark->marked_time = (int)sqlite3_column_int(stmt, 2);
684 if(STRING_VALID((const char *)sqlite3_column_text(stmt, 3)))
685 bookmark->thumbnail_path = strdup((const char *)sqlite3_column_text(stmt, 3));
687 if(callback((media_bookmark_h)bookmark, user_data) == false)
689 media_bookmark_destroy((media_bookmark_h)bookmark);
693 media_bookmark_destroy((media_bookmark_h)bookmark);
696 SQLITE3_FINALIZE(stmt);
702 int _media_db_get_face(const char *media_id, filter_h filter, media_face_cb callback, void *user_data)
704 int ret = MEDIA_CONTENT_ERROR_NONE;
705 char select_query[MAX_QUERY_SIZE] = {0, };
706 char *condition_query = NULL;
707 char *option_query = NULL;
708 sqlite3_stmt *stmt = NULL;
709 attribute_h attr = NULL;
710 filter_s *_filter = (filter_s*)filter;
712 attr = _content_get_attirbute_handle();
714 memset(select_query, 0x00, sizeof(select_query));
716 if((_filter != NULL) && STRING_VALID(_filter->storage_id))
717 snprintf(select_query, sizeof(select_query), SELECT_FACE_LIST_BY_MEDIA_ID, _filter->storage_id, media_id);
719 snprintf(select_query, sizeof(select_query), SELECT_FACE_LIST_BY_MEDIA_ID, DB_TABLE_MEDIA_VIEW, media_id);
721 ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query);
722 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
724 ret = _content_query_prepare(&stmt, select_query, condition_query, option_query);
725 SAFE_FREE(condition_query);
726 SAFE_FREE(option_query);
727 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
729 while(sqlite3_step(stmt) == SQLITE_ROW)
731 media_face_s *face = (media_face_s*)calloc(1, sizeof(media_face_s));
735 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
736 SQLITE3_FINALIZE(stmt);
737 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
740 if(STRING_VALID((const char *)sqlite3_column_text(stmt, 0)))
741 face->face_id = strdup((const char *)sqlite3_column_text(stmt, 0));
743 if(STRING_VALID((const char *)sqlite3_column_text(stmt, 1)))
744 face->media_id = strdup((const char *)sqlite3_column_text(stmt, 1));
746 face->face_rect_x = (int)sqlite3_column_int(stmt, 2);
747 face->face_rect_y = (int)sqlite3_column_int(stmt, 3);
748 face->face_rect_w = (int)sqlite3_column_int(stmt, 4);
749 face->face_rect_h = (int)sqlite3_column_int(stmt, 5);
750 face->orientation= (int)sqlite3_column_int(stmt, 6);
752 if(STRING_VALID((const char *)sqlite3_column_text(stmt, 7)))
753 face->face_tag = strdup((const char *)sqlite3_column_text(stmt, 7));
755 if(callback((media_face_h)face, user_data) == false)
757 media_face_destroy((media_face_h)face);
761 media_face_destroy((media_face_h)face);
764 SQLITE3_FINALIZE(stmt);
770 int _media_db_get_group_item_count_by_id(int group_id, filter_h filter, group_list_e group_type, int *item_count)
772 int ret = MEDIA_CONTENT_ERROR_NONE;
773 sqlite3_stmt *stmt = NULL;
774 char select_query[MAX_QUERY_SIZE] = {0, };
775 char *condition_query = NULL;
776 char *option_query = NULL;
777 attribute_h attr = NULL;
778 filter_s *_filter = (filter_s*)filter;
780 attr = _content_get_attirbute_handle();
781 memset(select_query, 0x00, sizeof(select_query));
783 if(group_type == MEDIA_GROUP_ALBUM)
785 if((_filter != NULL) && STRING_VALID(_filter->storage_id))
786 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_COUNT_FROM_ALBUM, _filter->storage_id, group_id);
788 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_COUNT_FROM_ALBUM, DB_TABLE_MEDIA_VIEW, group_id);
790 else if(group_type == MEDIA_GROUP_PLAYLIST)
792 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_COUNT_FROM_PLAYLIST, group_id);
794 else if(group_type == MEDIA_GROUP_TAG)
796 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_COUNT_FROM_TAG, group_id);
800 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
801 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
804 ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query);
805 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
807 ret = _content_query_prepare(&stmt, select_query, condition_query, option_query);
808 SAFE_FREE(condition_query);
809 SAFE_FREE(option_query);
810 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
812 while(sqlite3_step(stmt) == SQLITE_ROW)
814 *item_count = (int)sqlite3_column_int(stmt, 0);
817 SQLITE3_FINALIZE(stmt);
822 int _media_db_get_group_item_count(const char *group_name, filter_h filter, group_list_e group_type, int *item_count)
824 int ret = MEDIA_CONTENT_ERROR_NONE;
825 sqlite3_stmt *stmt = NULL;
826 char select_query[MAX_QUERY_SIZE] = {0, };
827 char *tmp_query = NULL;
828 char *condition_query = NULL;
829 char *option_query = NULL;
830 bool is_simple = FALSE;
831 attribute_h attr = NULL;
832 filter_s *_filter = (filter_s*)filter;
834 attr = _content_get_attirbute_handle();
835 memset(select_query, 0x00, sizeof(select_query));
837 if(group_type == MEDIA_GROUP_NONE)
839 /* There are 2 ways to get count for media table for performance
840 If user wants to set offset and count, use SQL SELECT_MEDIA_COUNT_FROM_MEDIA.
841 If user wants to get count without setting count, SELECT_MEDIA_COUNT_FROM_MEDIA_SIMPLE */
842 if (_filter && ((_filter->offset < 0) && (_filter->count < 0))) {
843 if(STRING_VALID(_filter->storage_id))
844 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_COUNT_FROM_MEDIA_SIMPLE, _filter->storage_id);
846 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_COUNT_FROM_MEDIA_SIMPLE, DB_TABLE_MEDIA_VIEW);
849 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_COUNT_FROM_MEDIA, DB_TABLE_MEDIA_VIEW);
852 else if(group_type == MEDIA_GROUP_FOLDER)
854 if((_filter != NULL) && STRING_VALID(_filter->storage_id))
855 tmp_query = sqlite3_mprintf(SELECT_MEDIA_COUNT_FROM_FOLDER, _filter->storage_id, group_name);
857 tmp_query = sqlite3_mprintf(SELECT_MEDIA_COUNT_FROM_FOLDER, DB_TABLE_MEDIA_VIEW, group_name);
859 SAFE_STRLCAT(select_query, tmp_query, sizeof(select_query));
861 else if(group_type == MEDIA_GROUP_TAG_BY_MEDIA_ID)
863 snprintf(select_query, sizeof(select_query), SELECT_TAG_COUNT_BY_MEDIA_ID, group_name);
865 else if(group_type == MEDIA_GROUP_BOOKMARK_BY_MEDIA_ID)
867 if((_filter != NULL) && STRING_VALID(_filter->storage_id))
868 tmp_query = sqlite3_mprintf(SELECT_BOOKMARK_COUNT_BY_MEDIA_ID, _filter->storage_id, group_name);
870 tmp_query = sqlite3_mprintf(SELECT_BOOKMARK_COUNT_BY_MEDIA_ID, DB_TABLE_MEDIA_VIEW, group_name);
872 SAFE_STRLCAT(select_query, tmp_query, sizeof(select_query));
874 else if(group_type == MEDIA_GROUP_STORAGE)
876 tmp_query = sqlite3_mprintf(SELECT_MEDIA_COUNT_FROM_STORAGE, group_name, group_name);
878 SAFE_STRLCAT(select_query, tmp_query, sizeof(select_query));
880 else if (group_type == MEDIA_GROUP_FACE_BY_MEDIA_ID)
882 if((_filter != NULL) && STRING_VALID(_filter->storage_id))
883 tmp_query = sqlite3_mprintf(SELECT_FACE_COUNT_BY_MEDIA_ID, _filter->storage_id, group_name);
885 tmp_query = sqlite3_mprintf(SELECT_FACE_COUNT_BY_MEDIA_ID, DB_TABLE_MEDIA_VIEW, group_name);
887 SAFE_STRLCAT(select_query, tmp_query, sizeof(select_query));
891 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
892 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
895 ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query);
896 if(ret != MEDIA_CONTENT_ERROR_NONE)
898 if(tmp_query != NULL)
899 SQLITE3_SAFE_FREE(tmp_query);
903 if(group_type == MEDIA_GROUP_NONE)
905 SAFE_STRLCAT(select_query, QUERY_KEYWORD_SPACE, sizeof(select_query));
906 if(STRING_VALID(condition_query))
907 SAFE_STRLCAT(select_query, condition_query, sizeof(select_query));
908 if(STRING_VALID(option_query))
909 SAFE_STRLCAT(select_query, option_query, sizeof(select_query));
912 SAFE_STRLCAT(select_query, QUERY_KEYWORD_BRACKET, sizeof(select_query));
914 SAFE_FREE(condition_query);
915 SAFE_FREE(option_query);
918 ret = _content_query_prepare(&stmt, select_query, condition_query, option_query);
919 if(tmp_query != NULL)
920 SQLITE3_SAFE_FREE(tmp_query);
921 SAFE_FREE(condition_query);
922 SAFE_FREE(option_query);
923 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
925 while(sqlite3_step(stmt) == SQLITE_ROW)
927 *item_count = (int)sqlite3_column_int(stmt, 0);
930 SQLITE3_FINALIZE(stmt);
935 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)
937 int ret = MEDIA_CONTENT_ERROR_NONE;
938 char select_query[MAX_QUERY_SIZE] = {0, };
939 char *condition_query = NULL;
940 char *option_query = NULL;
941 sqlite3_stmt *stmt = NULL;
942 attribute_h attr = NULL;
943 filter_s *_filter = (filter_s*)filter;
945 attr = _content_get_attirbute_handle();
946 memset(select_query, 0x00, sizeof(select_query));
948 if(group_type == MEDIA_GROUP_ALBUM)
950 if((_filter != NULL) && STRING_VALID(_filter->storage_id))
951 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_ALBUM, _filter->storage_id, group_id);
953 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_ALBUM, DB_TABLE_MEDIA_VIEW, group_id);
955 else if(group_type == MEDIA_GROUP_PLAYLIST)
957 if((_filter != NULL) && STRING_VALID(_filter->storage_id))
958 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_PLAYLIST, _filter->storage_id, group_id);
960 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_PLAYLIST, DB_TABLE_MEDIA_VIEW, group_id);
962 else if(group_type == MEDIA_GROUP_TAG)
964 if((_filter != NULL) && STRING_VALID(_filter->storage_id))
965 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_TAG, _filter->storage_id, group_id);
967 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_TAG, DB_TABLE_MEDIA_VIEW, group_id);
971 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
972 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
975 ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query);
976 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
978 ret = _content_query_prepare(&stmt, select_query, condition_query, option_query);
979 SAFE_FREE(condition_query);
980 SAFE_FREE(option_query);
981 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
983 while(sqlite3_step(stmt) == SQLITE_ROW)
985 media_info_s *item = (media_info_s*)calloc(1, sizeof(media_info_s));
988 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
989 SQLITE3_FINALIZE(stmt);
990 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
993 _media_info_item_get_detail(stmt, (media_info_h)item);
995 if(callback((media_info_h)item, user_data) == false)
997 media_info_destroy((media_info_h)item);
1001 media_info_destroy((media_info_h)item);
1004 SQLITE3_FINALIZE(stmt);
1009 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)
1011 int ret = MEDIA_CONTENT_ERROR_NONE;
1012 char select_query[MAX_QUERY_SIZE] = {0, };
1013 char *condition_query = NULL;
1014 char *option_query = NULL;
1015 sqlite3_stmt *stmt = NULL;
1016 attribute_h attr = NULL;
1017 filter_s *_filter = (filter_s*)filter;
1019 attr = _content_get_attirbute_handle();
1020 memset(select_query, 0x00, sizeof(select_query));
1022 if(group_type == MEDIA_GROUP_NONE)
1024 if((_filter != NULL) && STRING_VALID(_filter->storage_id))
1025 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_ITEM, _filter->storage_id);
1027 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_ITEM, DB_TABLE_MEDIA_VIEW);
1029 else if(group_type == MEDIA_GROUP_FOLDER)
1031 if((_filter != NULL) && STRING_VALID(_filter->storage_id))
1032 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_FOLDER, _filter->storage_id, group_name);
1034 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_FOLDER, DB_TABLE_MEDIA_VIEW, group_name);
1036 else if(group_type == MEDIA_GROUP_STORAGE)
1038 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_STORAGE, group_name, group_name);
1042 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1043 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1046 ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query);
1047 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
1049 ret = _content_query_prepare(&stmt, select_query, condition_query, option_query);
1050 SAFE_FREE(condition_query);
1051 SAFE_FREE(option_query);
1052 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
1054 while(sqlite3_step(stmt) == SQLITE_ROW)
1056 media_info_s *item = (media_info_s*)calloc(1, sizeof(media_info_s));
1059 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1060 SQLITE3_FINALIZE(stmt);
1061 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1064 _media_info_item_get_detail(stmt, (media_info_h)item);
1066 if(callback((media_info_h)item, user_data) == false)
1068 media_info_destroy((media_info_h)item);
1072 media_info_destroy((media_info_h)item);
1075 SQLITE3_FINALIZE(stmt);
1080 int _media_db_get_media_group_item_count(const char *group_name, filter_h filter, media_group_e group, int *item_count)
1082 int ret = MEDIA_CONTENT_ERROR_NONE;
1083 sqlite3_stmt *stmt = NULL;
1084 char select_query[MAX_QUERY_SIZE] = {0, };
1085 char *tmp_query = NULL;
1086 char *condition_query = NULL;
1087 char *option_query = NULL;
1088 attribute_h attr = NULL;
1089 filter_s *_filter = (filter_s*)filter;
1091 attr = _content_get_attirbute_handle();
1092 memset(select_query, 0x00, sizeof(select_query));
1094 if(group_name != NULL)
1096 if((_filter != NULL) && STRING_VALID(_filter->storage_id))
1098 tmp_query = sqlite3_mprintf(SELECT_MEDIA_COUNT_FROM_GROUP, _filter->storage_id, __media_db_get_group_name(group), group_name);
1099 SAFE_STRLCAT(select_query, tmp_query, sizeof(select_query));
1103 tmp_query = sqlite3_mprintf(SELECT_MEDIA_COUNT_FROM_GROUP, DB_TABLE_MEDIA_VIEW, __media_db_get_group_name(group), group_name);
1104 SAFE_STRLCAT(select_query, tmp_query, sizeof(select_query));
1109 if((_filter != NULL) && STRING_VALID(_filter->storage_id))
1110 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_COUNT_FROM_GROUP_NULL, _filter->storage_id, __media_db_get_group_name(group));
1112 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_COUNT_FROM_GROUP_NULL, DB_TABLE_MEDIA_VIEW, __media_db_get_group_name(group));
1115 ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query);
1116 if(ret != MEDIA_CONTENT_ERROR_NONE)
1118 if(tmp_query != NULL)
1119 SQLITE3_SAFE_FREE(tmp_query);
1123 SAFE_STRLCAT(select_query, QUERY_KEYWORD_SPACE, sizeof(select_query));
1124 if(STRING_VALID(condition_query))
1125 SAFE_STRLCAT(select_query, condition_query, sizeof(select_query));
1126 if(STRING_VALID(option_query))
1127 SAFE_STRLCAT(select_query, option_query, sizeof(select_query));
1128 SAFE_STRLCAT(select_query, QUERY_KEYWORD_BRACKET, sizeof(select_query));
1130 SAFE_FREE(condition_query);
1131 SAFE_FREE(option_query);
1133 ret = _content_query_prepare(&stmt, select_query, condition_query, option_query);
1134 if(tmp_query != NULL)
1135 SQLITE3_SAFE_FREE(tmp_query);
1136 SAFE_FREE(condition_query);
1137 SAFE_FREE(option_query);
1138 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
1140 while(sqlite3_step(stmt) == SQLITE_ROW)
1142 *item_count = (int)sqlite3_column_int(stmt, 0);
1145 SQLITE3_FINALIZE(stmt);
1150 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)
1152 int ret = MEDIA_CONTENT_ERROR_NONE;
1153 char select_query[MAX_QUERY_SIZE] = {0, };
1154 char *tmp_query = NULL;
1155 char *condition_query = NULL;
1156 char *option_query = NULL;
1157 sqlite3_stmt *stmt = NULL;
1158 attribute_h attr = NULL;
1159 filter_s *_filter = (filter_s*)filter;
1161 attr = _content_get_attirbute_handle();
1162 memset(select_query, 0x00, sizeof(select_query));
1164 if(group_name != NULL)
1166 if((_filter != NULL) && STRING_VALID(_filter->storage_id))
1167 tmp_query = sqlite3_mprintf(SELECT_MEDIA_FROM_GROUP, _filter->storage_id, __media_db_get_group_name(group), group_name);
1169 tmp_query = sqlite3_mprintf(SELECT_MEDIA_FROM_GROUP, DB_TABLE_MEDIA_VIEW, __media_db_get_group_name(group), group_name);
1171 SAFE_STRLCAT(select_query, tmp_query, sizeof(select_query));
1175 if((_filter != NULL) && STRING_VALID(_filter->storage_id))
1176 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_GROUP_NULL, _filter->storage_id, __media_db_get_group_name(group));
1178 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_GROUP_NULL, DB_TABLE_MEDIA_VIEW, __media_db_get_group_name(group));
1181 ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query);
1182 if(ret != MEDIA_CONTENT_ERROR_NONE)
1184 if(tmp_query != NULL)
1185 SQLITE3_SAFE_FREE(tmp_query);
1189 ret = _content_query_prepare(&stmt, select_query, condition_query, option_query);
1190 if(tmp_query != NULL)
1191 SQLITE3_SAFE_FREE(tmp_query);
1192 SAFE_FREE(condition_query);
1193 SAFE_FREE(option_query);
1194 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
1196 while(sqlite3_step(stmt) == SQLITE_ROW)
1198 media_info_s *item = (media_info_s*)calloc(1, sizeof(media_info_s));
1201 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1202 SQLITE3_FINALIZE(stmt);
1203 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1206 _media_info_item_get_detail(stmt, (media_info_h)item);
1208 if(callback((media_info_h)item, user_data) == false)
1210 media_info_destroy((media_info_h)item);
1214 media_info_destroy((media_info_h)item);
1217 SQLITE3_FINALIZE(stmt);
1222 int _media_db_get_storage(filter_h filter, media_storage_cb callback, void *user_data)
1224 int ret = MEDIA_CONTENT_ERROR_NONE;
1225 char select_query[DEFAULT_QUERY_SIZE];
1226 char *condition_query = NULL;
1227 char *option_query = NULL;
1228 sqlite3_stmt *stmt = NULL;
1229 attribute_h attr = NULL;
1231 attr = _content_get_attirbute_handle();
1232 memset(select_query, 0x00, sizeof(select_query));
1234 if(!SAFE_STRLCPY(select_query, SELECT_STORAGE_LIST, sizeof(select_query)))
1236 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1237 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1240 ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query);
1241 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
1243 ret = _content_query_prepare(&stmt, select_query, condition_query, option_query);
1244 SAFE_FREE(condition_query);
1245 SAFE_FREE(option_query);
1246 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
1248 while(sqlite3_step(stmt) == SQLITE_ROW)
1250 media_storage_s *_storage = (media_storage_s*)calloc(1, sizeof(media_storage_s));
1252 if(_storage == NULL)
1254 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1255 SQLITE3_FINALIZE(stmt);
1256 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1259 if(STRING_VALID((const char *)sqlite3_column_text(stmt, 0)))
1260 _storage->storage_id = strdup((const char *)sqlite3_column_text(stmt, 0));
1262 if(STRING_VALID((const char *)sqlite3_column_text(stmt, 1)))
1263 _storage->storage_name = strdup((const char *)sqlite3_column_text(stmt, 1));
1265 if(STRING_VALID((const char *)sqlite3_column_text(stmt, 2)))
1266 _storage->storage_path = strdup((const char *)sqlite3_column_text(stmt, 2));
1268 if(STRING_VALID((const char *)sqlite3_column_text(stmt, 3)))
1269 _storage->storage_account = strdup((const char *)sqlite3_column_text(stmt, 3));
1271 _storage->storage_type = (int)sqlite3_column_int(stmt, 4);
1273 if(callback((media_storage_h)_storage, user_data) == false)
1275 media_storage_destroy((media_storage_h) _storage);
1279 media_storage_destroy((media_storage_h) _storage);
1282 SQLITE3_FINALIZE(stmt);
1287 int _media_db_get_storage_id_by_media_id(const char *media_id, char *storage_id)
1289 int ret = MEDIA_CONTENT_ERROR_NONE;
1290 sqlite3_stmt *stmt = NULL;
1291 char *select_query = NULL;
1293 select_query = sqlite3_mprintf(SELECT_MEDIA_STORAGE_ID_BY_ID, media_id);
1295 ret = _content_query_prepare(&stmt, select_query, NULL, NULL);
1296 SQLITE3_SAFE_FREE(select_query);
1297 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
1299 if(sqlite3_step(stmt) == SQLITE_ROW)
1301 if(STRING_VALID((const char *)sqlite3_column_text(stmt, 0)))
1302 strncpy(storage_id, (const char *)sqlite3_column_text(stmt, 0), MEDIA_CONTENT_UUID_SIZE);
1304 media_content_error("There's no media!!");
1305 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1308 SQLITE3_FINALIZE(stmt);