我应该如何在 C 中使用 Sqlite“PRAGMAintegrity_check”

use*_*345 4 c sqlite

我损坏了数据库。在命令行中我输入

PRAGMA integrity_check
Run Code Online (Sandbox Code Playgroud)

和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
Run Code Online (Sandbox Code Playgroud)

在我的 c 程序中,我输入

sqlite3 *glbDBHandle;
sqlite3_open(DB_FILE, &glbDBHandle);
int result=sqlite3_exec(glbDBHandle, "PRAGMA integrity_check", 0, 0, 0);
Run Code Online (Sandbox Code Playgroud)

此代码始终返回 0 损坏和健康的数据库。

我应该如何在 C 中使用“PRAGMA完整性检查”?或者我怎么知道我的 sqlite 数据库坏了?

CL.*_*CL. 6

PRAGMAintegrity_check 的行为类似于 SELECT 查询,在单行中返回结果。要使用 读取结果sqlite3_exec,您需要使用回调。

请注意,PRAGMA integrity_check不能保证找到所有错误,因此您只能使用它来检查损坏的数据库,而不是检查健康的数据库。