Android的数据库文件损坏 [英] Android Database file corruption

查看:411
本文介绍了Android的数据库文件损坏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,允许用户应用程序SQLite数据库文件保存到SD卡。此功能已经到位了一年多,并已工作得很好。我有用户发邮件给我自己的数据库文件中的情况下,出现了一个错误,我无法重现。

I've got an app that allows the user to save the app SQLite database files to the SD card. This function has been in place for over a year and has worked just fine. I've had users email me their database files in cases where there was an error that I could not reproduce.

最近,一个用户发送我自己的数据库文件,当我试图将其加载到我的应用程序(将它们放置在应用程序的数据库文件位置),应用程序试图打开数据库文件时坠毁。该用户已给我发了文件之前,在过去,没有任何问题。

Recently, a user sent me his database files, and when I tried to load them into my app (by placing them into the app's database file location), the app crashed when trying to open the database file. This user has sent me his files before in the past with no problems.

我的应用程序之间的唯一区别当时和现在是:1)我添加的应用-2-SD功能,以及2)我的应用程序现在针对2.2与1.6当年(但1.5是最小SDK版本在这两种情况下)

The only differences between my app back then and now are: 1) I added app-2-SD functionality, and 2) My app targets 2.2 now versus 1.6 back then (but 1.5 is the min SDK version in both cases).

用户说,他放在应用在SD卡上,然后将应用程序开始崩溃。它甚至没有给他提交错误报告的选项。

The user said he placed the app on the SD card and then the app started crashing. It doesn't even give him the option of submitting an error report.

当我放置在模拟器他的文件,我得到了以下堆栈跟踪:

When I placed his files in the emulator, I got the following stack trace:

11-09 22:32:04.275: ERROR/AndroidRuntime(757): Caused by: android.database.sqlite.SQLiteException: file is encrypted or is not a database
11-09 22:32:04.275: ERROR/AndroidRuntime(757):     at android.database.sqlite.SQLiteDatabase.native_setLocale(Native Method)
11-09 22:32:04.275: ERROR/AndroidRuntime(757):     at android.database.sqlite.SQLiteDatabase.setLocale(SQLiteDatabase.java:1636)
11-09 22:32:04.275: ERROR/AndroidRuntime(757):     at android.database.sqlite.SQLiteDatabase.<init>(SQLiteDatabase.java:1586)
11-09 22:32:04.275: ERROR/AndroidRuntime(757):     at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:638)
11-09 22:32:04.275: ERROR/AndroidRuntime(757):     at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:168)

他之前给我发电子邮件数据,这些文件有正确的数据库名和扩展名,所以我给他怀疑的利益,而不是假设他发送了不正确的文件。有没有人在此之前看到的问题,以及任何可能的原因和/或解决方案,知道吗?

He's emailed me the data before, and the files had the correct database name and extension, so I'm giving him the benefit of the doubt and not assuming he sent an incorrect file. Has anyone seen this problem before, and know of any possible causes and/or solutions?

更新
如果这有什么差别,我从他的手机是HTC EVO 4G的用户发现了。我想我在最近的Andr​​oid版本,其中数据库文件存储在/数据/阅读加密的数据库文件的某处安全的东西/ ...而不是/数据/数据​​/ ......我不知道这可能与?在任何情况下,进一步质问用户后,我至少知道,这是在被有问题的数据库文件中的一个特定的表。我的应用程序的不同部分与数据库文件中不同的表进行交互。该应用程序正常工作,并允许他保存/当他访问其他表中读取数据,但是当他访问一个特定的表,只是试图打开该文件产生了错误。我想我可以添加一个丑陋的修复,如果它发生,捕捉此异常,然后删除损坏的表,然后重新创建它。思考?

Update In case it makes any difference, I found out from the user that his phone is an HTC Evo 4G. I thought I read something somewhere about encrypted database files in more recent Android releases, where the database files are stored under /data/secure/... rather than /data/data/... I wonder if this could be related? In any case, after questioning the user further, I at least know that it is one specific table in the database file that is having a problem. Different parts of my app interact with different tables within the database file. The app works fine, and allows him to save/read data when he accesses the other tables, but when he accesses one particular table, just trying to open the file produces his error. I'm thinking I can add an ugly fix that catches this exception if it occurs and then drop the corrupted table and then recreate it. Thoughts?

推荐答案

我也有一个(相当小)数据库的应用程序,最近我得到由于DB,我无法重现的问题崩溃报告。

I also have an app with a (rather small) db and recently I get crash reports due to db problems that I could not reproduce.

我的应用周围玩,真正推动它最终导致崩溃。

Playing around with my app and really pushing it finally caused crashes.

在我的情况的原因是,由于许多快速开/关/更新请求,应用程序中断,应用程序等,这样系统在某种程度上破坏了数据库中的语言变化。

The reason in my case was that due to many fast opening/closing/update requests, interruption of the app, language changes during the app, etc so the system somehow corrupted the db.

我现在实现的解决方案是

The solution I implemented now is

a. close/reopen the db often to avoid problems 

b. have a consistency-check routine for every save or retrieve of data now - lots of overhead - but that cleared it fo me so far...

PS我没有,虽然得到同样的崩溃报告你的。我现在对我进行测试的办公桌几个不同的Andr​​oid手机,现在,几乎从来没有得到它最新的高端那些崩溃。
这些问题似乎与更小的内存/速度较慢的CPU的手机比快速高端的人更经常发生。 - 但老实说,我仍然感到困惑这个! ......可能是SD卡使用的是关系到太不知何故?

ps I did not get the same crash report though as yours. I have now a couple of different Android phones on my desk for testing now and almost never got it to crash with the newest high-end ones. Those problems seem to happen more often with smaller memory/slower speed cpu phones than with fast high-end ones. - but honestly I am still confused about this! ... possibly the SD-card use is related to that too somehow?

这篇关于Android的数据库文件损坏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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