標籤:error pen open sig 版本 prepare column res result
/************************************************************************************************** 函數名稱: IntegrityCheck* 功能描述: 資料庫完整性檢測* 輸入參數: 無 * 輸出參數: 無* 返 回 值: 0:完整 / 1:損壞 * 其它說明:* 修改日期 版本號碼 修改人 修改內容* -----------------------------------------------* **************************************************************************************************/#defineDB_OK0/* 完整 */#defineDB_ERROR1/* 損壞 */sqlite3 *obj_db;char g_objfile[255] = "DB.db3";int IntegrityCheck(void){/*開啟資料庫*/sqlite3_open( g_objfile, &obj_db );BOOL integrityVerified = DB_ERROR;sqlite3_stmt *integrity = NULL;// integrity_check檢查包括:亂序的記錄、缺頁、錯誤的記錄、丟失的索引、唯一性限制式、非空約束//if ( sqlite3_prepare_v2( obj_db, "PRAGMA integrity_check;", -1, &integrity, NULL ) == SQLITE_OK ) //quick_check不檢查約束條件,耗時較短if ( sqlite3_prepare_v2( obj_db, "PRAGMA quick_check;", -1, &integrity, NULL ) == SQLITE_OK ) {while ( sqlite3_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 );}/*關閉資料庫*/sqlite3_close( obj_db );return integrityVerified;}
Sqlite資料庫完整性檢測