We try to update sqlite_sequence
with the following code.
WeNoteRoomDatabase weNoteRoomDatabase = WeNoteRoomDatabase.instance();
weNoteRoomDatab
i think query is wrong, you should try below query
weNoteRoomDatabase.query(new SimpleSQLiteQuery("UPDATE sqlite_sequence SET seq = 0 WHERE name = attachment"));
I'm using room database version 2.2.5
Here I'm unable to execute this query using Room Dao structure, so make one simple class and access method as like this and I got successful outcomes so this one is tested result. I'm using RxJava and RxAndroid for same.
public class SqlHelper {
private static SqlHelper helper = null;
public static SqlHelper getInstance() {
if (helper == null) {
helper = new SqlHelper();
}
return helper;
}
public Completable resetSequence(Context context) {
return Completable.create(emitter -> {
try {
AppDatabase.getDatabase(context)
.getOpenHelper()
.getWritableDatabase()
.execSQL("DELETE FROM sqlite_sequence WHERE name='<YOUR_TABLE_NAME>'");
emitter.onComplete();
} catch (Exception e) {
emitter.onError(e);
}
});
}
}
Execute:
SqlHelper.getInstance()
.resetQuizSequence(context)
.subscribeOn(Schedulers.io()
.observeOn(AndroidSchedulers.mainThread())
.subscribe(() -> {}, error -> {});
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()
still works fine, but with SupportSQLiteDatabase.execSQL()
the same UPDATE
or DELETE
queries against internal tables have no effect and do not throw errors.
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.
Table sql_sequence
is not managed by Room, so you need to edit it using a SupportSQLiteDatabase
.
Try this:
String sqlQuery = "DELETE FROM sqlite_sequence WHERE name='attachment'";
weNoteRoomDatabase().getOpenHelper().getWritableDatabase().execSQL(sqlQuery);