summaryrefslogtreecommitdiff
path: root/util_func.c
diff options
context:
space:
mode:
authorSeungYeup Kim <sy2004.kim@samsung.com>2013-03-26 09:58:47 +0900
committerSeungYeup Kim <sy2004.kim@samsung.com>2013-03-26 09:58:47 +0900
commit61f38f29b535fe15fa350ecea21d227e3cbc83ff (patch)
tree04b04aa758fd6a79a8b37c11397d17e5956c065c /util_func.c
parentc730f3f4388308376030ce8b4aad8b43cabf9b43 (diff)
downloadlibslp-db-util-61f38f29b535fe15fa350ecea21d227e3cbc83ff.tar.gz
libslp-db-util-61f38f29b535fe15fa350ecea21d227e3cbc83ff.tar.bz2
libslp-db-util-61f38f29b535fe15fa350ecea21d227e3cbc83ff.zip
Create localized collation on demand
Diffstat (limited to 'util_func.c')
-rwxr-xr-xutil_func.c37
1 files changed, 20 insertions, 17 deletions
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);