diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/rua_stat_internal.c | 33 |
1 files changed, 13 insertions, 20 deletions
diff --git a/src/rua_stat_internal.c b/src/rua_stat_internal.c index 254e7d3..5fd59e6 100644 --- a/src/rua_stat_internal.c +++ b/src/rua_stat_internal.c @@ -171,37 +171,30 @@ static int __create_table(sqlite3 *db) return 0; } -static sqlite3 *__db_init(sqlite3 *db, char *root, int flags) +int _rua_stat_init(sqlite3 **db, int flags) { + char defname[FILENAME_MAX]; + const char *rua_stat_db_path = tzplatform_getenv(TZ_USER_DB); int r; - r = db_util_open_with_options(root, &db, flags, NULL); + snprintf(defname, sizeof(defname), "%s/%s", rua_stat_db_path, RUA_STAT_DB_NAME); + r = db_util_open_with_options(defname, db, flags, NULL); if (r) { LOGE("db util open error(%d/%d/%d/%s)", r, - sqlite3_errcode(db), - sqlite3_extended_errcode(db), - sqlite3_errmsg(db)); + sqlite3_errcode(*db), + sqlite3_extended_errcode(*db), + sqlite3_errmsg(*db)); return NULL; } - r = __create_table(db); + + r = __create_table(*db); if (r) { - db_util_close(db); + db_util_close(*db); return NULL; } - return db; -} - -int _rua_stat_init(sqlite3 *db, int flags) -{ - char defname[FILENAME_MAX]; - const char *rua_stat_db_path = tzplatform_getenv(TZ_USER_DB); - - snprintf(defname, sizeof(defname), "%s/%s", rua_stat_db_path, RUA_STAT_DB_NAME); - __db_init(db, defname, flags); - - if (db == NULL) { + if (*db == NULL) { LOGW("__rua_stat_init error"); return -1; } @@ -226,7 +219,7 @@ int rua_stat_db_update(char *caller, char *rua_stat_tag) LOGD("rua_stat_update start"); - r = _rua_stat_init(db, SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE); + r = _rua_stat_init(&db, SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE); if (r == -1) { LOGE("__rua_stat_init fail"); return -1; |