From 3ecf1e1043e43dd00a4c2913a5caa2bb9babc909 Mon Sep 17 00:00:00 2001 From: Sungmin Kwak Date: Wed, 1 Nov 2017 14:35:33 +0900 Subject: [PATCH] Add sqlite3_free() and some code cleanup Change-Id: I4931c9a4dca2ba2318aaf9ff6a3be155d0a30465 (cherry picked from commit 46505b7eba681cc2768242afa08b72e1313d9f96) --- ism/src/isf_query_utility.cpp | 90 +++++++++++++++++++++---------------------- 1 file changed, 44 insertions(+), 46 deletions(-) diff --git a/ism/src/isf_query_utility.cpp b/ism/src/isf_query_utility.cpp index a1240bd..aca3eef 100644 --- a/ism/src/isf_query_utility.cpp +++ b/ism/src/isf_query_utility.cpp @@ -171,12 +171,11 @@ static inline int _db_create_ime_info(void) if (ret != SQLITE_OK) { LOGE ("sqlite3_exec returned %d: %s\n", ret, pException); sqlite3_free(pException); + databaseInfo.need_reset = true; return -EIO; } - if (sqlite3_changes(databaseInfo.pHandle) == 0) { - LOGD ("The database is not changed.\n"); - } + LOGD("CREATE TABLE ime_info"); return 0; } @@ -209,10 +208,11 @@ static inline int _db_init(void) if (lstat(databaseInfo.pPath, &stat) < 0) { char buf_err[256]; - LOGE("%s\n", strerror_r (errno, buf_err, sizeof (buf_err))); + LOGE("lstat failed. %s\n", strerror_r (errno, buf_err, sizeof (buf_err))); if (databaseInfo.pHandle) db_util_close(databaseInfo.pHandle); databaseInfo.pHandle = NULL; + databaseInfo.need_reset = true; return -EIO; } @@ -221,11 +221,12 @@ static inline int _db_init(void) if (databaseInfo.pHandle) db_util_close(databaseInfo.pHandle); databaseInfo.pHandle = NULL; + databaseInfo.need_reset = true; return -EINVAL; } if (!stat.st_size) { - LOGE ("The RPM file has not been installed properly.\n"); + LOGE ("The empty db"); _db_create_table(); } @@ -236,10 +237,11 @@ static inline int _db_init(void) if (ret != SQLITE_OK) { databaseInfo.need_reset = true; LOGE ("sqlite3_exec returned %d: %s\n", ret, pException); + sqlite3_free(pException); } } - if (SQLITE_CORRUPT == sqlite3_exec(databaseInfo.pHandle, "pragma integrity_check",_db_integrity_check_cb, NULL, NULL)) { + if (SQLITE_CORRUPT == sqlite3_exec(databaseInfo.pHandle, "pragma integrity_check", _db_integrity_check_cb, NULL, NULL)) { databaseInfo.need_reset = true; LOGE ("DB has been corrupted.\n"); } @@ -295,15 +297,13 @@ static int _db_select_all_ime_info(std::vector &ime_info) static const char* pQuery = "SELECT * FROM ime_info;"; char *db_text; - do { - if (i == 0) { - ret = sqlite3_prepare_v2(databaseInfo.pHandle, pQuery, -1, &pStmt, NULL); - if (ret != SQLITE_OK) { - LOGE ("sqlite3_prepare_v2: %s\n", sqlite3_errmsg(databaseInfo.pHandle)); - return 0; - } - } + ret = sqlite3_prepare_v2(databaseInfo.pHandle, pQuery, -1, &pStmt, NULL); + if (ret != SQLITE_OK) { + LOGE ("sqlite3_prepare_v2: %s\n", sqlite3_errmsg(databaseInfo.pHandle)); + return 0; + } + do { ret = sqlite3_step(pStmt); if (ret == SQLITE_ROW) { db_text = (char *)sqlite3_column_text(pStmt, 0); @@ -407,19 +407,19 @@ static int _db_select_ime_info_by_appid(const char *appid, ImeInfoDB *pImeInfo) ret = sqlite3_prepare_v2(databaseInfo.pHandle, pQuery, -1, &pStmt, NULL); if (ret != SQLITE_OK) { - LOGE ("%s\n", sqlite3_errmsg(databaseInfo.pHandle)); + LOGE ("sqlite3_prepare_v2: %s\n", sqlite3_errmsg(databaseInfo.pHandle)); return 0; } ret = sqlite3_bind_text(pStmt, 1, appid, -1, SQLITE_TRANSIENT); if (ret != SQLITE_OK) { - LOGE ("%s\n", sqlite3_errmsg(databaseInfo.pHandle)); + LOGE ("sqlite3_bind_text: %s\n", sqlite3_errmsg(databaseInfo.pHandle)); goto out; } ret = sqlite3_step(pStmt); if (ret != SQLITE_ROW) { - LOGE ("%s\n", sqlite3_errmsg(databaseInfo.pHandle)); + LOGE ("sqlite3_step: %s\n", sqlite3_errmsg(databaseInfo.pHandle)); goto out; } i = 1; @@ -494,21 +494,19 @@ static int _db_select_module_name_by_mode(TOOLBAR_MODE_T mode, std::vector &ap ret = sqlite3_prepare_v2(databaseInfo.pHandle, pQuery, -1, &pStmt, NULL); if (ret != SQLITE_OK) { - LOGE ("%s\n", sqlite3_errmsg(databaseInfo.pHandle)); + LOGE ("sqlite3_prepare_v2: %s\n", sqlite3_errmsg(databaseInfo.pHandle)); return 0; } ret = sqlite3_bind_text(pStmt, 1, pkgid, -1, SQLITE_TRANSIENT); if (ret != SQLITE_OK) { - LOGE ("%s\n", sqlite3_errmsg(databaseInfo.pHandle)); + LOGE ("sqlite3_bind_text: %s\n", sqlite3_errmsg(databaseInfo.pHandle)); goto out; } @@ -642,19 +640,19 @@ static int _db_select_is_enabled_by_appid(const char *appid, bool *is_enabled) ret = sqlite3_prepare_v2(databaseInfo.pHandle, pQuery, -1, &pStmt, NULL); if (ret != SQLITE_OK) { - LOGE ("%s\n", sqlite3_errmsg(databaseInfo.pHandle)); + LOGE ("sqlite3_prepare_v2: %s\n", sqlite3_errmsg(databaseInfo.pHandle)); return i; } ret = sqlite3_bind_text(pStmt, 1, appid, -1, SQLITE_TRANSIENT); if (ret != SQLITE_OK) { - LOGE ("%s\n", sqlite3_errmsg(databaseInfo.pHandle)); + LOGE ("sqlite3_bind_text: %s\n", sqlite3_errmsg(databaseInfo.pHandle)); goto out; } ret = sqlite3_step(pStmt); if (ret != SQLITE_ROW) { - LOGE ("%s\n", sqlite3_errmsg(databaseInfo.pHandle)); + LOGE ("sqlite3_step: %s\n", sqlite3_errmsg(databaseInfo.pHandle)); } else { *is_enabled = (bool)sqlite3_column_int(pStmt, 0); @@ -684,13 +682,13 @@ static int _db_select_count_by_module_name(const char *module_name) ret = sqlite3_prepare_v2(databaseInfo.pHandle, pQuery, -1, &pStmt, NULL); if (ret != SQLITE_OK) { - LOGE ("%s\n", sqlite3_errmsg(databaseInfo.pHandle)); + LOGE ("sqlite3_prepare_v2: %s\n", sqlite3_errmsg(databaseInfo.pHandle)); return 0; } ret = sqlite3_bind_text(pStmt, 1, module_name, -1, SQLITE_TRANSIENT); if (ret != SQLITE_OK) { - LOGE ("%s\n", sqlite3_errmsg(databaseInfo.pHandle)); + LOGE ("sqlite3_bind_text: %s\n", sqlite3_errmsg(databaseInfo.pHandle)); goto out; } @@ -841,7 +839,7 @@ static int _db_update_is_enabled_by_appid(const char *appid, bool is_enabled) ret = sqlite3_bind_int(pStmt, 1, (int)is_enabled); if (ret != SQLITE_OK) { - LOGE ("%s\n", sqlite3_errmsg(databaseInfo.pHandle)); + LOGE ("sqlite3_bind_int: %s\n", sqlite3_errmsg(databaseInfo.pHandle)); goto out; } @@ -896,7 +894,7 @@ static int _db_update_has_option_by_appid(const char *appid, bool has_option) ret = sqlite3_bind_int(pStmt, 1, (int)has_option); if (ret != SQLITE_OK) { - LOGE ("%s\n", sqlite3_errmsg(databaseInfo.pHandle)); + LOGE ("sqlite3_bind_int: %s\n", sqlite3_errmsg(databaseInfo.pHandle)); goto out; } @@ -981,7 +979,7 @@ static int _db_update_ime_info(ImeInfoDB *ime_db) ret = sqlite3_bind_int(pStmt, 5, has_option); if (ret != SQLITE_OK) { - LOGE ("%s\n", sqlite3_errmsg(databaseInfo.pHandle)); + LOGE ("sqlite3_bind_int: %s\n", sqlite3_errmsg(databaseInfo.pHandle)); goto out; } @@ -1160,7 +1158,7 @@ static int _db_delete_ime_info_by_pkgid(const char *pkgid) ret = sqlite3_prepare_v2(databaseInfo.pHandle, pQuery, -1, &pStmt, NULL); if (ret != SQLITE_OK) { - LOGE ("%s\n", sqlite3_errmsg(databaseInfo.pHandle)); + LOGE ("sqlite3_prepare_v2: %s\n", sqlite3_errmsg(databaseInfo.pHandle)); return i; } @@ -1202,7 +1200,7 @@ static int _db_delete_ime_info_by_appid(const char *appid) ret = sqlite3_prepare_v2(databaseInfo.pHandle, pQuery, -1, &pStmt, NULL); if (ret != SQLITE_OK) { - LOGE ("%s\n", sqlite3_errmsg(databaseInfo.pHandle)); + LOGE ("sqlite3_prepare_v2: %s\n", sqlite3_errmsg(databaseInfo.pHandle)); return i; } @@ -1242,7 +1240,7 @@ static int _db_delete_ime_info(void) ret = sqlite3_prepare_v2(databaseInfo.pHandle, pQuery, -1, &pStmt, NULL); if (ret != SQLITE_OK) { - LOGE ("%s\n", sqlite3_errmsg(databaseInfo.pHandle)); + LOGE ("sqlite3_prepare_v2: %s\n", sqlite3_errmsg(databaseInfo.pHandle)); return i; } -- 2.7.4