}
ret = sqlite3_exec(db, "pragma integrity_check", __integrity_callback, NULL, NULL);
+
+ if (true == need_to_remove || SQLITE_CORRUPT == ret || SQLITE_NOTADB == ret) {
+ /* LCOV_EXCL_START */
+ ERR("Delete db");
+ db_util_close(db);
+ return -2;
+ /* LCOV_EXCL_STOP */
+ }
+
+ /* check if table is missing */
+ sqlite3_stmt *stmt = NULL;
+ const char *query = "SELECT count(*) FROM sqlite_master WHERE type='table'"
+ " AND name IN ('schedule_table','rrule_table','normal_instance_table',"
+ "'allday_instance_table','attendee_table','calendar_table','timezone_table',"
+ "'alarm_table','extended_table','deleted_table','version_table')";
+ ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
+ if (SQLITE_OK != ret) {
+ /* LCOV_EXCL_START */
+ ERR("sqlite3_qlite3_prepare_v2() Fail(%d)", ret);
+ db_util_close(db);
+ return SQLITE_ERROR == ret ? -2 : -1; /* return -2, when sqlite_master does not exist */
+ /* LCOV_EXCL_STOP */
+ }
+
+ ret = sqlite3_step(stmt);
+ if (SQLITE_ROW != ret) {
+ /* LCOV_EXCL_START */
+ ERR("sqlite3_step() Fail(%d)", ret);
+ sqlite3_finalize(stmt);
+ db_util_close(db);
+ return -1;
+ /* LCOV_EXCL_STOP */
+ }
+
+ int get_count = sqlite3_column_int(stmt, 0);
+ sqlite3_finalize(stmt);
db_util_close(db);
- if (true == need_to_remove || SQLITE_CORRUPT == ret || SQLITE_NOTADB == ret)
+ if (get_count != CAL_TABLE_COUNT) {
+ /* LCOV_EXCL_START */
+ ERR("Table is missing(expected(%d) but result(%d)", CAL_TABLE_COUNT, get_count);
return -2;
+ /* LCOV_EXCL_STOP */
+ }
return 0;
}
#define CAL_TABLE_UTIME_INSTANCE "normal_instance_table"
#define CAL_TABLE_LOCALTIME_INSTANCE "allday_instance_table"
#define CAL_TABLE_EXTENDED "extended_table"
+/* MUST MACTH table count */
+#define CAL_TABLE_COUNT 11
/* for event or todo.. */
#define CAL_VIEW_TABLE_EVENT "event_view"