return WIDGET_ERROR_NONE;
}
-static int _recover_db(sqlite3 *db, const char *path, uid_t uid, bool is_init)
+static int _recover_db(const char *path, uid_t uid, bool is_init)
{
+ sqlite3 *db;
int ret;
char *errmsg = NULL;
_I("DB recovery process start");
- if (db)
- sqlite3_close(db);
- unlink(path);
+ if (access(path, F_OK) == 0)
+ unlink(path);
ret = sqlite3_open_v2(path, &db,
SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE,
NULL);
if (ret != SQLITE_OK) {
_E("Failed to open db[%d]", ret);
+ sqlite3_close_v2(db);
unlink(path);
return WIDGET_ERROR_FAULT;
}
ret = sqlite3_exec(db, CREATE_WIDGET_TABLE, NULL, NULL, &errmsg);
- sqlite3_close(db);
+ sqlite3_close_v2(db);
if (ret != SQLITE_OK) {
_E("Failed to exec query[%d][%s]", ret, errmsg);
sqlite3_free(errmsg);
_check_integrity_cb, NULL, &errmsg);
if (ret != SQLITE_OK || _is_corrupted) {
_E("Failed to exec query[%d][%s]", ret, errmsg);
- if (errmsg)
- sqlite3_free(errmsg);
+ sqlite3_free(errmsg);
return WIDGET_ERROR_FAULT;
}
if (ret != SQLITE_OK) {
/* LCOV_EXCL_START */
_E("prepare error: %s", sqlite3_errmsg(db));
- sqlite3_close_v2(db);
return WIDGET_ERROR_FAULT;
/* LCOV_EXCL_STOP */
}
sqlite3_finalize(stmt);
if (idx != WIDGET_TBL_COUNT) {
_E("wrong table count");
- sqlite3_close_v2(db);
return WIDGET_ERROR_FAULT;
}
ret = sqlite3_open_v2(path, &db, SQLITE_OPEN_READONLY, NULL);
if (ret != SQLITE_OK) {
/* LCOV_EXCL_START */
- ret = _recover_db(db, path, uid, is_init);
- return ret;
+ sqlite3_close_v2(db);
+ return _recover_db(path, uid, is_init);
/* LCOV_EXCL_STOP */
}
/* check integrity */
ret = _integrity_check(db);
if (ret != WIDGET_ERROR_NONE) {
- ret = _recover_db(db, path, uid, is_init);
- return ret;
+ sqlite3_close_v2(db);
+ return _recover_db(path, uid, is_init);
}
/* check table exist */
ret = _check_table_exist(db);
- if (ret != WIDGET_ERROR_NONE) {
- ret = _recover_db(db, path, uid, is_init);
- return ret;
- }
- sqlite3_close(db);
+ sqlite3_close_v2(db);
+ if (ret != WIDGET_ERROR_NONE)
+ return _recover_db(path, uid, is_init);
return WIDGET_ERROR_NONE;
}