问题
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