4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Hakjoo Ko <hakjoo.ko@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 "util-func.h"
26 #include "collation.h"
27 #include "db-util-debug.h"
29 static int __db_util_busyhandler(void *pData, int count)
32 DB_UTIL_TRACE_DEBUG("Busy Handler Called! : PID(%d) / CNT(%d)\n", getpid(), count+1);
33 usleep((count+1)*100000);
36 DB_UTIL_TRACE_DEBUG("Busy Handler will be returned SQLITE_BUSY error : PID(%d) \n", getpid());
41 static int __db_util_open(sqlite3 *ppDB)
46 DB_UTIL_TRACE_WARNING("Invalid input param error");
50 /* Register Busy handler */
51 rc = sqlite3_busy_handler(ppDB, __db_util_busyhandler, NULL);
52 if (SQLITE_OK != rc) {
53 DB_UTIL_TRACE_WARNING("Fail to register busy handler\n");
58 #ifdef SET_PERSIST_JOURNAL_MODE
59 /* Code to change default journal mode of sqlite3 is enabled so this option is disabled */
60 /* Enable persist journal mode */
61 rc = sqlite3_exec(ppDB, "PRAGMA journal_mode = PERSIST",
62 NULL, NULL, &pszErrorMsg);
63 if (SQLITE_OK != rc) {
64 DB_UTIL_TRACE_WARNING("Fail to change journal mode: %d, %d, %s, %s\n",
65 sqlite3_errcode(ppDB),
66 sqlite3_extended_errcode(ppDB),
68 sqlite3_errmsg(ppDB));
69 sqlite3_free(pszErrorMsg);
75 db_util_create_collation(ppDB, DB_UTIL_COL_LS_AS_CI,
76 DB_UTIL_COL_UTF8, "localized");
78 if (DB_UTIL_OK != rc) {
79 DB_UTIL_TRACE_WARNING("Fail to create collation");
87 int db_util_open(const char *pszFilePath, sqlite3 **ppDB, int nOption)
89 char *pszErrorMsg = NULL;
91 if((pszFilePath == NULL) || (ppDB == NULL)) {
92 DB_UTIL_TRACE_WARNING("Invalid input param error");
97 int rc = sqlite3_open(pszFilePath, ppDB);
98 if (SQLITE_OK != rc) {
102 rc = __db_util_open(*ppDB);
107 int db_util_open_with_options(const char *pszFilePath, sqlite3 **ppDB,
108 int flags, const char *zVfs)
110 char *pszErrorMsg = NULL;
112 if((pszFilePath == NULL) || (ppDB == NULL)) {
113 DB_UTIL_TRACE_WARNING("sqlite3 handle null error");
114 return DB_UTIL_ERROR;
118 int rc = sqlite3_open_v2(pszFilePath, ppDB, flags, zVfs);
119 if (SQLITE_OK != rc) {
123 rc = __db_util_open(*ppDB);
128 int db_util_close(sqlite3 *ppDB)
130 char *pszErrorMsg = NULL;
133 int rc = sqlite3_close(ppDB);
134 if (SQLITE_OK != rc) {
135 DB_UTIL_TRACE_WARNING("Fail to change journal mode: %s\n", pszErrorMsg);
136 sqlite3_free(pszErrorMsg);