}
}
-static int __db_util_open(sqlite3 *ppDB)
+void __db_util_collation_cb(void* pArg, sqlite3* pDB, int eTextRep, const char* szName)
+{
+ if (eTextRep == SQLITE_UTF8 && !strcmp(szName, "localized"))
+ db_util_create_collation(pDB, DB_UTIL_COL_LS_AS_CI,
+ DB_UTIL_COL_UTF8, "localized");
+}
+
+static int __db_util_open(sqlite3 *pDB)
{
int rc = 0;
- if(ppDB == NULL) {
+ if(pDB == NULL) {
DB_UTIL_TRACE_WARNING("Invalid input param error");
return DB_UTIL_ERROR;
}
/* Register Busy handler */
- rc = sqlite3_busy_handler(ppDB, __db_util_busyhandler, NULL);
+ rc = sqlite3_busy_handler(pDB, __db_util_busyhandler, NULL);
if (SQLITE_OK != rc) {
DB_UTIL_TRACE_WARNING("Fail to register busy handler\n");
- sqlite3_close(ppDB);
+ sqlite3_close(pDB);
return rc;
}
#ifdef SET_PERSIST_JOURNAL_MODE
/* Code to change default journal mode of sqlite3 is enabled so this option is disabled */
/* Enable persist journal mode */
- rc = sqlite3_exec(ppDB, "PRAGMA journal_mode = PERSIST",
+ rc = sqlite3_exec(pDB, "PRAGMA journal_mode = PERSIST",
NULL, NULL, &pszErrorMsg);
if (SQLITE_OK != rc) {
DB_UTIL_TRACE_WARNING("Fail to change journal mode: %d, %d, %s, %s\n",
- sqlite3_errcode(ppDB),
- sqlite3_extended_errcode(ppDB),
+ sqlite3_errcode(pDB),
+ sqlite3_extended_errcode(pDB),
pszErrorMsg,
- sqlite3_errmsg(ppDB));
+ sqlite3_errmsg(pDB));
sqlite3_free(pszErrorMsg);
- sqlite3_close(ppDB);
+ sqlite3_close(pDB);
return rc;
}
#endif
- db_util_create_collation(ppDB, DB_UTIL_COL_LS_AS_CI,
- DB_UTIL_COL_UTF8, "localized");
+ sqlite3_collation_needed(pDB, NULL, __db_util_collation_cb);
+
#if 0
if (DB_UTIL_OK != rc) {
DB_UTIL_TRACE_WARNING("Fail to create collation");
int db_util_open(const char *pszFilePath, sqlite3 **ppDB, int nOption)
{
- char *pszErrorMsg = NULL;
-
if((pszFilePath == NULL) || (ppDB == NULL)) {
DB_UTIL_TRACE_WARNING("Invalid input param error");
return DB_UTIL_ERROR;
int db_util_open_with_options(const char *pszFilePath, sqlite3 **ppDB,
int flags, const char *zVfs)
{
- char *pszErrorMsg = NULL;
-
if((pszFilePath == NULL) || (ppDB == NULL)) {
DB_UTIL_TRACE_WARNING("sqlite3 handle null error");
return DB_UTIL_ERROR;
return rc;
}
-int db_util_close(sqlite3 *ppDB)
+int db_util_close(sqlite3 *pDB)
{
char *pszErrorMsg = NULL;
/* Close DB */
- int rc = sqlite3_close(ppDB);
+ int rc = sqlite3_close(pDB);
if (SQLITE_OK != rc) {
DB_UTIL_TRACE_WARNING("Fail to change journal mode: %s\n", pszErrorMsg);
sqlite3_free(pszErrorMsg);