我应该如何使用 Sqlite“PRAGMA 完整性检查"?在 C [英] How should I use Sqlite "PRAGMA integrity_check" in C

查看:15
本文介绍了我应该如何使用 Sqlite“PRAGMA 完整性检查"?在 C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have corrupted database. In commandline I typed

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 程序中输入

In my c program I typed

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

此代码始终返回 0,数据库损坏且健康.

this code returns always 0 with broken and healthy databases.

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

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

推荐答案

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

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.

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

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.

这篇关于我应该如何使用 Sqlite“PRAGMA 完整性检查"?在 C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆