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

2023-12-06

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

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 中使用“PRAGMAintegrity_check”?或者我怎么知道我的 sqlite 数据库已损坏?


PRAGMA 完整性检查其行为类似于在单行中返回结果的 SELECT 查询。 读取结果sqlite3_exec,你需要使用回调。

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

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

我应该如何在C中使用Sqlite“PRAGMAintegrity_check” 的相关文章