4 * Copyright (c) 2012 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
27 #include "cal_internal.h"
28 #include "cal_typedef.h"
32 static inline int __remake_db_file(char* db_path)
37 char db_file[CAL_STR_MIDDLE_LEN] = {0};
39 snprintf(db_file, sizeof(db_file), "%s/%s", db_path ? db_path : DB_PATH, CALS_DB_NAME);
41 ret = db_util_open(db_file, &db, 0);
42 if (SQLITE_OK != ret) {
44 ERR("db_util_open() Fail(%d) ", ret);
49 ret = sqlite3_exec(db, schema_query, NULL, 0, &errmsg);
50 if (SQLITE_OK != ret) {
52 ERR("sqlite3_exec() Fail[%s]", errmsg);
62 static inline int __check_db_file(char* db_path)
65 char db_file[CAL_STR_MIDDLE_LEN] = {0,};
66 snprintf(db_file, sizeof(db_file), "%s/%s", db_path ? db_path : DB_PATH, CALS_DB_NAME);
69 fd = open(db_file, O_RDONLY);
72 ERR("DB file(%s) is not exist(err:%d) ", db_file, fd);
80 int cal_server_schema_check(void)
82 if (__check_db_file(NULL))
83 __remake_db_file(NULL);