diff options
author | SeungYeup Kim <sy2004.kim@samsung.com> | 2013-03-26 09:58:47 +0900 |
---|---|---|
committer | SeungYeup Kim <sy2004.kim@samsung.com> | 2013-03-26 09:58:47 +0900 |
commit | 61f38f29b535fe15fa350ecea21d227e3cbc83ff (patch) | |
tree | 04b04aa758fd6a79a8b37c11397d17e5956c065c | |
parent | c730f3f4388308376030ce8b4aad8b43cabf9b43 (diff) | |
download | libslp-db-util-61f38f29b535fe15fa350ecea21d227e3cbc83ff.tar.gz libslp-db-util-61f38f29b535fe15fa350ecea21d227e3cbc83ff.tar.bz2 libslp-db-util-61f38f29b535fe15fa350ecea21d227e3cbc83ff.zip |
Create localized collation on demand
-rwxr-xr-x | collation.c | 3 | ||||
-rwxr-xr-x | 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); |