return result;
}
-static int __uam_db_check_table_creation(void)
-{
- FUNC_ENTRY;
- int error_code = UAM_ERROR_DB_FAILED;
-
- if (!__uam_db_is_table_existing(UAM_DB_USERDATA_TABLE))
- return error_code;
-
- if (!__uam_db_is_table_existing(UAM_DB_DEVICES_TABLE))
- return error_code;
-
- if (!__uam_db_is_table_existing(UAM_DB_SERVICES_TABLE))
- return error_code;
-
- if (!__uam_db_is_table_existing(UAM_DB_DEVICE_SERVICES_TABLE))
- return error_code;
-
- if (!__uam_db_is_table_existing(UAM_DB_IBEACON_ADV_TABLE))
- return error_code;
-
- UAM_DBG("Successfully verified table creation");
- FUNC_EXIT;
- return UAM_ERROR_NONE;
-}
-
static int __uam_db_check_integrity_cb(
void *err, int count, char **data, char **columns)
{
return ret;
}
-static void __uam_db_prepare_table(void)
+static int __uam_db_check_table_creation(void)
{
+ FUNC_ENTRY;
+ int error_code = UAM_ERROR_DB_FAILED;
+
/*
* 4) Each __is_table_existing() open DB file again and again.. it is redundant
*/
if (!__uam_db_is_table_existing(UAM_DB_USERDATA_TABLE))
- __uam_db_create_table(CREATE_USERDATA_TABLE);
+ retv_if(UAM_ERROR_NONE != __uam_db_create_table(CREATE_USERDATA_TABLE), error_code);
if (!__uam_db_is_table_existing(UAM_DB_DEVICES_TABLE))
- __uam_db_create_table(CREATE_DEVICES_TABLE);
+ retv_if(UAM_ERROR_NONE != __uam_db_create_table(CREATE_DEVICES_TABLE), error_code);
if (!__uam_db_is_table_existing(UAM_DB_SERVICES_TABLE))
- __uam_db_create_table(CREATE_SERVICES_TABLE);
+ retv_if(UAM_ERROR_NONE != __uam_db_create_table(CREATE_SERVICES_TABLE), error_code);
if (!__uam_db_is_table_existing(UAM_DB_DEVICE_SERVICES_TABLE))
- __uam_db_create_table(CREATE_DEVICE_SERVICES_TABLE);
+ retv_if(UAM_ERROR_NONE != __uam_db_create_table(CREATE_DEVICE_SERVICES_TABLE), error_code);
if (!__uam_db_is_table_existing(UAM_DB_IBEACON_ADV_TABLE))
- __uam_db_create_table(CREATE_IBEACON_ADV_TABLE);
+ retv_if(UAM_ERROR_NONE != __uam_db_create_table(CREATE_IBEACON_ADV_TABLE), error_code);
+
+ UAM_DBG("Successfully verified table creation");
+ FUNC_EXIT;
+ return UAM_ERROR_NONE;
}
static int __uam_db_verify()
/* set locking mode */
retv_if(UAM_ERROR_NONE != __uam_db_set_locking_mode(), UAM_ERROR_DB_FAILED);
+ UAM_DBG("Successfully verified database");
return UAM_ERROR_NONE;
}
{
FUNC_ENTRY;
char *sql;
- /* open database */
- retv_if(SQLITE_OK != __uam_db_open(), UAM_ERROR_DB_FAILED);
- if (UAM_ERROR_NONE != __uam_db_verify()) {
- UAM_ERR("Failed to verify database");
- sqlite3_close(database);
- unlink(DATABASE_FULL_PATH);
- database = NULL;
+ int max_retries = 2;
- /* Reopen database */
+ do{
+ /* open database */
retv_if(SQLITE_OK != __uam_db_open(), UAM_ERROR_DB_FAILED);
- }
- __uam_db_prepare_table();
+ if (UAM_ERROR_NONE != __uam_db_verify()) {
+ UAM_ERR("Failed to verify database");
+ sqlite3_close(database);
+ unlink(DATABASE_FULL_PATH);
+ database = NULL;
+ } else {
+ break;
+ }
+ } while(max_retries--);
/*
* 3) Default journal mode is PERIST so it seems use-less.