Reputation: 18130
I want to clear my SQLite db every time I hit a particular spot in my application.
I intended on just making a method that I could call called resetTables()
, but this seems to be more challenging than I expected because I don't really know where to place it. Here is a snippet.
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(DATABASE_CREATE);
}
public void reset(SQLiteDatabase db) {
db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE);
}
I'm getting a yellow line under reset and I can't call this method in my code. Any ideas?
Note this question is similar, but couldn't get it to help me.
public void resetTables(){
mDb.delete(TABLE_NAME, null, null);
}
Upvotes: 1
Views: 228
Reputation: 2446
first create one method where you create your database and table.
/**
* Re crate database
* Delete all tables and create them again
* */
public void resetTables(){
SQLiteDatabase db = this.getWritableDatabase();
// Delete All Rows
db.delete(TABLE_NAME, null, null);
db.close();
}
and call above method using on your button click event.
Upvotes: 1
Reputation: 993
i have done it by this way...
@Override
public void onOpen(SQLiteDatabase db) {
// TODO Auto-generated method stub
super.onOpen(db);
db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE);
}
and yes it definitely worked for me..:)
Upvotes: 0