architecture-components-samples icon indicating copy to clipboard operation
architecture-components-samples copied to clipboard

clearing sqlite_sequence is not working in android room

Open uday-ks opened this issue 8 years ago • 6 comments

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.

uday-ks avatar Mar 28 '18 11:03 uday-ks

I'm sure room is using "sqlite_sequence".. But I too face this problem

lvabarajithan avatar Aug 05 '18 15:08 lvabarajithan

Im also faced with the same problem! not sure how I can reset auto increment id to 0

wavehunterhawk avatar Oct 04 '18 12:10 wavehunterhawk

Same problem. I want to clear a table ant reset auto increment. I tried using TRUNCATE, but it is not supported by Room.

hivian avatar Oct 19 '18 19:10 hivian

I'm facing the same problem too : https://stackoverflow.com/questions/53573731/not-able-to-update-sqlite-sequence-table-using-roomdatabase-query

Any idea?

yccheok avatar Dec 02 '18 08:12 yccheok

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); }

HasanElHefnawy avatar Aug 09 '19 15:08 HasanElHefnawy

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.

ianhanniballake avatar Jan 27 '20 00:01 ianhanniballake