无法使用 RoomDatabase.query 更新 sqlite_sequence 表 [英] Not able to update sqlite_sequence table using RoomDatabase.query
问题描述
我们尝试使用以下代码更新sqlite_sequence
.
We try to update sqlite_sequence
with the following code.
WeNoteRoomDatabase weNoteRoomDatabase = WeNoteRoomDatabase.instance();
weNoteRoomDatabase.query(new SimpleSQLiteQuery("UPDATE sqlite_sequence SET seq = 0 WHERE name = 'attachment'"));
然而,它根本没有效果.我使用 SQLite 浏览器检查 sqlite_sequence
表内容.计数器未重置为 0.
However, it has no effect at all. I exam the sqlite_sequence
table content using SQLite browser. The counter is not reset to 0.
如果我们尝试使用 SQLite 浏览器在同一个 SQLite 文件上手动运行相同的查询,它会正常工作.
If we try to run the same query manually using SQLite browser on same SQLite file, it works just fine.
我们的 Room 数据库非常简单.
Our Room database is pretty straightforward.
@Database(
entities = {Attachment.class},
version = 6
)
public abstract class WeNoteRoomDatabase extends RoomDatabase {
private volatile static WeNoteRoomDatabase INSTANCE;
private static final String NAME = "wenote";
public abstract AttachmentDao attachmentDao();
public static WeNoteRoomDatabase instance() {
if (INSTANCE == null) {
synchronized (WeNoteRoomDatabase.class) {
if (INSTANCE == null) {
INSTANCE = Room.databaseBuilder(
WeNoteApplication.instance(),
WeNoteRoomDatabase.class,
NAME
)
.build();
}
}
}
return INSTANCE;
}
}
知道我们错过了什么吗?
Any idea what we had missed out?
附加信息:清除 sqlite_sequence 在 android 机房中不起作用
推荐答案
Room
不使用 SQLiteDatabase - 但它使用 SupportSQLiteDatabase,虽然它是源代码 指出,它将所有调用委托给 {@link SQLiteDatabase}
的实现...我什至可以进一步挖掘 - 但我确信这是一个一致性功能,而不是一个错误.
Room
doesn't use SQLiteDatabase - but it uses SupportSQLiteDatabase, while it's source code states, that it delegates all calls to an implementation of {@link SQLiteDatabase}
... I could even dig further - but I'm convinced, that this is a consistency feature and not a bug.
SQLiteDatabase.execSQL()
仍然可以正常工作,但是使用 SupportSQLiteDatabase.execSQL()
相同的 UPDATE
或 DELETE
对内部表的查询没有效果,也不会抛出错误.
SQLiteDatabase.execSQL()
still works fine, but with SupportSQLiteDatabase.execSQL()
the same UPDATE
or DELETE
queries against internal tables have no effect and do not throw errors.
我的 MaintenanceHelper
可在 GitHub.重要的是,一开始让 Room
创建数据库 - 然后可以使用 SQLiteDatabase.execSQL()
操作内部表.在研究时,我遇到了注释 @SkipQueryVerification,其中可以可能在表sqlite_sequence
上允许UPDATE
或DELETE
;我只设法使用 Dao
执行了 SELECT
... 通常内部表的所有提示都被视为 read-only
,从公开可用的API的角度来看;所有的操纵尝试都被默默地忽略了.
my MaintenanceHelper
is available on GitHub. it is important that one initially lets Room
create the database - then one can manipulate the internal tables with SQLiteDatabase.execSQL()
. while researching I've came across annotation @SkipQueryVerification, which could possibly permit UPDATE
or DELETE
on table sqlite_sequence
; I've only managed to perform a SELECT
with Dao
... which in general all hints for the internal tables are being treated as read-only
, from the perspective of the publicly available API; all manipulation attempts are being silently ignored.
这篇关于无法使用 RoomDatabase.query 更新 sqlite_sequence 表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!