clearing sqlite_sequence is not working in android room
Following code is not resetting/clearing the auto increment id to 0
database = Room.databaseBuilder(getApplicationContext(), AppDatabase.class,DatabaseMeta.DB_NAME).build();
database.query("DELETE FROM sqlite_sequence WHERE name = ?", new Object[]{"tableName"});
Is there any other way to clear "sqlite_sequence"?
Android room is not using "sqlite_sequence" for auto increment i think, not sure.
I'm sure room is using "sqlite_sequence".. But I too face this problem
Im also faced with the same problem! not sure how I can reset auto increment id to 0
Same problem. I want to clear a table ant reset auto increment. I tried using TRUNCATE, but it is not supported by Room.
I'm facing the same problem too : https://stackoverflow.com/questions/53573731/not-able-to-update-sqlite-sequence-table-using-roomdatabase-query
Any idea?
As per the answers given here, and here, and here, I could do it as following:
public void deleteAndReset() {
SQLiteDatabase database;
database = SQLiteDatabase.openOrCreateDatabase(context.getDatabasePath(MY_DATABASE_NAME), null);
String deleteTable = "DELETE FROM " + MY_TABLE_NAME;
database.execSQL(deleteTable);
String deleteSqliteSequence = "DELETE FROM sqlite_sequence WHERE name = '" + MY_TABLE_NAME + "'";
database.execSQL(deleteSqliteSequence);
}
This doesn't seem to be an issue with the samples. You can file an issue against Room on the issue tracker if you're still having an issue / have a feature request.