Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clearing sqlite_sequence is not working in android room #330

Closed
uday-ks opened this issue Mar 28, 2018 · 6 comments
Closed

clearing sqlite_sequence is not working in android room #330

uday-ks opened this issue Mar 28, 2018 · 6 comments

Comments

@uday-ks
Copy link

uday-ks commented Mar 28, 2018

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.

@lvabarajithan
Copy link

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

@wavehunterhawk
Copy link

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

@hivian
Copy link

hivian commented Oct 19, 2018

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

@yccheok
Copy link

yccheok commented Dec 2, 2018

@HasanElHefnawy
Copy link

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

@ianhanniballake
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants