clearing sqlite_sequence is not working in android room
See original GitHub issueFollowing 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.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Android room - clearing sqlite_sequence is not working
Try this code works for me class FeedReaderDbHelper extends SQLiteOpenHelper { static final int DATABASE_VERSION = 1; static final String ...
Read more >Understanding the SQLite AUTOINCREMENT
This tutorial helps you understand SQLite AUTOINCREMENT attribute and explain when you should use it in the primary key of a table.
Read more >Android Room with a View - Java
RecyclerView and adapters; SQLite database and the SQLite query language; Threading and ExecutorService; It helps to be familiar with software ...
Read more >How to Reset Autoincrement Number Sequence in SQLite?
#Deleting the Table Number Sequence ... DELETE FROM `sqlite_sequence` WHERE `name` = 'table_name';. If a table sequence is deleted from the ...
Read more >7 Pro-tips for Room - Medium
7. Avoid false positive notifications for observable queries · SQLite supports triggers that fire whenever a DELETE , UPDATE or INSERT happens in...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.