agrosner / DBFlow

A blazing fast, powerful, and very simple ORM android database library that writes database code for you.
MIT License
4.87k stars 598 forks source link

How to remove all data from the databases #257

Closed darkovski88 closed 9 years ago

darkovski88 commented 9 years ago

Hello, In my app I have 2 databases and everything is working fine, but when the user wants to log out from the app, I need to remove all the saved data. I guess I need to drop the tables or something like that.. Can anyone tell me how can I do that? I was searching for something like this but I didn't found anything.

Thanks!

agrosner commented 9 years ago

context.deleteDatabase(MyDatabase.NAME);

darkovski88 commented 9 years ago

@agrosner When I added this: deleteDatabase(TodoDatabase.NAME); - loged back again , and the data is not removed. Any idea?

agrosner commented 9 years ago

Do you need to append ".db"? We add in the .db to the name of the database when its created. I should add that to the README

darkovski88 commented 9 years ago

@agrosner I dont understand.. I've just appended ".db" to the database name and I get errors while compiling. Here is what I've done:

@Database(name = FavoritesDatabase.NAME, version = FavoritesDatabase.VERSION) public class FavoritesDatabase {

public static final String NAME = "Favorites.db";

public static final int VERSION = 1;

}

and here is what I get in logcat:

/app/build/generated/source/apt/debug/com/raizlabs/android/dbflow/config/ShoppingList/db$Database.java Error:(5, 32) error: '{' expected Error:(8, 34) error: expected

agrosner commented 9 years ago

Remove the .db from your database name except for when you call context.deleteDatabase(name + ".db"); I am putting in a fix for 2.0.1 that if the name starts with .db then it won't try to include that in the generated class name.