Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ORMLite reset all tables

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?

like image 503
dierre Avatar asked May 13 '12 10:05

dierre


2 Answers

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

like image 92
Gray Avatar answered Oct 14 '22 12:10

Gray


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.

like image 28
Amit Tumkur Avatar answered Oct 14 '22 11:10

Amit Tumkur