Android Room has method void clearAllTables()
and according to docs it makes the following:
Deletes all rows from all the tables that are registered to this database as
entities()
.This does NOT reset the auto-increment value generated by
autoGenerate()
.After deleting the rows, Room will set a WAL checkpoint and run VACUUM. This means that the data is completely erased. The space will be reclaimed by the system if the amount surpasses the threshold of database file size.
I checked it in my project and looks like db has no data after that call, but when I pulled *.db file from my device and opened it in sqlite viewer I've seen that all the data exists, the tables are filled and nothing has been erased. How can that be? I consider this as a potential flaw in my app. Please provide a reliable approach of cleaning room database
looks like db has no data after that call
It means the method worked.
when I pulled *.db file from my device and opened it in sqlite viewer I've seen that all the data exists
Most probably the transactions are not moved to the original database from the WAL file yet.
You can force a checkpoint using the wal_checkpoint pragma. Query the following statement against the database.
pragma wal_checkpoint(full)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With