ORMLite reset all tables

14,870

Solution 1

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() .

Solution 2

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.

Solution 3

You can also use TableUtils.createTableIfNotExists(source,dataClass). Useful when testing.

Share:
14,870
dierre
Author by

dierre

I'm learning.

Updated on June 26, 2022

Comments

  • dierre
    dierre about 2 years

    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?