4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Hyunjun Ko <zzoon.ko@samsung.com>, Haejeong Kim <backto.kim@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
25 #include <media-util.h>
27 #include "media-svc-env.h"
28 #include "media-svc-debug.h"
29 #include "media-svc-util.h"
30 #include "media-svc-db-utils.h"
31 #include "media-util-err.h"
32 #include "media-util-db.h"
33 #include "media-svc-media.h"
35 static int __media_svc_db_upgrade(sqlite3 *db_handle, int cur_version, uid_t uid);
36 static int __media_svc_rebuild_view_query(sqlite3 *db_handle, uid_t uid);
39 static GHashTable *table;
40 static GSList *column_list[MEDIA_SVC_DB_LIST_MAX];
42 int __media_svc_add_table_info(const char *name, const char *trigger_name, const char *event_table, const char *action_table, const char *view_name)
44 table_info_s *tbl = NULL;
46 media_svc_retvm_if(!STRING_VALID(name), MS_MEDIA_ERR_INVALID_PARAMETER, "name is NULL");
48 if (STRING_VALID(trigger_name)) {
49 media_svc_retvm_if(!STRING_VALID(event_table), MS_MEDIA_ERR_INVALID_PARAMETER, "event_table is NULL");
50 media_svc_retvm_if(!STRING_VALID(action_table), MS_MEDIA_ERR_INVALID_PARAMETER, "action_table is NULL");
53 tbl = malloc(sizeof(table_info_s));
55 media_svc_error("MS_MEDIA_ERR_OUT_OF_MEMORY");
56 return MS_MEDIA_ERR_OUT_OF_MEMORY;
59 memset(tbl, 0x00, sizeof(table_info_s));
61 if (STRING_VALID(trigger_name)) {
62 tbl->trigger_name = malloc(MEDIA_SVC_PATHNAME_SIZE);
63 if (tbl->trigger_name == NULL) {
64 media_svc_error("MS_MEDIA_ERR_OUT_OF_MEMORY");
66 return MS_MEDIA_ERR_OUT_OF_MEMORY;
69 memset(tbl->trigger_name, 0x00, MEDIA_SVC_PATHNAME_SIZE);
70 snprintf(tbl->trigger_name, MEDIA_SVC_PATHNAME_SIZE, "%s_%s", trigger_name, event_table);
72 tbl->event_table = strndup(event_table, strlen(event_table));
73 tbl->action_table = strndup(action_table, strlen(action_table));
76 if (STRING_VALID(view_name))
77 tbl->view_name = strndup(view_name, strlen(view_name));
79 g_hash_table_insert(table, (gpointer)name, (gpointer)tbl);
81 return MS_MEDIA_ERR_NONE;
84 int __media_svc_add_column_info(GSList **slist, const char *name, const char *type, const char *option, int version, const char *index_name, bool is_unique, bool is_trigger, bool is_view)
86 column_info_s *col = NULL;
87 col = malloc(sizeof(column_info_s));
89 media_svc_error("MS_MEDIA_ERR_OUT_OF_MEMORY");
90 return MS_MEDIA_ERR_OUT_OF_MEMORY;
92 memset(col, 0, sizeof(column_info_s));
94 col->name = strndup(name, strlen(name));
95 col->type = strndup(type, strlen(type));
97 col->has_option = true;
98 col->option = strndup(option, strlen(option));
100 col->has_option = false;
102 col->version = version;
103 if (index_name != NULL) {
104 col->is_index = true;
105 col->index_name = strndup(index_name, strlen(index_name));
107 col->is_index = false;
109 col->is_unique = is_unique;
110 col->is_trigger = is_trigger;
111 col->is_view = is_view;
112 *slist = g_slist_append(*slist, col);
114 return MS_MEDIA_ERR_NONE;
117 static int __media_svc_rebuild_view_query(sqlite3 *db_handle, uid_t uid)
119 int ret = MS_MEDIA_ERR_NONE;
120 column_info_s *col_ptr = NULL;
122 char table_query[MEDIA_SVC_QUERY_LEN_NORMAL] = {0, };
123 char temp[1024] = {0, };
127 _media_svc_update_media_view(db_handle, uid);
129 /*drop playlist_view, tag_view */
130 sql = sqlite3_mprintf(MEDIA_SVC_DB_QUERY_DROP_VIEW, MEDIA_SVC_DB_VIEW_PLAYLIST);
131 ret = _media_svc_sql_query(sql, uid);
132 SQLITE3_SAFE_FREE(sql);
133 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
135 sql = sqlite3_mprintf(MEDIA_SVC_DB_QUERY_DROP_VIEW, MEDIA_SVC_DB_VIEW_TAG);
136 ret = _media_svc_sql_query(sql, uid);
137 SQLITE3_SAFE_FREE(sql);
138 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
140 /*create playlist_view */
141 len = g_slist_length(column_list[MEDIA_SVC_DB_LIST_PLAYLIST]);
142 for (i = 1; i < len; i++) {
143 col_ptr = g_slist_nth_data(column_list[MEDIA_SVC_DB_LIST_PLAYLIST], i);
144 if (col_ptr->is_view) {
146 if (strncmp(col_ptr->name, MEDIA_SVC_DB_COLUMN_THUMBNAIL, strlen(MEDIA_SVC_DB_COLUMN_THUMBNAIL)) == 0)
147 snprintf(temp, sizeof(temp), ", playlist.%s AS p_thumbnail_path", col_ptr->name);
149 snprintf(temp, sizeof(temp), ", playlist.%s", col_ptr->name);
151 snprintf(temp, sizeof(temp), "playlist.%s", col_ptr->name);
154 SAFE_STRLCAT(table_query, temp, sizeof(table_query));
156 memset(temp, 0, sizeof(temp));
158 len = g_slist_length(column_list[MEDIA_SVC_DB_LIST_PLAYLIST_MAP]);
159 for (i = 1; i < len; i++) {
160 col_ptr = g_slist_nth_data(column_list[MEDIA_SVC_DB_LIST_PLAYLIST_MAP], i);
161 if (col_ptr->is_view) {
162 if (strncmp(col_ptr->name, MEDIA_SVC_DB_COLUMN_MAP_ID, strlen(MEDIA_SVC_DB_COLUMN_MAP_ID)) == 0)
163 snprintf(temp, sizeof(temp), ", media_count IS NOT NULL AS media_count, playlist_map.%s AS pm_id", col_ptr->name);
165 snprintf(temp, sizeof(temp), ", playlist_map.%s", col_ptr->name);
166 SAFE_STRLCAT(table_query, temp, sizeof(table_query));
168 memset(temp, 0, sizeof(temp));
171 len = g_slist_length(column_list[MEDIA_SVC_DB_LIST_MEDIA]);
172 for (i = 1; i < len; i++) {
173 col_ptr = g_slist_nth_data(column_list[MEDIA_SVC_DB_LIST_MEDIA], i);
174 if (col_ptr->is_view) {
175 snprintf(temp, sizeof(temp), ", media.%s", col_ptr->name);
176 SAFE_STRLCAT(table_query, temp, sizeof(table_query));
178 memset(temp, 0, sizeof(temp));
180 sql = sqlite3_mprintf(MEDIA_SVC_DB_QUERY_VIEW_PLAYLIST, MEDIA_SVC_DB_VIEW_PLAYLIST, table_query);
181 ret = _media_svc_sql_query(sql, uid);
182 SQLITE3_SAFE_FREE(sql);
183 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
187 memset(table_query, 0, sizeof(table_query));
189 len = g_slist_length(column_list[MEDIA_SVC_DB_LIST_TAG]);
190 for (i = 1; i < len; i++) {
191 col_ptr = g_slist_nth_data(column_list[MEDIA_SVC_DB_LIST_TAG], i);
192 if (col_ptr->is_view) {
194 snprintf(temp, sizeof(temp), ", tag.%s", col_ptr->name);
196 snprintf(temp, sizeof(temp), "tag.%s", col_ptr->name);
199 SAFE_STRLCAT(table_query, temp, sizeof(table_query));
201 memset(temp, 0, sizeof(temp));
203 len = g_slist_length(column_list[MEDIA_SVC_DB_LIST_TAG_MAP]);
204 for (i = 1; i < len; i++) {
205 col_ptr = g_slist_nth_data(column_list[MEDIA_SVC_DB_LIST_TAG_MAP], i);
206 if (col_ptr->is_view) {
207 if (strncmp(col_ptr->name, MEDIA_SVC_DB_COLUMN_MAP_ID, strlen(MEDIA_SVC_DB_COLUMN_MAP_ID)) == 0)
208 snprintf(temp, sizeof(temp), ", media_count IS NOT NULL AS media_count, tag_map.%s AS tm_id", col_ptr->name);
210 snprintf(temp, sizeof(temp), ", tag_map.%s", col_ptr->name);
211 SAFE_STRLCAT(table_query, temp, sizeof(table_query));
213 memset(temp, 0, sizeof(temp));
216 len = g_slist_length(column_list[MEDIA_SVC_DB_LIST_MEDIA]);
217 for (i = 1; i < len; i++) {
218 col_ptr = g_slist_nth_data(column_list[MEDIA_SVC_DB_LIST_MEDIA], i);
219 if (col_ptr->is_view) {
220 snprintf(temp, sizeof(temp), ", media.%s", col_ptr->name);
221 SAFE_STRLCAT(table_query, temp, sizeof(table_query));
223 memset(temp, 0, sizeof(temp));
225 sql = sqlite3_mprintf(MEDIA_SVC_DB_QUERY_VIEW_TAG, MEDIA_SVC_DB_VIEW_TAG, table_query);
226 ret = _media_svc_sql_query(sql, uid);
227 SQLITE3_SAFE_FREE(sql);
228 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
230 return MS_MEDIA_ERR_NONE;
233 int _media_svc_make_table_query(const char *table_name, media_svc_table_slist_e list, uid_t uid)
235 int ret = MS_MEDIA_ERR_NONE;
236 table_info_s *tb = NULL;
237 column_info_s *col_ptr = NULL;
239 char table_query[MEDIA_SVC_QUERY_LEN_NORMAL] = {0, };
240 char index_query[MEDIA_SVC_QUERY_LEN_NORMAL] = {0, };
241 char trigger_query[MEDIA_SVC_QUERY_LEN_NORMAL] = {0, };
242 char table_query_sub[1024] = {0, };
243 char temp[1024] = {0 ,};
245 bool sub_flag = false;
249 tb = g_hash_table_lookup(table, table_name);
251 media_svc_debug("lookup fail.. table name [%s] ", table_name);
252 tb = g_hash_table_lookup(table, MEDIA_SVC_DB_TABLE_MEDIA);
255 len = g_slist_length(column_list[list]);
258 media_svc_error("Invalid column");
259 return MS_MEDIA_ERR_INTERNAL;
262 for (i = 1; i < len; i++) {
263 col_ptr = g_slist_nth_data(column_list[list], i);
265 if (col_ptr->has_option) {
267 snprintf(temp, sizeof(temp), ", %s %s %s", col_ptr->name, col_ptr->type, col_ptr->option);
269 snprintf(temp, sizeof(temp), "%s %s %s", col_ptr->name, col_ptr->type, col_ptr->option);
272 SAFE_STRLCAT(table_query, temp, sizeof(table_query));
275 snprintf(temp, sizeof(temp), ", %s %s", col_ptr->name, col_ptr->type);
277 snprintf(temp, sizeof(temp), "%s %s", col_ptr->name, col_ptr->type);
280 SAFE_STRLCAT(table_query, temp, sizeof(table_query));
282 memset(temp, 0, sizeof(temp));
285 if (col_ptr->is_unique) {
286 if (sub_flag == true) {
287 snprintf(temp, sizeof(temp), ", %s", col_ptr->name);
289 snprintf(temp, sizeof(temp), "%s", col_ptr->name);
292 SAFE_STRLCAT(table_query_sub, temp, sizeof(table_query_sub));
294 memset(temp, 0, sizeof(temp));
297 if (col_ptr->is_index) {
298 snprintf(temp, sizeof(temp), MEDIA_SVC_DB_QUERY_INDEX, col_ptr->index_name, table_name, col_ptr->name);
299 SAFE_STRLCAT(index_query, temp, sizeof(index_query));
301 memset(temp, 0, sizeof(temp));
304 if (col_ptr->is_trigger) {
305 if (STRING_VALID(tb->trigger_name)) {
306 if (strncmp(table_name, MEDIA_SVC_DB_TABLE_ALBUM, strlen(MEDIA_SVC_DB_TABLE_ALBUM)) == 0) {
307 snprintf(temp, sizeof(temp), MEDIA_SVC_DB_QUERY_TRIGGER_WITH_COUNT, tb->trigger_name, tb->event_table, tb->action_table, tb->event_table, col_ptr->name, col_ptr->name, col_ptr->name, col_ptr->name);
309 snprintf(temp, sizeof(temp), MEDIA_SVC_DB_QUERY_TRIGGER, tb->trigger_name, tb->event_table, tb->action_table, col_ptr->name, col_ptr->name);
311 SAFE_STRLCAT(trigger_query, temp, sizeof(trigger_query));
313 media_svc_error("invalid trigger name");
316 memset(temp, 0, sizeof(temp));
320 if (sub_flag == true) {
321 sql = sqlite3_mprintf(MEDIA_SVC_DB_QUERY_TABLE_WITH_UNIQUE, table_name, table_query, table_query_sub);
322 ret = _media_svc_sql_query(sql, uid);
323 SQLITE3_SAFE_FREE(sql);
324 memset(table_query, 0, sizeof(table_query));
325 memset(table_query_sub, 0, sizeof(table_query_sub));
326 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
328 sql = sqlite3_mprintf(MEDIA_SVC_DB_QUERY_TABLE, table_name, table_query);
329 ret = _media_svc_sql_query(sql, uid);
330 SQLITE3_SAFE_FREE(sql);
331 memset(table_query, 0, sizeof(table_query));
332 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
335 if (STRING_VALID(index_query)) {
336 ret = _media_svc_sql_query(index_query, uid);
337 memset(index_query, 0, sizeof(index_query));
338 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
341 if (STRING_VALID(trigger_query)) {
342 ret = _media_svc_sql_query(trigger_query, uid);
343 memset(trigger_query, 0, sizeof(trigger_query));
344 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
349 if (tb != NULL && tb->view_name != NULL) {
350 if (strncmp(table_name, MEDIA_SVC_DB_TABLE_MEDIA, strlen(MEDIA_SVC_DB_TABLE_MEDIA)) == 0) {
351 sql = sqlite3_mprintf(MEDIA_SVC_DB_QUERY_VIEW_MEDIA, tb->view_name, table_name);
352 ret = _media_svc_sql_query(sql, uid);
353 SQLITE3_SAFE_FREE(sql);
354 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
356 } else if (strncmp(table_name, MEDIA_SVC_DB_TABLE_PLAYLIST, strlen(MEDIA_SVC_DB_TABLE_PLAYLIST)) == 0) {
357 len = g_slist_length(column_list[MEDIA_SVC_DB_LIST_PLAYLIST]);
358 for (i = 1; i < len; i++) {
359 col_ptr = g_slist_nth_data(column_list[MEDIA_SVC_DB_LIST_PLAYLIST], i);
360 if (col_ptr->is_view) {
362 if (strncmp(col_ptr->name, MEDIA_SVC_DB_COLUMN_THUMBNAIL, strlen(MEDIA_SVC_DB_COLUMN_THUMBNAIL)) == 0)
363 snprintf(temp, sizeof(temp), ", playlist.%s AS p_thumbnail_path", col_ptr->name);
365 snprintf(temp, sizeof(temp), ", playlist.%s", col_ptr->name);
367 snprintf(temp, sizeof(temp), "playlist.%s", col_ptr->name);
370 SAFE_STRLCAT(table_query, temp, sizeof(table_query));
372 memset(temp, 0, sizeof(temp));
374 len = g_slist_length(column_list[MEDIA_SVC_DB_LIST_PLAYLIST_MAP]);
375 for (i = 1; i < len; i++) {
376 col_ptr = g_slist_nth_data(column_list[MEDIA_SVC_DB_LIST_PLAYLIST_MAP], i);
377 if (col_ptr->is_view) {
378 if (strncmp(col_ptr->name, MEDIA_SVC_DB_COLUMN_MAP_ID, strlen(MEDIA_SVC_DB_COLUMN_MAP_ID)) == 0)
379 snprintf(temp, sizeof(temp), ", media_count IS NOT NULL AS media_count, playlist_map.%s AS pm_id", col_ptr->name);
381 snprintf(temp, sizeof(temp), ", playlist_map.%s", col_ptr->name);
382 SAFE_STRLCAT(table_query, temp, sizeof(table_query));
384 memset(temp, 0, sizeof(temp));
387 len = g_slist_length(column_list[MEDIA_SVC_DB_LIST_MEDIA]);
388 for (i = 1; i < len; i++) {
389 col_ptr = g_slist_nth_data(column_list[MEDIA_SVC_DB_LIST_MEDIA], i);
390 if (col_ptr->is_view) {
391 snprintf(temp, sizeof(temp), ", media.%s", col_ptr->name);
392 SAFE_STRLCAT(table_query, temp, sizeof(table_query));
394 memset(temp, 0, sizeof(temp));
396 sql = sqlite3_mprintf(MEDIA_SVC_DB_QUERY_VIEW_PLAYLIST, tb->view_name, table_query);
397 ret = _media_svc_sql_query(sql, uid);
398 SQLITE3_SAFE_FREE(sql);
399 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
402 len = g_slist_length(column_list[MEDIA_SVC_DB_LIST_TAG]);
403 for (i = 1; i < len; i++) {
404 col_ptr = g_slist_nth_data(column_list[MEDIA_SVC_DB_LIST_TAG], i);
405 if (col_ptr->is_view) {
407 snprintf(temp, sizeof(temp), ", tag.%s", col_ptr->name);
409 snprintf(temp, sizeof(temp), "tag.%s", col_ptr->name);
412 SAFE_STRLCAT(table_query, temp, sizeof(table_query));
414 memset(temp, 0, sizeof(temp));
416 len = g_slist_length(column_list[MEDIA_SVC_DB_LIST_TAG_MAP]);
417 for (i = 1; i < len; i++) {
418 col_ptr = g_slist_nth_data(column_list[MEDIA_SVC_DB_LIST_TAG_MAP], i);
419 if (col_ptr->is_view) {
420 if (strncmp(col_ptr->name, MEDIA_SVC_DB_COLUMN_MAP_ID, strlen(MEDIA_SVC_DB_COLUMN_MAP_ID)) == 0)
421 snprintf(temp, sizeof(temp), ", media_count IS NOT NULL AS media_count, tag_map.%s AS tm_id", col_ptr->name);
423 snprintf(temp, sizeof(temp), ", tag_map.%s", col_ptr->name);
424 SAFE_STRLCAT(table_query, temp, sizeof(table_query));
426 memset(temp, 0, sizeof(temp));
429 len = g_slist_length(column_list[MEDIA_SVC_DB_LIST_MEDIA]);
430 for (i = 1; i < len; i++) {
431 col_ptr = g_slist_nth_data(column_list[MEDIA_SVC_DB_LIST_MEDIA], i);
432 if (col_ptr->is_view) {
433 snprintf(temp, sizeof(temp), ", media.%s", col_ptr->name);
434 SAFE_STRLCAT(table_query, temp, sizeof(table_query));
436 memset(temp, 0, sizeof(temp));
438 sql = sqlite3_mprintf(MEDIA_SVC_DB_QUERY_VIEW_TAG, tb->view_name, table_query);
439 ret = _media_svc_sql_query(sql, uid);
440 SQLITE3_SAFE_FREE(sql);
441 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
445 return MS_MEDIA_ERR_NONE;
448 int _media_svc_upgrade_table_query(sqlite3 *db_handle, const char *table_name, media_svc_table_slist_e list, uid_t uid)
450 int ret = MS_MEDIA_ERR_NONE;
451 column_info_s *col_ptr = NULL;
453 char temp[1024] = {0, };
456 sqlite3_stmt *sql_stmt = NULL;
458 len = g_slist_length(column_list[list]);
460 sql = sqlite3_mprintf("PRAGMA user_version");
461 ret = _media_svc_sql_prepare_to_step(db_handle, sql, &sql_stmt);
463 if (ret != MS_MEDIA_ERR_NONE) {
464 media_svc_error("error when get user_version. err = [%d]", ret);
467 cur_version = sqlite3_column_int(sql_stmt, 0);
468 SQLITE3_FINALIZE(sql_stmt);
470 len = g_slist_length(column_list[list]);
471 for (i = 1; i < len; i++) {
472 col_ptr = g_slist_nth_data(column_list[list], i);
473 if (col_ptr->version > cur_version) {
475 if (col_ptr->has_option)
476 snprintf(temp, sizeof(temp), "%s %s %s", col_ptr->name, col_ptr->type, col_ptr->option);
478 snprintf(temp, sizeof(temp), "%s %s", col_ptr->name, col_ptr->type);
479 sql = sqlite3_mprintf(MEDIA_SVC_DB_QUERY_ALTER_TABLE, table_name, temp);
480 ret = _media_svc_sql_query(sql, uid);
481 SQLITE3_SAFE_FREE(sql);
482 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
484 if (col_ptr->is_index) {
485 memset(temp, 0, sizeof(temp));
486 snprintf(temp, sizeof(temp), MEDIA_SVC_DB_QUERY_INDEX, col_ptr->index_name, table_name, col_ptr->name);
487 ret = _media_svc_sql_query(temp, uid);
488 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
491 memset(temp, 0, sizeof(temp));
494 return MS_MEDIA_ERR_NONE;
497 int _media_svc_init_table_query(const char *event_table_name)
499 int ret = MS_MEDIA_ERR_NONE;
502 /*variable initialize.. */
503 table = g_hash_table_new(g_str_hash, g_str_equal);
504 for (i = 0; i < MEDIA_SVC_DB_LIST_MAX; i++)
505 column_list[i] = g_slist_alloc();
507 /*table specification.. (table_name, index, unique set, trigger, view, trigger name, event table, action table, view name) */
508 ret = __media_svc_add_table_info(MEDIA_SVC_DB_TABLE_MEDIA, NULL, NULL, NULL, MEDIA_SVC_DB_VIEW_MEDIA);
509 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
510 ret = __media_svc_add_table_info(MEDIA_SVC_DB_TABLE_FOLDER, MEDIA_SVC_DB_TRIGGER_FOLDER, event_table_name, MEDIA_SVC_DB_TABLE_FOLDER, NULL);
511 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
512 ret = __media_svc_add_table_info(MEDIA_SVC_DB_TABLE_PLAYLIST_MAP, MEDIA_SVC_DB_TRIGGER_PLAYLIST_MAP, event_table_name, MEDIA_SVC_DB_TABLE_PLAYLIST_MAP, NULL);
513 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
514 ret = __media_svc_add_table_info(MEDIA_SVC_DB_TABLE_PLAYLIST, MEDIA_SVC_DB_TRIGGER_PLAYLIST_MAP1, MEDIA_SVC_DB_TABLE_PLAYLIST, MEDIA_SVC_DB_TABLE_PLAYLIST_MAP, MEDIA_SVC_DB_VIEW_PLAYLIST);
515 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
516 ret = __media_svc_add_table_info(MEDIA_SVC_DB_TABLE_ALBUM, MEDIA_SVC_DB_TRIGGER_ALBUM, event_table_name, MEDIA_SVC_DB_TABLE_ALBUM, NULL);
517 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
518 ret = __media_svc_add_table_info(MEDIA_SVC_DB_TABLE_TAG_MAP, MEDIA_SVC_DB_TRIGGER_TAG_MAP, event_table_name, MEDIA_SVC_DB_TABLE_TAG_MAP, NULL);
519 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
520 ret = __media_svc_add_table_info(MEDIA_SVC_DB_TABLE_TAG, MEDIA_SVC_DB_TRIGGER_TAG_MAP1, MEDIA_SVC_DB_TABLE_TAG, MEDIA_SVC_DB_TABLE_TAG_MAP, MEDIA_SVC_DB_VIEW_TAG);
521 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
522 ret = __media_svc_add_table_info(MEDIA_SVC_DB_TABLE_BOOKMARK, MEDIA_SVC_DB_TRIGGER_BOOKMARK, event_table_name, MEDIA_SVC_DB_TABLE_BOOKMARK, NULL);
523 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
524 ret = __media_svc_add_table_info(MEDIA_SVC_DB_TABLE_STORAGE, NULL, NULL, NULL, NULL);
525 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
526 ret = __media_svc_add_table_info(MEDIA_SVC_DB_TABLE_FACE_SCAN_LIST, MEDIA_SVC_DB_TRIGGER_FACE_SCAN_LIST, MEDIA_SVC_DB_TABLE_MEDIA, MEDIA_SVC_DB_TABLE_FACE_SCAN_LIST, NULL);
527 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
528 ret = __media_svc_add_table_info(MEDIA_SVC_DB_TABLE_FACE, MEDIA_SVC_DB_TRIGGER_FACE, MEDIA_SVC_DB_TABLE_FACE_SCAN_LIST, MEDIA_SVC_DB_TABLE_FACE, NULL);
529 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
530 ret = __media_svc_add_table_info(MEDIA_SVC_DB_TABLE_UHD, MEDIA_SVC_DB_TRIGGER_UHD, event_table_name, MEDIA_SVC_DB_TABLE_UHD, NULL);
531 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
532 ret = __media_svc_add_table_info(MEDIA_SVC_DB_TABLE_PVR, MEDIA_SVC_DB_TRIGGER_PVR, event_table_name, MEDIA_SVC_DB_TABLE_PVR, NULL);
533 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
535 /*insert column info.. */
537 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "media_uuid", MEDIA_SVC_DB_TYPE_TEXT, "PRIMARY KEY", USER_V2, NULL, false, false, true);
538 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
539 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "path", MEDIA_SVC_DB_TYPE_TEXT, "NOT NULL UNIQUE", USER_V2, NULL, true, false, true);
540 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
541 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "file_name", MEDIA_SVC_DB_TYPE_TEXT, "NOT NULL", USER_V2, "media_file_name_idx", true, false, true);
542 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
543 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "media_type", MEDIA_SVC_DB_TYPE_INT, NULL, USER_V2, NULL, false, false, true);
544 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
545 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "mime_type", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V2, NULL, false, false, true);
546 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
547 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "size", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", USER_V2, NULL, false, false, true);
548 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
549 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "added_time", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", USER_V2, NULL, false, false, true);
550 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
551 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "modified_time", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", USER_V2, "media_modified_time_idx", false, false, true);
552 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
553 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "folder_uuid", MEDIA_SVC_DB_TYPE_TEXT, "NOT NULL", USER_V2, "folder_uuid_idx", false, false, false);
554 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
555 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "thumbnail_path", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V2, NULL, false, false, true);
556 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
557 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "title", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V2, "media_title_idx", false, false, true);
558 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
559 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "album_id", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", USER_V2, NULL, false, false, false);
560 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
561 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "album", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V2, "media_album_idx", false, false, true);
562 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
563 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "artist", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V2, "media_artist_idx", false, false, true);
564 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
565 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "album_artist", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V2, NULL, false, false, true);
566 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
567 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "genre", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V2, "media_genre_idx", false, false, true);
568 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
569 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "composer", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V2, NULL, false, false, true);
570 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
571 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "year", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V2, NULL, false, false, true);
572 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
573 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "recorded_date", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V2, NULL, false, false, true);
574 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
575 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "copyright", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V2, NULL, false, false, true);
576 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
577 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "track_num", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V2, NULL, false, false, true);
578 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
579 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "description", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V2, NULL, false, false, true);
580 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
581 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "bitrate", MEDIA_SVC_DB_TYPE_INT, "DEFAULT -1", USER_V2, NULL, false, false, true);
582 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
583 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "bitpersample", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", USER_V3, NULL, false, false, true);
584 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
585 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "samplerate", MEDIA_SVC_DB_TYPE_INT, "DEFAULT -1", USER_V2, NULL, false, false, true);
586 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
587 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "channel", MEDIA_SVC_DB_TYPE_INT, "DEFAULT -1", USER_V2, NULL, false, false, true);
588 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
589 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "duration", MEDIA_SVC_DB_TYPE_INT, "DEFAULT -1", USER_V2, NULL, false, false, true);
590 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
591 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "longitude", MEDIA_SVC_DB_TYPE_DOUBLE, "DEFAULT 0", USER_V2, NULL, false, false, true);
592 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
593 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "latitude", MEDIA_SVC_DB_TYPE_DOUBLE, "DEFAULT 0", USER_V2, NULL, false, false, true);
594 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
595 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "altitude", MEDIA_SVC_DB_TYPE_DOUBLE, "DEFAULT 0", USER_V2, NULL, false, false, true);
596 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
597 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "exposure_time", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V4, NULL, false, false, true);
598 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
599 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "fnumber", MEDIA_SVC_DB_TYPE_DOUBLE, "DEFAULT 0", USER_V4, NULL, false, false, true);
600 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
601 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "iso", MEDIA_SVC_DB_TYPE_INT, "DEFAULT -1", USER_V4, NULL, false, false, true);
602 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
603 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "model", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V4, NULL, false, false, true);
604 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
605 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "width", MEDIA_SVC_DB_TYPE_INT, "DEFAULT -1", USER_V2, NULL, false, false, true);
606 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
607 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "height", MEDIA_SVC_DB_TYPE_INT, "DEFAULT -1", USER_V2, NULL, false, false, true);
608 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
609 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "datetaken", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V2, NULL, false, false, true);
610 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
611 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "orientation", MEDIA_SVC_DB_TYPE_INT, "DEFAULT -1", USER_V2, NULL, false, false, true);
612 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
613 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "burst_id", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V2, NULL, false, false, true);
614 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
615 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "played_count", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", USER_V2, NULL, false, false, true);
616 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
617 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "last_played_time", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", USER_V2, NULL, false, false, true);
618 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
619 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "last_played_position", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", USER_V2, NULL, false, false, true);
620 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
621 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "rating", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", USER_V2, NULL, false, false, true);
622 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
623 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "favourite", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", USER_V2, NULL, false, false, true);
624 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
625 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "author", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V2, NULL, false, false, true);
626 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
627 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "provider", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V2, NULL, false, false, true);
628 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
629 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "content_name", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V2, NULL, false, false, true);
630 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
631 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "category", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V2, NULL, false, false, true);
632 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
633 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "location_tag", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V2, NULL, false, false, true);
634 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
635 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "age_rating", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V2, NULL, false, false, true);
636 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
637 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "keyword", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V2, NULL, false, false, true);
638 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
639 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "is_drm", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", USER_V2, NULL, false, false, true);
640 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
641 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "storage_type", MEDIA_SVC_DB_TYPE_INT, NULL, USER_V2, NULL, false, false, true);
642 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
643 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "timeline", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", USER_V2, "media_timeline_idx", false, false, true);
644 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
645 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "weather", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V2, NULL, false, false, true);
646 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
647 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "sync_status", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", USER_V2, NULL, false, false, true);
648 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
649 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "file_name_pinyin", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V2, NULL, false, false, false);
650 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
651 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "title_pinyin", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V2, NULL, false, false, false);
652 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
653 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "album_pinyin", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V2, NULL, false, false, false);
654 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
655 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "artist_pinyin", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V2, NULL, false, false, false);
656 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
657 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "album_artist_pinyin", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V2, NULL, false, false, false);
658 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
659 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "genre_pinyin", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V2, NULL, false, false, false);
660 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
661 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "composer_pinyin", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V2, NULL, false, false, false);
662 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
663 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "copyright_pinyin", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V2, NULL, false, false, false);
664 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
665 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "description_pinyin", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V2, NULL, false, false, false);
666 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
667 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "author_pinyin", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V2, NULL, false, false, false);
668 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
669 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "provider_pinyin", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V2, NULL, false, false, false);
670 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
671 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "content_name_pinyin", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V2, NULL, false, false, false);
672 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
673 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "category_pinyin", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V2, NULL, false, false, false);
674 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
675 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "location_tag_pinyin", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V2, NULL, false, false, false);
676 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
677 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "age_rating_pinyin", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V2, NULL, false, false, false);
678 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
679 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "keyword_pinyin", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V2, NULL, false, false, false);
680 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
681 /* storage_uuid column is added in DB v4. When doing DB upgrade to v4, if storage_uuid is NOT NULL, alter table failed. */
682 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "storage_uuid", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V4, NULL, false, false, true);
683 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
684 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "validity", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 1", USER_V2, NULL, false, false, false);
685 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
686 /* color column is added with dcm. (DB v5) */
687 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "color_r", MEDIA_SVC_DB_TYPE_INT, NULL, USER_V5, NULL, false, false, false);
688 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
689 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "color_g", MEDIA_SVC_DB_TYPE_INT, NULL, USER_V5, NULL, false, false, false);
690 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
691 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "color_b", MEDIA_SVC_DB_TYPE_INT, NULL, USER_V5, NULL, false, false, false);
692 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
693 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_MEDIA], "is_360", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", USER_V5, NULL, false, false, true);
694 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
697 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_FOLDER], "folder_uuid", MEDIA_SVC_DB_TYPE_TEXT, "PRIMARY KEY", USER_V2, NULL, false, false, false);
698 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
699 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_FOLDER], "path", MEDIA_SVC_DB_TYPE_TEXT, "NOT NULL", USER_V2, NULL, true, false, false);
700 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
701 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_FOLDER], "name", MEDIA_SVC_DB_TYPE_TEXT, "NOT NULL", USER_V2, NULL, false, false, false);
702 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
703 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_FOLDER], "modified_time", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", USER_V2, NULL, false, false, false);
704 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
705 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_FOLDER], "name_pinyin", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V2, NULL, false, false, false);
706 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
707 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_FOLDER], "storage_type", MEDIA_SVC_DB_TYPE_INT, NULL, USER_V2, NULL, false, false, false);
708 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
709 /* storage_uuid column is added in DB v4. When doing DB upgrade to v4, if storage_uuid is NOT NULL, alter table failed. */
710 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_FOLDER], "storage_uuid", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V4, NULL, true, false, false);
711 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
712 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_FOLDER], "folder_order", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", USER_V4, NULL, false, false, false);
713 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
714 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_FOLDER], "parent_folder_uuid", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V4, NULL, false, false, false);
715 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
716 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_FOLDER], "validity", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 1", USER_V4, NULL, false, false, false);
717 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
718 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_FOLDER], "scan_status", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", USER_V4, NULL, false, false, false);
719 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
722 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_PLAYLIST_MAP], "_id", MEDIA_SVC_DB_TYPE_INT, "PRIMARY KEY AUTOINCREMENT", USER_V2, NULL, false, false, true);
723 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
724 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_PLAYLIST_MAP], "playlist_id", MEDIA_SVC_DB_TYPE_INT, "NOT NULL", USER_V2, NULL, false, false, false);
725 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
726 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_PLAYLIST_MAP], "media_uuid", MEDIA_SVC_DB_TYPE_TEXT, "NOT NULL", USER_V2, NULL, false, true, false);
727 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
728 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_PLAYLIST_MAP], "play_order", MEDIA_SVC_DB_TYPE_INT, "NOT NULL", USER_V2, NULL, false, false, true);
729 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
732 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_PLAYLIST], "playlist_id", MEDIA_SVC_DB_TYPE_INT, "PRIMARY KEY AUTOINCREMENT", USER_V2, NULL, false, true, true);
733 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
734 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_PLAYLIST], "name", MEDIA_SVC_DB_TYPE_TEXT, "NOT NULL UNIQUE", USER_V2, NULL, false, false, true);
735 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
736 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_PLAYLIST], "name_pinyin", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V2, NULL, false, false, false);
737 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
738 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_PLAYLIST], "thumbnail_path", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V2, NULL, false, false, true);
739 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
742 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_ALBUM], "album_id", MEDIA_SVC_DB_TYPE_INT, "PRIMARY KEY AUTOINCREMENT", USER_V2, NULL, false, true, false);
743 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
744 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_ALBUM], "name", MEDIA_SVC_DB_TYPE_TEXT, "NOT NULL", USER_V2, NULL, false, false, false);
745 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
746 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_ALBUM], "artist", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V2, NULL, false, false, false);
747 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
748 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_ALBUM], "album_art", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V2, NULL, false, false, false);
749 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
752 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_TAG_MAP], "_id", MEDIA_SVC_DB_TYPE_INT, "PRIMARY KEY AUTOINCREMENT", USER_V2, NULL, false, false, true);
753 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
754 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_TAG_MAP], "tag_id", MEDIA_SVC_DB_TYPE_INT, "NOT NULL", USER_V2, NULL, true, false, false);
755 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
756 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_TAG_MAP], "media_uuid", MEDIA_SVC_DB_TYPE_TEXT, "NOT NULL", USER_V2, NULL, true, true, false);
757 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
760 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_TAG], "tag_id ", MEDIA_SVC_DB_TYPE_INT, "PRIMARY KEY AUTOINCREMENT", USER_V2, NULL, false, true, true);
761 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
762 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_TAG], "name", MEDIA_SVC_DB_TYPE_TEXT, "NOT NULL UNIQUE", USER_V2, NULL, false, false, true);
763 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
764 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_TAG], "name_pinyin", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V2, NULL, false, false, false);
765 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
768 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_BOOKMARK], "bookmark_id", MEDIA_SVC_DB_TYPE_INT, "PRIMARY KEY AUTOINCREMENT", USER_V2, NULL, false, false, false);
769 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
770 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_BOOKMARK], "media_uuid", MEDIA_SVC_DB_TYPE_TEXT, "NOT NULL", USER_V2, NULL, true, true, false);
771 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
772 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_BOOKMARK], "marked_time", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", USER_V2, NULL, true, false, false);
773 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
774 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_BOOKMARK], "thumbnail_path", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V2, NULL, false, false, false);
775 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
776 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_BOOKMARK], "name", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V6, NULL, false, false, false);
777 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
780 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_STORAGE], "storage_uuid", MEDIA_SVC_DB_TYPE_TEXT, "NOT NULL", USER_V3, NULL, true, false, false);
781 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
782 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_STORAGE], "storage_name", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V3, NULL, true, false, false);
783 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
784 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_STORAGE], "storage_path", MEDIA_SVC_DB_TYPE_TEXT, "NOT NULL", USER_V3, NULL, false, false, false);
785 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
786 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_STORAGE], "storage_type", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", USER_V3, NULL, false, false, false);
787 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
788 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_STORAGE], "scan_status", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", USER_V3, NULL, false, false, false);
789 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
790 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_STORAGE], "validity", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 1", USER_V3, NULL, false, false, false);
791 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
794 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_FACE_SCAN_LIST], "media_uuid", MEDIA_SVC_DB_TYPE_TEXT, "NOT NULL", USER_V3, NULL, true, true, false);
795 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
796 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_FACE_SCAN_LIST], "storage_uuid", MEDIA_SVC_DB_TYPE_TEXT, "NOT NULL", USER_V3, NULL, false, false, false);
797 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
800 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_FACE], "face_uuid", MEDIA_SVC_DB_TYPE_TEXT, "PRIMARY KEY", USER_V3, NULL, true, false, false);
801 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
802 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_FACE], "media_uuid", MEDIA_SVC_DB_TYPE_TEXT, "NOT NULL", USER_V3, NULL, false, true, false);
803 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
804 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_FACE], "face_rect_x", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", USER_V3, NULL, false, false, false);
805 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
806 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_FACE], "face_rect_y", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", USER_V3, NULL, false, false, false);
807 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
808 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_FACE], "face_rect_w", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", USER_V3, NULL, false, false, false);
809 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
810 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_FACE], "face_rect_h", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", USER_V3, NULL, false, false, false);
811 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
812 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_FACE], "orientation", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", USER_V3, NULL, false, false, false);
813 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
814 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_FACE], "face_tag", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V3, NULL, false, false, false);
815 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
818 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_UHD], "media_uuid", MEDIA_SVC_DB_TYPE_TEXT, "PRIMARY KEY", USER_V4, NULL, true, true, false);
819 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
820 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_UHD], "storage_uuid", MEDIA_SVC_DB_TYPE_TEXT, "NOT NULL", USER_V4, "uhd_storage_id_idx", true, false, false);
821 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
822 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_UHD], "path", MEDIA_SVC_DB_TYPE_TEXT, "NOT NULL", USER_V4, NULL, false, false, false);
823 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
824 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_UHD], "size", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", USER_V4, NULL, false, false, false);
825 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
826 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_UHD], "content_id", MEDIA_SVC_DB_TYPE_TEXT, "NOT NULL", USER_V4, NULL, false, false, false);
827 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
828 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_UHD], "content_title", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V4, NULL, false, false, false);
829 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
830 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_UHD], "file_name", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V4, NULL, false, false, false);
831 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
832 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_UHD], "folder_uuid", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V4, NULL, false, false, false);
833 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
834 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_UHD], "release_date", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V4, NULL, false, false, false);
835 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
836 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_UHD], "modified_time", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", USER_V4, NULL, false, false, false);
837 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
838 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_UHD], "played_position", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", USER_V4, NULL, false, false, false);
839 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
840 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_UHD], "sub_type", MEDIA_SVC_DB_TYPE_INT, "DEFAULT -1", USER_V4, NULL, false, false, false);
841 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
842 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_UHD], "played_count", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", USER_V4, NULL, false, false, false);
843 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
846 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_PVR], "media_uuid", MEDIA_SVC_DB_TYPE_TEXT, "PRIMARY KEY", USER_V4, NULL, false, true, false);
847 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
848 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_PVR], "storage_uuid", MEDIA_SVC_DB_TYPE_TEXT, "NOT NULL", USER_V4, "pvr_storage_id_idx", true, false, false);
849 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
850 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_PVR], "path", MEDIA_SVC_DB_TYPE_TEXT, "NOT NULL", USER_V4, NULL, true, false, false);
851 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
852 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_PVR], "size", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", USER_V4, NULL, false, false, false);
853 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
854 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_PVR], "duration", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", USER_V4, NULL, false, false, false);
855 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
856 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_PVR], "timezone", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", USER_V4, NULL, false, false, false);
857 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
858 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_PVR], "ptc", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", USER_V4, NULL, false, false, false);
859 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
860 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_PVR], "major", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", USER_V4, NULL, false, false, false);
861 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
862 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_PVR], "minor", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", USER_V4, NULL, false, false, false);
863 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
864 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_PVR], "channel_type", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", USER_V4, NULL, false, false, false);
865 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
866 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_PVR], "channel_name", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V4, NULL, false, false, false);
867 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
868 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_PVR], "channel_num", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V4, NULL, false, false, false);
869 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
870 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_PVR], "program_title", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V4, NULL, false, false, false);
871 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
872 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_PVR], "program_num", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", USER_V4, NULL, false, false, false);
873 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
874 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_PVR], "program_crid", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V4, NULL, false, false, false);
875 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
876 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_PVR], "guidance", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V4, NULL, false, false, false);
877 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
878 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_PVR], "synopsis", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V4, NULL, false, false, false);
879 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
880 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_PVR], "genre", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V4, NULL, false, false, false);
881 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
882 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_PVR], "language", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V4, NULL, false, false, false);
883 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
884 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_PVR], "embargo_time", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", USER_V4, NULL, false, false, false);
885 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
886 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_PVR], "expiry_time", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", USER_V4, NULL, false, false, false);
887 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
888 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_PVR], "start_time", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", USER_V4, NULL, false, false, false);
889 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
890 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_PVR], "program_start_time", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", USER_V4, NULL, false, false, false);
891 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
892 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_PVR], "program_end_time", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", USER_V4, NULL, false, false, false);
893 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
894 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_PVR], "program_date", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", USER_V4, NULL, false, false, false);
895 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
896 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_PVR], "parental_rating", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", USER_V4, NULL, false, false, false);
897 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
898 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_PVR], "timer_record", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", USER_V4, NULL, false, false, false);
899 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
900 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_PVR], "series_record", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", USER_V4, NULL, false, false, false);
901 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
902 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_PVR], "hd", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", USER_V4, NULL, false, false, false);
903 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
904 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_PVR], "subtitle", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", USER_V4, NULL, false, false, false);
905 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
906 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_PVR], "ttx", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", USER_V4, NULL, false, false, false);
907 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
908 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_PVR], "ad", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", USER_V4, NULL, false, false, false);
909 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
910 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_PVR], "hard_of_hearing_radio", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", USER_V4, NULL, false, false, false);
911 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
912 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_PVR], "data_service", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", USER_V4, NULL, false, false, false);
913 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
914 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_PVR], "content_lock", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", USER_V4, NULL, false, false, false);
915 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
916 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_PVR], "content_watch", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", USER_V4, NULL, false, false, false);
917 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
918 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_PVR], "has_audio_only", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", USER_V4, NULL, false, false, false);
919 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
920 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_PVR], "is_local_record", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", USER_V4, NULL, false, false, false);
921 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
922 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_PVR], "resolution", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", USER_V4, NULL, false, false, false);
923 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
924 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_PVR], "aspectratio", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", USER_V4, NULL, false, false, false);
925 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
926 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_PVR], "modified_date", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V4, NULL, false, false, false);
927 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
928 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_PVR], "sports_type", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", USER_V4, NULL, false, false, false);
929 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
930 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_PVR], "guidance_length", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", USER_V4, NULL, false, false, false);
931 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
932 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_PVR], "tvmode", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", USER_V4, NULL, false, false, false);
933 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
934 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_PVR], "play_count", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", USER_V4, NULL, false, false, false);
935 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
936 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_PVR], "private_data", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V4, NULL, false, false, false);
937 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
938 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_PVR], "highlight", MEDIA_SVC_DB_TYPE_INT, "DEFAULT 0", USER_V4, NULL, false, false, false);
939 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
940 ret = __media_svc_add_column_info(&column_list[MEDIA_SVC_DB_LIST_PVR], "folder_uuid", MEDIA_SVC_DB_TYPE_TEXT, NULL, USER_V4, NULL, false, false, false);
941 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
945 void __media_svc_table_free(table_info_s *tb)
947 SAFE_FREE(tb->trigger_name);
948 SAFE_FREE(tb->view_name);
949 SAFE_FREE(tb->event_table);
950 SAFE_FREE(tb->action_table);
954 void __media_svc_column_free(column_info_s *col)
956 SAFE_FREE(col->name);
957 SAFE_FREE(col->type);
958 SAFE_FREE(col->option);
959 SAFE_FREE(col->index_name);
963 void _media_svc_destroy_table_query()
966 table_info_s *tb = NULL;
967 column_info_s *col_ptr = NULL;
971 tb = g_hash_table_lookup(table, MEDIA_SVC_DB_TABLE_MEDIA);
972 __media_svc_table_free(tb);
973 g_hash_table_remove(table, MEDIA_SVC_DB_TABLE_MEDIA);
975 tb = g_hash_table_lookup(table, MEDIA_SVC_DB_TABLE_FOLDER);
976 __media_svc_table_free(tb);
977 g_hash_table_remove(table, MEDIA_SVC_DB_TABLE_FOLDER);
979 tb = g_hash_table_lookup(table, MEDIA_SVC_DB_TABLE_PLAYLIST);
980 __media_svc_table_free(tb);
981 g_hash_table_remove(table, MEDIA_SVC_DB_TABLE_PLAYLIST);
983 tb = g_hash_table_lookup(table, MEDIA_SVC_DB_TABLE_PLAYLIST_MAP);
984 __media_svc_table_free(tb);
985 g_hash_table_remove(table, MEDIA_SVC_DB_TABLE_PLAYLIST_MAP);
987 tb = g_hash_table_lookup(table, MEDIA_SVC_DB_TABLE_ALBUM);
988 __media_svc_table_free(tb);
989 g_hash_table_remove(table, MEDIA_SVC_DB_TABLE_ALBUM);
991 tb = g_hash_table_lookup(table, MEDIA_SVC_DB_TABLE_TAG);
992 __media_svc_table_free(tb);
993 g_hash_table_remove(table, MEDIA_SVC_DB_TABLE_TAG);
995 tb = g_hash_table_lookup(table, MEDIA_SVC_DB_TABLE_TAG_MAP);
996 __media_svc_table_free(tb);
997 g_hash_table_remove(table, MEDIA_SVC_DB_TABLE_TAG_MAP);
999 tb = g_hash_table_lookup(table, MEDIA_SVC_DB_TABLE_BOOKMARK);
1000 __media_svc_table_free(tb);
1001 g_hash_table_remove(table, MEDIA_SVC_DB_TABLE_BOOKMARK);
1003 tb = g_hash_table_lookup(table, MEDIA_SVC_DB_TABLE_STORAGE);
1004 __media_svc_table_free(tb);
1005 g_hash_table_remove(table, MEDIA_SVC_DB_TABLE_STORAGE);
1007 tb = g_hash_table_lookup(table, MEDIA_SVC_DB_TABLE_UHD);
1008 __media_svc_table_free(tb);
1009 g_hash_table_remove(table, MEDIA_SVC_DB_TABLE_UHD);
1011 tb = g_hash_table_lookup(table, MEDIA_SVC_DB_TABLE_PVR);
1012 __media_svc_table_free(tb);
1013 g_hash_table_remove(table, MEDIA_SVC_DB_TABLE_PVR);
1015 g_hash_table_destroy(table);
1018 len = g_slist_length(column_list[MEDIA_SVC_DB_LIST_MEDIA]);
1020 for (i = 1; i < len; i++) {
1021 col_ptr = g_slist_nth_data(column_list[MEDIA_SVC_DB_LIST_MEDIA], i);
1022 __media_svc_column_free(col_ptr);
1025 len = g_slist_length(column_list[MEDIA_SVC_DB_LIST_FOLDER]);
1027 for (i = 1; i < len; i++) {
1028 col_ptr = g_slist_nth_data(column_list[MEDIA_SVC_DB_LIST_FOLDER], i);
1029 __media_svc_column_free(col_ptr);
1032 len = g_slist_length(column_list[MEDIA_SVC_DB_LIST_PLAYLIST_MAP]);
1034 for (i = 1; i < len; i++) {
1035 col_ptr = g_slist_nth_data(column_list[MEDIA_SVC_DB_LIST_PLAYLIST_MAP], i);
1036 __media_svc_column_free(col_ptr);
1039 len = g_slist_length(column_list[MEDIA_SVC_DB_LIST_PLAYLIST]);
1041 for (i = 1; i < len; i++) {
1042 col_ptr = g_slist_nth_data(column_list[MEDIA_SVC_DB_LIST_PLAYLIST], i);
1043 __media_svc_column_free(col_ptr);
1046 len = g_slist_length(column_list[MEDIA_SVC_DB_LIST_ALBUM]);
1048 for (i = 1; i < len; i++) {
1049 col_ptr = g_slist_nth_data(column_list[MEDIA_SVC_DB_LIST_ALBUM], i);
1050 __media_svc_column_free(col_ptr);
1053 len = g_slist_length(column_list[MEDIA_SVC_DB_LIST_TAG_MAP]);
1055 for (i = 1; i < len; i++) {
1056 col_ptr = g_slist_nth_data(column_list[MEDIA_SVC_DB_LIST_TAG_MAP], i);
1057 __media_svc_column_free(col_ptr);
1060 len = g_slist_length(column_list[MEDIA_SVC_DB_LIST_TAG]);
1062 for (i = 1; i < len; i++) {
1063 col_ptr = g_slist_nth_data(column_list[MEDIA_SVC_DB_LIST_TAG], i);
1064 __media_svc_column_free(col_ptr);
1067 len = g_slist_length(column_list[MEDIA_SVC_DB_LIST_BOOKMARK]);
1069 for (i = 1; i < len; i++) {
1070 col_ptr = g_slist_nth_data(column_list[MEDIA_SVC_DB_LIST_BOOKMARK], i);
1071 __media_svc_column_free(col_ptr);
1074 len = g_slist_length(column_list[MEDIA_SVC_DB_LIST_STORAGE]);
1076 for (i = 1; i < len; i++) {
1077 col_ptr = g_slist_nth_data(column_list[MEDIA_SVC_DB_LIST_STORAGE], i);
1078 __media_svc_column_free(col_ptr);
1081 for (i = 0; i < MEDIA_SVC_DB_LIST_MAX; i++)
1082 g_slist_free(column_list[i]);
1086 static int __media_svc_db_upgrade(sqlite3 *db_handle, int cur_version, uid_t uid)
1088 int ret = MS_MEDIA_ERR_NONE;
1091 ret = _media_svc_init_table_query(MEDIA_SVC_DB_TABLE_MEDIA);
1092 if (ret != MS_MEDIA_ERR_NONE) {
1093 media_svc_error("Query initialization failed");
1097 ret = _media_svc_upgrade_table_query(db_handle, MEDIA_SVC_DB_TABLE_MEDIA, MEDIA_SVC_DB_LIST_MEDIA, uid);
1098 if (ret != MS_MEDIA_ERR_NONE) {
1099 media_svc_error("_media_svc_upgrade_table_query failed");
1103 /* Upgrade issue in folder table */
1104 if (cur_version < USER_V4) {
1105 /* Create tmp table */
1106 sql = sqlite3_mprintf("CREATE TABLE '%q' AS SELECT * FROM '%q';", MEDIA_SVC_DB_TABLE_TMP_TABLE, MEDIA_SVC_DB_TABLE_FOLDER);
1108 media_svc_error("_media_svc_upgrade_table_query failed");
1109 ret = MS_MEDIA_ERR_OUT_OF_MEMORY;
1113 ret = _media_svc_sql_query(sql, uid);
1114 if (ret != MS_MEDIA_ERR_NONE)
1115 media_svc_error("Error when create backup folder table");
1116 SQLITE3_SAFE_FREE(sql);
1118 /* Drop original table */
1119 sql = sqlite3_mprintf("DROP TABLE '%q';", MEDIA_SVC_DB_TABLE_FOLDER);
1121 media_svc_error("_media_svc_upgrade_table_query failed");
1122 ret = MS_MEDIA_ERR_OUT_OF_MEMORY;
1126 ret = _media_svc_sql_query(sql, uid);
1127 if (ret != MS_MEDIA_ERR_NONE)
1128 media_svc_error("Error when drop table");
1129 SQLITE3_SAFE_FREE(sql);
1131 /* Create new table */
1132 ret = _media_svc_make_table_query(MEDIA_SVC_DB_TABLE_FOLDER, MEDIA_SVC_DB_LIST_FOLDER, uid);
1133 if (ret != MS_MEDIA_ERR_NONE) {
1134 media_svc_error("_media_svc_make_table_query failed");
1138 /* Insert into new table */
1139 sql = sqlite3_mprintf("INSERT INTO '%q'(folder_uuid, path, name, modified_time, name_pinyin, storage_type) SELECT folder_uuid, path, name, modified_time, name_pinyin, storage_type FROM '%q';", MEDIA_SVC_DB_TABLE_FOLDER, MEDIA_SVC_DB_TABLE_TMP_TABLE);
1141 media_svc_error("Query creation failed");
1142 ret = MS_MEDIA_ERR_OUT_OF_MEMORY;
1146 ret = _media_svc_sql_query(sql, uid);
1147 if (ret != MS_MEDIA_ERR_NONE)
1148 media_svc_error("Error when backup folder table");
1149 SQLITE3_SAFE_FREE(sql);
1152 sql = sqlite3_mprintf("DROP TABLE '%q';", MEDIA_SVC_DB_TABLE_TMP_TABLE);
1154 media_svc_error("Query creation failed");
1155 ret = MS_MEDIA_ERR_OUT_OF_MEMORY;
1159 ret = _media_svc_sql_query(sql, uid);
1160 if (ret != MS_MEDIA_ERR_NONE)
1161 media_svc_error("Error when drop backup folder table");
1162 SQLITE3_SAFE_FREE(sql);
1165 ret = _media_svc_upgrade_table_query(db_handle, MEDIA_SVC_DB_TABLE_FOLDER, MEDIA_SVC_DB_LIST_FOLDER, uid);
1166 if (ret != MS_MEDIA_ERR_NONE) {
1167 media_svc_error("_media_svc_upgrade_table_query failed");
1172 ret = _media_svc_upgrade_table_query(db_handle, MEDIA_SVC_DB_TABLE_PLAYLIST_MAP, MEDIA_SVC_DB_LIST_PLAYLIST_MAP, uid);
1173 if (ret != MS_MEDIA_ERR_NONE) {
1174 media_svc_error("_media_svc_upgrade_table_query failed");
1178 ret = _media_svc_upgrade_table_query(db_handle, MEDIA_SVC_DB_TABLE_PLAYLIST, MEDIA_SVC_DB_LIST_PLAYLIST, uid);
1179 if (ret != MS_MEDIA_ERR_NONE) {
1180 media_svc_error("_media_svc_upgrade_table_query failed");
1184 ret = _media_svc_upgrade_table_query(db_handle, MEDIA_SVC_DB_TABLE_ALBUM, MEDIA_SVC_DB_LIST_ALBUM, uid);
1185 if (ret != MS_MEDIA_ERR_NONE) {
1186 media_svc_error("_media_svc_upgrade_table_query failed");
1190 ret = _media_svc_upgrade_table_query(db_handle, MEDIA_SVC_DB_TABLE_TAG_MAP, MEDIA_SVC_DB_LIST_TAG_MAP, uid);
1191 if (ret != MS_MEDIA_ERR_NONE) {
1192 media_svc_error("_media_svc_upgrade_table_query failed");
1196 ret = _media_svc_upgrade_table_query(db_handle, MEDIA_SVC_DB_TABLE_TAG, MEDIA_SVC_DB_LIST_TAG, uid);
1197 if (ret != MS_MEDIA_ERR_NONE) {
1198 media_svc_error("_media_svc_upgrade_table_query failed");
1202 ret = _media_svc_upgrade_table_query(db_handle, MEDIA_SVC_DB_TABLE_BOOKMARK, MEDIA_SVC_DB_LIST_BOOKMARK, uid);
1203 if (ret != MS_MEDIA_ERR_NONE) {
1204 media_svc_error("_media_svc_upgrade_table_query failed");
1208 ret = _media_svc_upgrade_table_query(db_handle, MEDIA_SVC_DB_TABLE_STORAGE, MEDIA_SVC_DB_LIST_STORAGE, uid);
1209 if (ret != MS_MEDIA_ERR_NONE) {
1210 media_svc_error("_media_svc_upgrade_table_query failed");
1214 if (cur_version < USER_V4) {
1215 /* Need to default value in storage_uuid */
1216 sql = sqlite3_mprintf("UPDATE %q SET storage_uuid = '%q';", MEDIA_SVC_DB_TABLE_MEDIA, "media");
1218 media_svc_error("Query creation failed");
1219 ret = MS_MEDIA_ERR_OUT_OF_MEMORY;
1223 ret = _media_svc_sql_query(sql, uid);
1224 SQLITE3_SAFE_FREE(sql);
1226 sql = sqlite3_mprintf("UPDATE %q SET storage_uuid = '%q';", MEDIA_SVC_DB_TABLE_FOLDER, "media");
1228 media_svc_error("Query creation failed");
1229 ret = MS_MEDIA_ERR_OUT_OF_MEMORY;
1233 ret = _media_svc_sql_query(sql, uid);
1234 SQLITE3_SAFE_FREE(sql);
1237 ret = __media_svc_rebuild_view_query(db_handle, uid);
1239 sql = sqlite3_mprintf("PRAGMA user_version=%d;", LATEST_VERSION_NUMBER);
1241 media_svc_error("Query creation failed");
1242 ret = MS_MEDIA_ERR_OUT_OF_MEMORY;
1246 ret = _media_svc_sql_query(sql, uid);
1247 SQLITE3_SAFE_FREE(sql);
1249 _media_svc_destroy_table_query();
1254 _media_svc_destroy_table_query();
1259 int _media_svc_sql_query(const char *sql_str, uid_t uid)
1261 int ret = MS_MEDIA_ERR_NONE;
1263 media_svc_sec_debug("[SQL query] : %s", sql_str);
1265 ret = media_db_request_update_db(sql_str, uid);
1270 int _media_svc_get_user_version(sqlite3 *db_handle, int *user_version)
1272 int ret = MS_MEDIA_ERR_NONE;
1273 sqlite3_stmt *sql_stmt = NULL;
1274 char *sql = sqlite3_mprintf("PRAGMA user_version;");
1276 ret = _media_svc_sql_prepare_to_step(db_handle, sql, &sql_stmt);
1277 if (ret != MS_MEDIA_ERR_NONE) {
1278 media_svc_error("error when get user_version.");
1282 *user_version = sqlite3_column_int(sql_stmt, 0);
1283 SQLITE3_FINALIZE(sql_stmt);
1285 return MS_MEDIA_ERR_NONE;
1288 int _media_svc_sql_prepare_to_step(sqlite3 *handle, const char *sql_str, sqlite3_stmt **stmt)
1292 media_svc_sec_debug("[SQL query] : %s", sql_str);
1294 if (!STRING_VALID(sql_str)) {
1295 media_svc_error("invalid query");
1296 return MS_MEDIA_ERR_INVALID_PARAMETER;
1299 err = sqlite3_prepare_v2(handle, sql_str, -1, stmt, NULL);
1300 sqlite3_free((char *)sql_str);
1302 if (err != SQLITE_OK) {
1303 media_svc_error("prepare error %d[%s]", err, sqlite3_errmsg(handle));
1304 if (err == SQLITE_CORRUPT)
1305 return MS_MEDIA_ERR_DB_CORRUPT;
1306 else if (err == SQLITE_PERM)
1307 return MS_MEDIA_ERR_DB_PERMISSION;
1309 return MS_MEDIA_ERR_DB_INTERNAL;
1312 err = sqlite3_step(*stmt);
1313 if (err != SQLITE_ROW) {
1314 media_svc_error("[No-Error] Item not found. end of row [%s]", sqlite3_errmsg(handle));
1315 SQLITE3_FINALIZE(*stmt);
1316 return MS_MEDIA_ERR_DB_NO_RECORD;
1319 return MS_MEDIA_ERR_NONE;
1322 int _media_svc_sql_prepare_to_step_simple(sqlite3 *handle, const char *sql_str, sqlite3_stmt **stmt)
1326 media_svc_sec_debug("[SQL query] : %s", sql_str);
1328 if (!STRING_VALID(sql_str)) {
1329 media_svc_error("invalid query");
1330 return MS_MEDIA_ERR_INVALID_PARAMETER;
1333 err = sqlite3_prepare_v2(handle, sql_str, -1, stmt, NULL);
1334 sqlite3_free((char *)sql_str);
1336 if (err != SQLITE_OK) {
1337 media_svc_error("prepare error %d[%s]", err, sqlite3_errmsg(handle));
1338 if (err == SQLITE_CORRUPT)
1339 return MS_MEDIA_ERR_DB_CORRUPT;
1340 else if (err == SQLITE_PERM)
1341 return MS_MEDIA_ERR_DB_PERMISSION;
1343 return MS_MEDIA_ERR_DB_INTERNAL;
1346 return MS_MEDIA_ERR_NONE;
1349 int _media_svc_sql_begin_trans(uid_t uid)
1351 int ret = MS_MEDIA_ERR_NONE;
1353 media_svc_error("========_media_svc_sql_begin_trans");
1355 ret = media_db_request_update_db_batch_start("BEGIN IMMEDIATE;", uid);
1360 int _media_svc_sql_end_trans(uid_t uid)
1362 int ret = MS_MEDIA_ERR_NONE;
1364 media_svc_error("========_media_svc_sql_end_trans");
1366 ret = media_db_request_update_db_batch_end("COMMIT;", uid);
1371 int _media_svc_sql_rollback_trans(uid_t uid)
1373 media_svc_error("========_media_svc_sql_rollback_trans");
1375 return _media_svc_sql_query("ROLLBACK;", uid);
1378 int _media_svc_sql_query_list(GList **query_list, uid_t uid)
1380 int ret = MS_MEDIA_ERR_NONE;
1382 int length = g_list_length(*query_list);
1384 char query_bundle[MEDIA_SVC_QUERY_LEN_MAX] = {0, };
1388 media_svc_debug("query list length : [%d]", length);
1390 memset(query_bundle, 0, sizeof(query_bundle));
1392 for (idx = 0; idx < length; idx++) {
1393 sql = (char *)g_list_nth_data(*query_list, idx);
1394 if (STRING_VALID(sql)) {
1395 query_len = strlen(sql);
1397 if (query_len >= (sizeof(query_bundle) - 1)) {
1398 media_svc_error("NEED TO CHECK FILE : A single query size exceeds 8k [%d]", query_len);
1399 SQLITE3_SAFE_FREE(sql);
1403 if ((total_len + query_len) >= (sizeof(query_bundle) - 1)) {
1404 ret = media_db_request_update_db_batch(query_bundle, uid);
1405 if (ret != MS_MEDIA_ERR_NONE)
1406 media_svc_error("media_db_request_update_db_batch failed : %d", ret);
1408 memset(query_bundle, 0, sizeof(query_bundle));
1410 /* NEED TO CHECK : If a single query size is over 8K, drop it. */
1411 /* Consider inserting the basic information without metadata */
1412 /* Refer : SQLITE3 spec In Tizen 3.0 */
1413 /* Single query limit size = 1 billion bytes(1GiB) */
1414 /* DB limit size = 1 billion bytes(1GiB) */
1415 /* column limit = 2000 */
1418 SAFE_STRLCAT(query_bundle, sql, sizeof(query_bundle));
1419 total_len += query_len;
1421 SQLITE3_SAFE_FREE(sql);
1425 if (total_len > 0) {
1426 ret = media_db_request_update_db_batch(query_bundle, uid);
1427 if (ret != MS_MEDIA_ERR_NONE)
1428 media_svc_error("media_db_request_update_db_batch failed : %d", ret);
1430 memset(query_bundle, 0, sizeof(query_bundle));
1434 _media_svc_sql_query_release(query_list);
1436 return MS_MEDIA_ERR_NONE;
1440 void _media_svc_sql_query_add(GList **query_list, char **query)
1442 *query_list = g_list_append(*query_list, *query);
1445 void _media_svc_sql_query_release(GList **query_list)
1448 media_svc_debug("_svc_sql_query_release");
1449 g_list_free(*query_list);
1454 int _media_svc_check_db_upgrade(sqlite3 *db_handle, int user_version, uid_t uid)
1456 if (user_version < LATEST_VERSION_NUMBER) {
1457 media_svc_error("Current DB is out of date(%d).. So start to upgrade DB(%d)", user_version, LATEST_VERSION_NUMBER);
1458 return __media_svc_db_upgrade(db_handle, user_version, uid);
1460 return MS_MEDIA_ERR_NONE;
1464 int _media_db_check_corrupt(sqlite3 *db_handle)
1466 int ret = MS_MEDIA_ERR_NONE;
1467 char *sql = sqlite3_mprintf("PRAGMA quick_check(1)");
1468 sqlite3_stmt *sql_stmt = NULL;
1469 char *result = NULL;
1471 ret = _media_svc_sql_prepare_to_step(db_handle, sql, &sql_stmt);
1472 if (ret != MS_MEDIA_ERR_NONE) {
1473 media_svc_error("error when check db. err = [%d]", ret);
1477 result = (char *)sqlite3_column_text(sql_stmt, 0);
1478 SQLITE3_FINALIZE(sql_stmt);
1480 if (result != NULL) {
1481 media_svc_debug("result %s", result);
1482 if (strcasecmp(result, "OK"))
1483 ret = MS_MEDIA_ERR_DB_CORRUPT;
1485 media_svc_error("result is NULL");
1486 ret = MS_MEDIA_ERR_DB_INTERNAL;
1493 int _media_svc_create_media_table_with_id(const char *table_id, uid_t uid)
1495 int ret = MS_MEDIA_ERR_NONE;
1497 ret = _media_svc_init_table_query(table_id);
1498 if (ret != MS_MEDIA_ERR_NONE) {
1499 media_svc_error("_media_svc_init_table_query failed");
1503 ret = _media_svc_make_table_query(table_id, MEDIA_SVC_DB_LIST_MEDIA, uid);
1504 if (ret != MS_MEDIA_ERR_NONE) {
1505 media_svc_error("_media_svc_make_table_query failed");
1509 /* Add for trigger */
1510 ret = _media_svc_make_table_query(MEDIA_SVC_DB_TABLE_FOLDER, MEDIA_SVC_DB_LIST_FOLDER, uid);
1511 if (ret != MS_MEDIA_ERR_NONE) {
1512 media_svc_error("_media_svc_make_table_query failed");
1516 ret = _media_svc_make_table_query(MEDIA_SVC_DB_TABLE_PLAYLIST_MAP, MEDIA_SVC_DB_LIST_PLAYLIST_MAP, uid);
1517 if (ret != MS_MEDIA_ERR_NONE) {
1518 media_svc_error("_media_svc_make_table_query failed");
1522 ret = _media_svc_make_table_query(MEDIA_SVC_DB_TABLE_ALBUM, MEDIA_SVC_DB_LIST_ALBUM, uid);
1523 if (ret != MS_MEDIA_ERR_NONE) {
1524 media_svc_error("_media_svc_make_table_query failed");
1528 ret = _media_svc_make_table_query(MEDIA_SVC_DB_TABLE_TAG_MAP, MEDIA_SVC_DB_LIST_TAG_MAP, uid);
1529 if (ret != MS_MEDIA_ERR_NONE) {
1530 media_svc_error("_media_svc_make_table_query failed");
1534 ret = _media_svc_make_table_query(MEDIA_SVC_DB_TABLE_BOOKMARK, MEDIA_SVC_DB_LIST_BOOKMARK, uid);
1535 if (ret != MS_MEDIA_ERR_NONE) {
1536 media_svc_error("_media_svc_make_table_query failed");
1540 ret = _media_svc_make_table_query(MEDIA_SVC_DB_TABLE_UHD, MEDIA_SVC_DB_LIST_UHD, uid);
1541 if (ret != MS_MEDIA_ERR_NONE) {
1542 media_svc_error("_media_svc_make_table_query failed");
1546 ret = _media_svc_make_table_query(MEDIA_SVC_DB_TABLE_PVR, MEDIA_SVC_DB_LIST_PVR, uid);
1547 if (ret != MS_MEDIA_ERR_NONE) {
1548 media_svc_error("_media_svc_make_table_query failed");
1552 _media_svc_destroy_table_query();
1557 _media_svc_destroy_table_query();
1562 int _media_svc_drop_media_table(const char *storage_id, uid_t uid)
1564 int ret = MS_MEDIA_ERR_NONE;
1566 char *sql = sqlite3_mprintf("DROP TABLE IF EXISTS '%q'", storage_id);
1568 ret = _media_svc_sql_query(sql, uid);
1569 SQLITE3_SAFE_FREE(sql);
1574 int _media_svc_update_media_view(sqlite3 *db_handle, uid_t uid)
1576 int ret = MS_MEDIA_ERR_NONE;
1578 sqlite3_stmt *sql_stmt = NULL;
1581 GList *storage_list = NULL;
1582 char view_query[MEDIA_SVC_QUERY_LEN_NORMAL] = {0, };
1583 memset(view_query, 0x00, sizeof(view_query));
1585 snprintf(view_query, sizeof(view_query), "DROP VIEW IF EXISTS %s; CREATE VIEW IF NOT EXISTS %s AS SELECT * from %s ", MEDIA_SVC_DB_VIEW_MEDIA, MEDIA_SVC_DB_VIEW_MEDIA, MEDIA_SVC_DB_TABLE_MEDIA);
1587 /*Select list of storage*/
1588 sql = sqlite3_mprintf("SELECT storage_uuid FROM '%s' WHERE validity=1 AND storage_uuid != '%s'", MEDIA_SVC_DB_TABLE_STORAGE, MEDIA_SVC_DB_TABLE_MEDIA);
1589 ret = _media_svc_sql_prepare_to_step_simple(db_handle, sql, &sql_stmt);
1590 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
1592 while (sqlite3_step(sql_stmt) == SQLITE_ROW) {
1593 if (STRING_VALID((const char *)sqlite3_column_text(sql_stmt, 0)))
1594 storage_list = g_list_append(storage_list, strdup((char *)sqlite3_column_text(sql_stmt, 0)));
1596 SQLITE3_FINALIZE(sql_stmt);
1598 if ((storage_list != NULL) && (g_list_length(storage_list) > 0)) {
1599 item_cnt = g_list_length(storage_list);
1601 for (idx = 0; idx < item_cnt; idx++) {
1603 char *storage_id = NULL;
1604 storage_id = g_list_nth_data(storage_list, idx);
1606 if (STRING_VALID(storage_id)) {
1607 /*Select list of storage*/
1608 sql = sqlite3_mprintf("SELECT COUNT(*) FROM SQLITE_MASTER WHERE type='table' and name='%q'", storage_id);
1609 ret = _media_svc_sql_prepare_to_step(db_handle, sql, &sql_stmt);
1610 if (ret != MS_MEDIA_ERR_NONE) {
1611 SAFE_FREE(storage_id);
1615 table_cnt = sqlite3_column_int(sql_stmt, 0);
1616 SQLITE3_FINALIZE(sql_stmt);
1618 if (table_cnt > 0) {
1619 char append_query[128] = {0, };
1620 memset(append_query, 0x00, sizeof(append_query));
1621 snprintf(append_query, sizeof(append_query), " UNION SELECT * from '%s'", storage_id);
1622 SAFE_STRLCAT(view_query, append_query, sizeof(view_query));
1624 media_svc_error("media table not exist for storage [%s]", storage_id);
1627 SAFE_FREE(storage_id);
1630 g_list_free(storage_list);
1633 ret = _media_svc_sql_query(view_query, uid);
1634 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);