你如何确定.sqlite或.sqback在Java中是否已损坏? [英] How do you determine if an .sqlite or .sqback is corrupt in Java?
问题描述
我已经获得了一个目录目录,每个目录都包含我必须解析的.sqlite和.sqback文件的集合。
I have been given a directory of directories each containing a collection of .sqlite and .sqback files that I must parse.
问题是我相信一些这些文件在我收到它们时会损坏,因为我收到错误:
错误:[SQLITE_CORRUPT]数据库磁盘映像格式错误(数据库磁盘映像格式错误)当我尝试处理它们时,我的控制台上的
。这只发生在某些文件中。我已经隔离了一些,并尝试单独运行我的程序在这些坏文件的新副本上,它们会导致错误。大多数文件都很好但是:)
The problem is that I believe some of these files to be corrupt when I receive them because I get the error: ERR: [SQLITE_CORRUPT] The database disk image is malformed (database disk image is malformed) on my console when I try to process them. This only happens with some of the files. I have isolated a few and tried running my program on fresh copies of these bad files individually and they cause errors. Most of the files are fine though :)
我意识到我有可能确实会被给予损坏的文件,所以我想要一种方法来确定,在尝试解析它们之前,哪些文件是好的,哪些文件不好。
I realized that there is a chance that I may indeed be given corrupt files to begin with so I would like a way to determine, prior to trying to parse them, which files are good and which are not.
我用Java编写。我只对sqlite和sqback验证感兴趣,因为我知道我的解析器工作。我正在重复使用以前的项目。
I am writing in Java. I am only interested in the sqlite and sqback validation as I know my parser works. I am reusing it from a previous project.
提示?建议?答案?
非常感谢知识转移。
推荐答案
像普通的SQL查询一样运行 PRAGMA quick_check
。结果与包含字符串的单列表相同;对于一个完整的数据库,你得到一行说ok,对于一个腐败的,一堆错误信息。
Run PRAGMA quick_check
like a normal SQL query. The result is the same as a one-column table containing strings; for an intact database, you get a single row saying "ok", for a corrupt one, a bunch of error messages.
sqlite> pragma quick_check;
ok
更改文件中的一些字节后:
after changing some bytes in the file:
sqlite> pragma quick_check;
*** in database main ***
Page 64: btreeInitPage() returns error code 11
On tree page 40 cell 23: Child page depth differs
On tree page 40 cell 24: Child page depth differs
没有保证可以找到错误。
There is no guarantee that errors will be found by this.
这篇关于你如何确定.sqlite或.sqback在Java中是否已损坏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!