From 61f38f29b535fe15fa350ecea21d227e3cbc83ff Mon Sep 17 00:00:00 2001 From: SeungYeup Kim Date: Tue, 26 Mar 2013 09:58:47 +0900 Subject: Create localized collation on demand --- collation.c | 3 +-- util_func.c | 37 ++++++++++++++++++++----------------- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/collation.c b/collation.c index 64c7a25..5b38fb5 100755 --- a/collation.c +++ b/collation.c @@ -302,7 +302,7 @@ static int __db_util_collate_icu_8_lc(void *ucol, int str1_len, const void *str1 char* str_from = (char*)str1; char* str_to = (char*)str1; glong v1_char_len, v2_char_len; - int ret, i; + int i; #ifdef DB_UTIL_ENABLE_DEVDEBUG DB_UTIL_TRACE_DEBUG("__db_util_collate_icu_8_lc func start \n"); @@ -472,7 +472,6 @@ int db_util_create_collation( { int ret = DB_UTIL_OK; UErrorCode status = U_ZERO_ERROR; - char *dl_error = NULL; const char* locale = NULL; DB_UTIL_TRACE_DEBUG("db_util_create_collation start"); diff --git a/util_func.c b/util_func.c index ba242f3..393d50d 100755 --- a/util_func.c +++ b/util_func.c @@ -38,42 +38,49 @@ static int __db_util_busyhandler(void *pData, int count) } } -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"); @@ -86,8 +93,6 @@ static int __db_util_open(sqlite3 *ppDB) 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; @@ -107,8 +112,6 @@ int db_util_open(const char *pszFilePath, sqlite3 **ppDB, int nOption) 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; @@ -125,12 +128,12 @@ int db_util_open_with_options(const char *pszFilePath, sqlite3 **ppDB, 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); -- cgit v1.2.3