无法在deleteDatabase后创建同名数据库

来源:互联网 发布:淘宝上下架神什么意思 编辑:程序博客网 时间:2024/04/29 19:06

Android开发,遇到一个奇怪的问题,在应用退出的时候,使用deleteDatabase删除sqlite数据库。

然后登录的时候,出现类似os_unix.c stat(/data/data/org.ibuo.demo/databases/demo.db) 

 android.database.sqlite.SQLiteDiskIOException: disk I/O error (code 1802)的错误。


后来在google code发现已经有人提出了同样的问题:

https://code.google.com/p/android/issues/detail?id=13727

Reported by jschn...@gmail.com, Jan 5, 2011
This happened with multiple android versions and devicesI was developing on...I attempted to clear the database when logging out of our app in two different ways:1.  Deleting the file under "data/data/MY_APP/databases" directly2.  Using context.deleteDatabase();Both of these resulted in the file seeming to be deleted from the file system (it did not show up when listing files from an adb shell).When logging back in however, the old data was still available, and there was no db file created on the file system.  SQLiteDatabase.getPath showed we were still looking at the same location however.  Using lsof, I determined that the file handle still existed.This is unusual behavior which I would not have expected from the built in Context.deleteDatabase() method, and at least requires some explanation in the docs.Workaround: I solved my problem by dropping all of the tables in the db and setting the version back to 0 instead of using Context.deleteDatabase().
=======================

是说被删除的文件的句柄还没有释放。后来用了其他的方法绕过去了这个问题。


在调试的过程中发现,SDK 2.2,2.3会出现数据库已删除,但是却能读出文件的问题。

而4.1,4.2,会直接报错。提示找不到文件的错误。

然后应用会重启,重启后,却可以了。


解决办法:

在deleteDatabase前,把同一句柄的db close掉。

0 0
原创粉丝点击