Does RoomDB supports dropAllTables() and createAllTables()?
Asked Answered
M

1

0

GreenDAO supports DaoMaster.dropAllTables() and DaoMaster.createAllTables(). I'm looking for similar functionality in RoomDB. Does RoomDB supports this functionality ??

The use-case for this functionality is, when the user tries to login with new mobile number to my app, i want to clear the data of old login number by showing a warning dialog message and allow login with new number.

Mickey answered 16/6, 2020 at 10:3 Comment(1)
Do you really need to drop and recreate the tables? Isn't deleting all rows in the tables enough?Tallent
T
1

Room supports dropping and creating tables only during a migration between schema versions.

You can gain access to the underlying SupportSQLiteDatabase via RoomDatabase.getOpenHelper().getReadableDatabase(). With that, you can use execSQL() to execute SQL statements, include table dropping and creating.

But doing so is not consistent with the intended use of Room and is not safe. It will very likely break the InvalidationTracker used to notify observers of changes to managed tables.

From your use-case, it seems like rather than dropping and recreating the tables, all you need to do is clear them by deleting all entries.

Tallent answered 16/6, 2020 at 22:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.