2014-03-04 41 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不保证能够找到所有错误,因此您只能使用它来检查损坏的数据库,而不是用于健康的数据库。