return 1;
}
+static int __uam_db_check_integrity_cb(void *err, int count, char **data, char **columns)
+{
+ FUNC_ENTRY;
+ int i;
+
+ for (i = 0; i < count; i++) {
+ UAM_DBG("%s = %s\n", columns[i], data[i] ? data[i] : "NULL");
+ if (!g_strcmp0(columns[i], "integrity_check") && !g_strcmp0(data[i], "ok")) return 0;
+ }
+ return 1;
+}
+
+static int __uam_db_check_table_cb(void *err, int count, char **data, char **columns)
+{
+ FUNC_ENTRY;
+ int i;
+
+ for (i = 0; i < count; i++) {
+ UAM_DBG("%s = %s\n", columns[i], data[i] ? data[i] : "NULL");
+ if (!g_strcmp0(columns[i], "count") && !g_strcmp0(data[i], "1")) return 0;
+ }
+ return 1;
+}
+
static int __ua_device_db_initialize_once(void)
{
FUNC_ENTRY;
}
res = sqlite3_open(DATABASE_FULL_PATH, &database);
-
if (res != SQLITE_OK) {
// TODO : Can add logic of retry if not able to open
UAM_ERR("Error in opening database %s: %s", DATABASE_FULL_PATH, sqlite3_errmsg(database));
return UAM_ERROR_DB_FAILED;
}
-
UAM_DBG("Successfully opened database");
size_t db_size = _uam_getFilesize(DATABASE_FULL_PATH);
}
UAM_DBG("Database size: %d", db_size);
- res = sqlite3_exec(database, "PRAGMA integrity_check", 0, 0, 0);
-
+ res = sqlite3_exec(database, "PRAGMA integrity_check", __uam_db_check_integrity_cb, 0, 0);
if (res != SQLITE_OK) {
UAM_ERR("Can't verify database integrity %s",
sqlite3_errmsg(database));
}
UAM_DBG("Successfully verified database integrity");
- res = sqlite3_exec(database, "PRAGMA locking_mode = NORMAL", 0, 0, 0);
+ res = sqlite3_exec(database,
+ "SELECT count(*) as count FROM sqlite_master WHERE type='table' AND name='devices'",
+ __uam_db_check_table_cb, 0, 0);
+ if (res != SQLITE_OK) {
+ UAM_ERR("Can't verify table creation %s",
+ sqlite3_errmsg(database));
+ sqlite3_close(database);
+ database = NULL;
+ FUNC_EXIT;
+ return UAM_ERROR_DB_FAILED;
+ }
+ UAM_DBG("Successfully verified table creation");
+ res = sqlite3_exec(database, "PRAGMA locking_mode = NORMAL", 0, 0, 0);
if (res != SQLITE_OK) {
UAM_ERR("Can't set locking mode %s, skip set busy handler.",
sqlite3_errmsg(database));
return 1;
}
+static int __uam_db_check_integrity_cb(void *err, int count, char **data, char **columns)
+{
+ FUNC_ENTRY;
+ int i;
+
+ for (i = 0; i < count; i++) {
+ UAM_DBG("%s = %s\n", columns[i], data[i] ? data[i] : "NULL");
+ if (!g_strcmp0(columns[i], "integrity_check") && !g_strcmp0(data[i], "ok")) return 0;
+ }
+ return 1;
+}
+
+static int __uam_db_check_table_cb(void *err, int count, char **data, char **columns)
+{
+ FUNC_ENTRY;
+ int i;
+
+ for (i = 0; i < count; i++) {
+ UAM_DBG("%s = %s\n", columns[i], data[i] ? data[i] : "NULL");
+ if (!g_strcmp0(columns[i], "count") && !g_strcmp0(data[i], "1")) return 0;
+ }
+ return 1;
+}
+
static int __ua_device_service_db_initialize_once(void)
{
FUNC_ENTRY;
}
res = sqlite3_open(DATABASE_FULL_PATH, &database);
-
if (res != SQLITE_OK) {
// TODO : Can add logic of retry if not able to open
UAM_ERR("Error in opening database %s: %s", DATABASE_FULL_PATH, sqlite3_errmsg(database));
return UAM_ERROR_DB_FAILED;
}
-
UAM_DBG("Successfully opened database");
size_t db_size = _uam_getFilesize(DATABASE_FULL_PATH);
}
UAM_DBG("Database size: %d", db_size);
- res = sqlite3_exec(database, "PRAGMA integrity_check", 0, 0, 0);
-
+ res = sqlite3_exec(database, "PRAGMA integrity_check", __uam_db_check_integrity_cb, 0, 0);
if (res != SQLITE_OK) {
UAM_ERR("Can't verify database integrity %s",
sqlite3_errmsg(database));
}
UAM_DBG("Successfully verified database integrity");
- res = sqlite3_exec(database, "PRAGMA locking_mode = NORMAL", 0, 0, 0);
+ res = sqlite3_exec(database,
+ "SELECT count(*) as count FROM sqlite_master WHERE type='table' AND name='device_services'",
+ __uam_db_check_table_cb, 0, 0);
+ if (res != SQLITE_OK) {
+ UAM_ERR("Can't verify table creation %s",
+ sqlite3_errmsg(database));
+ sqlite3_close(database);
+ database = NULL;
+ FUNC_EXIT;
+ return UAM_ERROR_DB_FAILED;
+ }
+ UAM_DBG("Successfully verified table creation");
+ res = sqlite3_exec(database, "PRAGMA locking_mode = NORMAL", 0, 0, 0);
if (res != SQLITE_OK) {
UAM_ERR("Can't set locking mode %s, skip set busy handler.",
sqlite3_errmsg(database));
return 1;
}
+static int __uam_db_check_integrity_cb(void *err, int count, char **data, char **columns)
+{
+ FUNC_ENTRY;
+ int i;
+
+ for (i = 0; i < count; i++) {
+ UAM_DBG("%s = %s\n", columns[i], data[i] ? data[i] : "NULL");
+ if (!g_strcmp0(columns[i], "integrity_check") && !g_strcmp0(data[i], "ok")) return 0;
+ }
+ return 1;
+}
+
+static int __uam_db_check_table_cb(void *err, int count, char **data, char **columns)
+{
+ FUNC_ENTRY;
+ int i;
+
+ for (i = 0; i < count; i++) {
+ UAM_DBG("%s = %s\n", columns[i], data[i] ? data[i] : "NULL");
+ if (!g_strcmp0(columns[i], "count") && !g_strcmp0(data[i], "1")) return 0;
+ }
+ return 1;
+}
+
static int __ua_service_db_initialize_once(void)
{
FUNC_ENTRY;
}
res = sqlite3_open(DATABASE_FULL_PATH, &database);
-
if (res != SQLITE_OK) {
// TODO : Can add logic of retry if not able to open
UAM_ERR("Error in opening database %s: %s", DATABASE_FULL_PATH, sqlite3_errmsg(database));
return UAM_ERROR_DB_FAILED;
}
-
UAM_DBG("Successfully opened database");
size_t db_size = _uam_getFilesize(DATABASE_FULL_PATH);
if (db_size == 0) {
- UAM_ERR("Database size is 0");
- return UAM_ERROR_DB_FAILED;
+ UAM_ERR("Database size is 0");
+ return UAM_ERROR_DB_FAILED;
}
UAM_DBG("Database size: %d", db_size);
- res = sqlite3_exec(database, "PRAGMA integrity_check", 0, 0, 0);
-
+ res = sqlite3_exec(database, "PRAGMA integrity_check", __uam_db_check_integrity_cb, 0, 0);
if (res != SQLITE_OK) {
UAM_ERR("Can't verify database integrity %s",
sqlite3_errmsg(database));
}
UAM_DBG("Successfully verified database integrity");
- res = sqlite3_exec(database, "PRAGMA locking_mode = NORMAL", 0, 0, 0);
+ res = sqlite3_exec(database,
+ "SELECT count(*) as count FROM sqlite_master WHERE type='table' AND name='services'",
+ __uam_db_check_table_cb, 0, 0);
+ if (res != SQLITE_OK) {
+ UAM_ERR("Can't verify table creation %s",
+ sqlite3_errmsg(database));
+ sqlite3_close(database);
+ database = NULL;
+ FUNC_EXIT;
+ return UAM_ERROR_DB_FAILED;
+ }
+ UAM_DBG("Successfully verified table creation");
+ res = sqlite3_exec(database, "PRAGMA locking_mode = NORMAL", 0, 0, 0);
if (res != SQLITE_OK) {
UAM_ERR("Can't set locking mode %s, skip set busy handler.",
sqlite3_errmsg(database));
return 1;
}
+static int __uam_db_check_integrity_cb(void *err, int count, char **data, char **columns)
+{
+ FUNC_ENTRY;
+ int i;
+
+ for (i = 0; i < count; i++) {
+ UAM_DBG("%s = %s\n", columns[i], data[i] ? data[i] : "NULL");
+ if (!g_strcmp0(columns[i], "integrity_check") && !g_strcmp0(data[i], "ok")) return 0;
+ }
+ return 1;
+}
+
+static int __uam_db_check_table_cb(void *err, int count, char **data, char **columns)
+{
+ FUNC_ENTRY;
+ int i;
+
+ for (i = 0; i < count; i++) {
+ UAM_DBG("%s = %s\n", columns[i], data[i] ? data[i] : "NULL");
+ if (!g_strcmp0(columns[i], "count") && !g_strcmp0(data[i], "1")) return 0;
+ }
+ return 1;
+}
+
static int __ua_db_initialize_once(void)
{
FUNC_ENTRY;
}
res = sqlite3_open(DATABASE_FULL_PATH, &database);
-
if (res != SQLITE_OK) {
// TODO : Can add logic of retry if not able to open
UAM_ERR("Error in opening database %s: %s", DATABASE_FULL_PATH, sqlite3_errmsg(database));
return UAM_ERROR_DB_FAILED;
}
-
UAM_DBG("Successfully opened database");
size_t db_size = _uam_getFilesize(DATABASE_FULL_PATH);
}
UAM_DBG("Database size: %d", db_size);
- res = sqlite3_exec(database, "PRAGMA integrity_check", 0, 0, 0);
-
+ res = sqlite3_exec(database, "PRAGMA integrity_check", __uam_db_check_integrity_cb, 0, 0);
if (res != SQLITE_OK) {
UAM_ERR("Can't verify database integrity %s",
sqlite3_errmsg(database));
}
UAM_DBG("Successfully verified database integrity");
- res = sqlite3_exec(database, "PRAGMA locking_mode = NORMAL", 0, 0, 0);
+ res = sqlite3_exec(database,
+ "SELECT count(*) as count FROM sqlite_master WHERE type='table' AND name='userdata'",
+ __uam_db_check_table_cb, 0, 0);
+ if (res != SQLITE_OK) {
+ UAM_ERR("Can't verify table creation %s",
+ sqlite3_errmsg(database));
+ sqlite3_close(database);
+ database = NULL;
+ FUNC_EXIT;
+ return UAM_ERROR_DB_FAILED;
+ }
+ UAM_DBG("Successfully verified table creation");
+ res = sqlite3_exec(database, "PRAGMA locking_mode = NORMAL", 0, 0, 0);
if (res != SQLITE_OK) {
UAM_ERR("Can't set locking mode %s, skip set busy handler.",
sqlite3_errmsg(database));