2014-03-04 42 views
2

中使用Sqlite「PRAGMA integrity_check」我有損壞的數據庫。在命令行我輸入我應該如何在C

PRAGMA integrity_check 

和SQLite返回

On tree page 441 cell 17: Rowid 205 out of order (min less than parent max of 12258) 
On tree page 26 cell 12: 2nd reference to page 441 
On tree page 26 cell 12: Child page depth differs 
On tree page 26 cell 13: Child page depth differs 
Page 65 is never used 
Page 66 is never used 
wrong # of entries in index sqlite_autoindex_TBL_1 

在我的C程序中,我輸入

sqlite3 *glbDBHandle; 
sqlite3_open(DB_FILE, &glbDBHandle); 
int result=sqlite3_exec(glbDBHandle, "PRAGMA integrity_check", 0, 0, 0); 

這個代碼用碎和健康數據庫總是返回0。

我應該如何在C中使用「PRAGMA integrity_check」?或者我怎麼能知道我的sqlite數據庫已損壞?

回答

3

PRAGMA integrity_check的行爲像一個SELECT查詢,它返回單行結果。 要使用sqlite3_exec讀取結果,您需要使用回調。

請注意,PRAGMA integrity_check不保證能夠找到所有錯誤,因此您只能使用它來檢查損壞的數據庫,而不是用於健康的數據庫。