return query;
}
-static int _recover_db(void)
+static int _create_db_table(sqlite3 *db)
{
- int ret = STICKERD_SERVER_ERROR_NONE;
- sqlite3 *db = NULL;
char *err = NULL;
-
- LOGD("Start to recover sticker db");
- //Remove sticker database file
- if (unlink(STICKER_DB_PATH) == -1)
- LOGE("Failed to remove db file");
-
- ret = sqlite3_open_v2(STICKER_DB_PATH, &db, SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE, NULL);
- if (ret != SQLITE_OK) {
- LOGE("Failed to open db : %s", sqlite3_errmsg(db));
- if (unlink(STICKER_DB_PATH) == -1)
- LOGE("Failed to remove db file");
- ret = STICKERD_SERVER_ERROR_DB_FAILED;
- goto cleanup;
- }
+ int ret = STICKERD_SERVER_ERROR_NONE;
ret = sqlite3_exec(db, STICKER_INFO_CREATE_TABLE, NULL, NULL, &err);
if (ret != SQLITE_OK) {
if (ret != SQLITE_OK) {
LOGE("Failed to create sticker_group_info table : %s", err);
ret = STICKERD_SERVER_ERROR_DB_FAILED;
- goto cleanup;
}
- is_corrupted = FALSE;
-
cleanup:
if (err)
sqlite3_free(err);
+ return ret;
+}
+
+static int _recover_db(void)
+{
+ int ret = STICKERD_SERVER_ERROR_NONE;
+ sqlite3 *db = NULL;
+
+ LOGD("Start to recover sticker db");
+ //Remove sticker database file
+ if (unlink(STICKER_DB_PATH) == -1)
+ LOGE("Failed to remove db file");
+
+ ret = sqlite3_open_v2(STICKER_DB_PATH, &db, SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE, NULL);
+ if (ret != SQLITE_OK) {
+ LOGE("Failed to open db : %s", sqlite3_errmsg(db));
+ if (unlink(STICKER_DB_PATH) == -1)
+ LOGE("Failed to remove db file");
+ ret = STICKERD_SERVER_ERROR_DB_FAILED;
+ goto cleanup;
+ }
+
+ ret = _create_db_table(db);
+ if (ret != SQLITE_OK)
+ goto cleanup;
+
+ is_corrupted = FALSE;
+
+cleanup:
if (db)
sqlite3_close(db);
goto cleanup;
}
- ret = sqlite3_exec(db, STICKER_INFO_CREATE_TABLE, NULL, NULL, &err);
- if (ret != SQLITE_OK) {
- LOGE("Failed to create sticker_info table : %s" , err);
- ret = STICKERD_SERVER_ERROR_DB_FAILED;
- goto cleanup;
- }
-
- ret = sqlite3_exec(db, STICKER_KEYWORD_INFO_CREATE_TABLE, NULL, NULL, &err);
- if (ret != SQLITE_OK) {
- LOGE("Failed to create sticker_keyword_info table : %s", err);
- ret = STICKERD_SERVER_ERROR_DB_FAILED;
- goto cleanup;
- }
-
- ret = sqlite3_exec(db, STICKER_WHITELIST_INFO_CREATE_TABLE, NULL, NULL, &err);
- if (ret != SQLITE_OK) {
- LOGE("Failed to create sticker_whitelist_info table : %s", err);
- ret = STICKERD_SERVER_ERROR_DB_FAILED;
- goto cleanup;
- }
-
- ret = sqlite3_exec(db, STICKER_RECENT_HISTORY_INFO_CREATE_TABLE, NULL, NULL, &err);
- if (ret != SQLITE_OK) {
- LOGE("Failed to create sticker_recent_history_info table : %s", err);
- ret = STICKERD_SERVER_ERROR_DB_FAILED;
- goto cleanup;
- }
-
- ret = sqlite3_exec(db, STICKER_GROUP_INFO_CREATRE_TABLE, NULL, NULL, &err);
- if (ret != SQLITE_OK) {
- LOGE("Failed to create sticker_group_info table : %s", err);
- ret = STICKERD_SERVER_ERROR_DB_FAILED;
+ ret = _create_db_table(db);
+ if (ret != SQLITE_OK)
goto cleanup;
- }
ret = sqlite3_exec(db, "PRAGMA journal_mode = WAL", NULL, NULL, &err);
if (ret != SQLITE_OK) {