question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

clearing sqlite_sequence is not working in android room

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
HasanElHefnawycommented, Aug 9, 2019

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

1reaction
ianhanniballakecommented, Jan 27, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found