I have an application that uses ORMLite. I need to create a function to reset the entire db (basically I need to delete all rows from every db, reset the autoincrement and reset indexes).
I probably can do this by launching a truncate on every table but does ORMLite has some specific method to do this?
ORMLite does not have a special method to reset the entire db. It does support the TableUtils.clearTable(connectionSource, dataClass))
method which removes all of the rows from the table, which would clear the index, but this will not reset the auto-increment. Also, I'm not sure what "reset indexes" implies more than clearing them. The process of resetting the auto-increment is going to be extremely database dependent so ORMLite will most likely never have native support that anyway.
I think your best bet is to drop the table using TableUtils.dropTable()
and then re-create it with TableUtils.createTable()
.
There is one way possible.. delete the database but this method is usually used when user log out and login with another user id etc, at login db is created and at logout db is deleted.
mContext.deleteDatabase("xxxxxx");
where "xxxxx" is the database name.
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