“SQLiteDiskIOException:错误代码 10:磁盘 I/O 错误”在 ICS 和 Samsung Nexus 上重新调整 DROP TABLE

发布于 2024-12-21 17:51:34 字数 740 浏览 1 评论 0原文

我收到以下错误:

android.database.sqlite.SQLiteDiskIOException: error code 10: disk I/O error
    at android.database.sqlite.SQLiteStatement.native_execute(Native Method)
    at android.database.sqlite.SQLiteStatement.executeUpdateDelete(SQLiteStatement.java:92)
    at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1926)
    at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1866)

我仅在 Samsung Nexus 手机上的 ICS 4.0.1 上收到此错误。在模拟器(Motorola Xoom 3.2 和 HTC Desire 2.3.3)上,代码运行良好。我的代码针对的是 SDK 版本 8 或 2.2.x。 execSQL 的执行方式如下:

db.execSQL("DROP TABLE IF EXISTS " + table.getTableName());

数据库存储在内部,而不是存储在 SD 卡上。关于如何解决这个问题有什么建议吗?

I'm getting the following error:

android.database.sqlite.SQLiteDiskIOException: error code 10: disk I/O error
    at android.database.sqlite.SQLiteStatement.native_execute(Native Method)
    at android.database.sqlite.SQLiteStatement.executeUpdateDelete(SQLiteStatement.java:92)
    at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1926)
    at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1866)

I only get this error on ICS 4.0.1 on a Samsung Nexus phone. On an emulator, a Motorola Xoom 3.2 and an HTC Desire 2.3.3, the code works fine. My code is targeted at version 8, or 2.2.x, of the SDK. The execSQL is executed as follows:

db.execSQL("DROP TABLE IF EXISTS " + table.getTableName());

The database is stored internally and not on an SD card. Any suggestions on how to solve this problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你穿错了嫁妆 2024-12-28 17:51:34

解决了这个问题。

问题是,在 drop table 语句之前有一个 Context.deleteDatabase('dbName') 语句,该语句显然已删除了数据库,然后报告的 I/O 错误就很有意义了。

似乎之前已经使用了腰带和支架的方法(不必要)。

然而有趣的是,直到迁移到 ICS 后,这才显现为问题。

Solved this.

Problem was that prior to the drop table statements there was a Context.deleteDatabase('dbName') statement which had obviously removed the db, and the I/O error being reported then makes perfect sense.

It seems that a belt and braces approach had been used previously (unnecessarily).

However the interesting thing is that this didn't manifest as a problem until the move to ICS.

仄言 2024-12-28 17:51:34

当加密数据库无法使用外键/索引正确删除表时,我遇到了同样的问题。在删除表之前删除现有记录解决了问题:

fun SupportSQLiteDatabase.dropTable(name: String) {
    execSQL("DELETE FROM $name")
    execSQL("DROP TABLE IF EXISTS $name")
}

I run into the same problem, when encrypted database was not able to properly drop table with ForeignKey/Index. Deleting existing records just before dropping table resolved issue:

fun SupportSQLiteDatabase.dropTable(name: String) {
    execSQL("DELETE FROM $name")
    execSQL("DROP TABLE IF EXISTS $name")
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文