#include "badge_error.h"
#include "badge_internal.h"
-#define BADGE_DB_NAME ".badge.db"
#define CREATE_BADGE_TABLE " \
PRAGMA journal_mode = PERSIST; \
PRAGMA synchronous = FULL; \
EXPORT_API
int badge_db_init()
{
- int r;
+ int ret = BADGE_ERROR_NONE;
+ int sql_ret;
sqlite3 *db = NULL;
char *errmsg = NULL;
- char defname[FILENAME_MAX];
- const char *db_path = tzplatform_getenv(TZ_SYS_DB);
- if (db_path == NULL) {
- ERR("fail to get db_path");
- return BADGE_ERROR_OUT_OF_MEMORY;
- }
- snprintf(defname, sizeof(defname), "%s/%s", db_path, BADGE_DB_NAME);
- DBG("db path : %s", defname);
- r = sqlite3_open_v2(defname, &db, SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE, NULL);
- if (r) {
- db_util_close(db);
- ERR("fail to open badge db %d", r);
- return BADGE_ERROR_IO_ERROR;
+ sql_ret = sqlite3_open_v2(BADGE_DB_PATH, &db,
+ SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE, NULL);
+ if (sql_ret != SQLITE_OK) {
+ ERR("Failed to open badge db[%d]", sql_ret);
+ return BADGE_ERROR_FROM_DB;
}
- r = sqlite3_exec(db, CREATE_BADGE_TABLE, NULL, NULL, &errmsg);
+ sql_ret = sqlite3_exec(db, CREATE_BADGE_TABLE, NULL, NULL, &errmsg);
+ if (sql_ret != SQLITE_OK) {
+ ERR("Failed to exec query[%d][%s]", sql_ret, errmsg);
+ ret = BADGE_ERROR_FROM_DB;
+ }
- if (r != SQLITE_OK) {
- ERR("query error(%d)(%s)", r, errmsg);
+ if (errmsg)
sqlite3_free(errmsg);
+
+ if (db)
db_util_close(db);
- return BADGE_ERROR_IO_ERROR;
- }
- db_util_close(db);
- return BADGE_ERROR_NONE;
+ return ret;
}
EXPORT_API