/************************************************************************************************** Function Name: integritycheck* function Description: Database integrity detection * Input parameters: None * Output parameters: None * return value: 0: Full/1: Damage * Other Instructions: * Revision date version number modified content *-------------------- ---------------------------* *********************************************************************************** /#defineDB_OK0/* Full */#defineDB_ERROR1/* Damage */sqlite3 *obj_db;char g_objfile[255] = "DB.DB3"; int Integritycheck (void) {/* Open database */sqlite3_open (G_objfile, &obj_db); BOOL integrityverified = db_error;sqlite3_stmt *integrity = null;//integrity_check check includes: Disorderly sequence of records, missing pages, incorrect records, lost indexes, uniqueness constraints, Non-null constraint//if (SQLITE3_PREPARE_V2 (obj_db, "PRAGMA integrity_check;",-1, &integrity, NULL) = = SQLITE_OK)//quick_check No Check constraints, take shorter if (Sqlite3_prepare_v2 (obj_db, "PRAGMA quick_check;",-1, &integrity, NULL) = = Sqlite_ok) {while (SQL Ite3_step (Integrity) = = Sqlite_row) {Const unsigned char *result = sqlite3_column_text (integrity, 0); if (Result && strcmp ((const char *) result, (const char *) "OK") = = 0) {integrityverified = Db_ok;break;}} Sqlite3_finalize (integrity);} /* Close Database */sqlite3_close (obj_db); return integrityverified;}
SQLite Database Integrity Detection