无法使用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.
我们的会议室数据库非常简单.
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 ,虽然它是
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
在 @SkipQueryVerification ,其中可能可以允许在表sqlite_sequence
上使用UPDATE
或DELETE
;我只能用Dao
执行SELECT
...从公开的API角度来看,通常将内部表的所有提示都视为read-only
;所有的操作尝试都将被静默忽略.
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屋!