How should I use Sqlite “PRAGMA integrity_check” in C

对着背影说爱祢 提交于 2021-02-19 02:29:10

问题


I have corrupted database. In commandline I typed

PRAGMA integrity_check

and sqlite returned

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

In my c program I typed

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

this code returns always 0 with broken and healthy databases.

How should I use "PRAGMA integrity_check" in C ? Or how can I know my sqlite database is broken ?


回答1:


PRAGMA integrity_check behaves like a SELECT query that returns results in a single row. To read the results with sqlite3_exec, you need to use a callback.

Please note that PRAGMA integrity_check is not guaranteed to find all errors, so you can use it only to check for broken databases, not for healthy databases.



来源:https://stackoverflow.com/questions/22172186/how-should-i-use-sqlite-pragma-integrity-check-in-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!