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.
22 #include "media-util-err.h"
23 #include "media-svc-debug.h"
24 #include "media-svc-env.h"
25 #include "media-svc-db-utils.h"
26 #include "media-svc-util.h"
27 #include "media-svc-storage.h"
29 int _media_svc_init_storage(sqlite3 *handle, uid_t uid)
31 int ret = MS_MEDIA_ERR_NONE;
33 sqlite3_stmt *sql_stmt = NULL;
36 /*Add Internal storage*/
37 sql = sqlite3_mprintf("SELECT COUNT(*) FROM '%s' WHERE storage_uuid='%s'", MEDIA_SVC_DB_TABLE_STORAGE, MEDIA_SVC_DB_TABLE_MEDIA);
38 ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
39 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
41 storage_cnt = sqlite3_column_int(sql_stmt, 0);
42 SQLITE3_FINALIZE(sql_stmt);
46 sql = sqlite3_mprintf("INSERT INTO %s (storage_uuid, storage_name, storage_path, storage_type) VALUES ('%s', '%s', '%s', 0);",
47 MEDIA_SVC_DB_TABLE_STORAGE, MEDIA_SVC_DB_TABLE_MEDIA, MEDIA_SVC_DB_TABLE_MEDIA, _media_svc_get_path(uid));
49 ret = _media_svc_sql_query(handle, sql, uid);
51 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
57 int _media_svc_append_storage(sqlite3 *handle, const char *storage_id, const char *storage_name, const char *storage_path, const char *storage_account, media_svc_storage_type_e storage_type, uid_t uid)
59 int ret = MS_MEDIA_ERR_NONE;
60 char *sql = sqlite3_mprintf("INSERT INTO %s (storage_uuid, storage_name, storage_path, storage_account, storage_type) values (%Q, %Q, %Q, %Q, %d); ",
61 MEDIA_SVC_DB_TABLE_STORAGE, storage_id, storage_name, storage_path, storage_account, storage_type);
63 ret = _media_svc_sql_query(handle, sql, uid);
69 int _media_svc_delete_storage(sqlite3 *handle, const char *storage_id, uid_t uid)
71 int ret = MS_MEDIA_ERR_NONE;
72 char *sql = sqlite3_mprintf("DELETE FROM '%s' WHERE storage_uuid=%Q", MEDIA_SVC_DB_TABLE_STORAGE, storage_id);
74 ret = _media_svc_sql_query(handle, sql, uid);
80 int _media_svc_update_storage_validity(sqlite3 *handle, const char *storage_id, int validity, uid_t uid)
82 int ret = MS_MEDIA_ERR_NONE;
85 if (storage_id == NULL) {
86 sql = sqlite3_mprintf("UPDATE '%s' SET validity=%d WHERE storage_uuid != 'media';", MEDIA_SVC_DB_TABLE_STORAGE, validity);
88 sql = sqlite3_mprintf("UPDATE '%s' SET validity=%d WHERE storage_uuid=%Q;", MEDIA_SVC_DB_TABLE_STORAGE, validity, storage_id);
91 ret = _media_svc_sql_query(handle, sql, uid);