Lara
Lara

Reputation: 61

How to drop an ORMLite database?

I would like to know how to drop a database with ORMLite. Is there already any API call?

Just dropping all the tables does not delete the whole database.

Thanks in advance.

Upvotes: 6

Views: 6515

Answers (2)

Gray
Gray

Reputation: 116888

Edit:

Looks like you figured it out. You do something like:

boolean success =
    context.deleteDatabase(
        "/data/data/source.package.goes.here/databases/database-name.db‌​");

Edit:

Dropping a database is strange with ORMLite but I think it can be done. Really, when you do a dao.executeRaw(...) method, you have a connection open to the database engine that can perform just about any operation. You should be able to something like:

fooDao.executeRaw("drop database foo;");

That at least works for me under MySQL and it should under Sqlite.


Yes, ORMLite has the TableUtils class which allows you to create and drop tables. Here are the javadocs for the method.

Upvotes: 7

Rishigesh Murugesh
Rishigesh Murugesh

Reputation: 1

You could do something like this,

    TableUtils.dropTable(connectionSource, Model_Class.class, false);

for each table in the database, provided if you had model class for each table.

Reference:

http://ormlite.com/javadoc/ormlite-core/com/j256/ormlite/table/TableUtils.html#dropTable%28com.j256.ormlite.support.ConnectionSource,%20java.lang.Class,%20boolean%29

Upvotes: -1

Related Questions