Sqlite資料庫完整性檢測

來源:互聯網
上載者:User

標籤: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資料庫完整性檢測

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.