Reputation: 11688
I'm trying to drop my tables onUpgrade, and it does delete the empty tables, but if tables have rows in it - it doesn't get deleted.
I've tried the following code to clean the table first:
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.delete(EventsTable.TABLE_NAME,null,null);
db.delete(UsersTable.TABLE_NAME,null,null);
//Create the drop query
String dropQuery = "Drop Table " + EventsTable.TABLE_NAME + ";";
dropQuery += " Drop Table " + UsersTable.TABLE_NAME + ";";
// Drop older tables if existed
db.execSQL(dropQuery);
// Create tables again
onCreate(db);
}
But still, the table doesn't drop - and it will cause me problem with releasing a new version of my application since my DB has changed
Upvotes: 1
Views: 182
Reputation: 29672
String dropQuery = "Drop Table " + EventsTable.TABLE_NAME + ";";
dropQuery += " Drop Table " + UsersTable.TABLE_NAME + ";";
You are trying to execute multiple SQL statement which is not allowed in sqlite. I suggest you to execute both drop table sql statement separately.
String dropQuery = "Drop Table " + EventsTable.TABLE_NAME + ";";
db.execSQL(dropQuery);
dropQuery = " Drop Table " + UsersTable.TABLE_NAME + ";";
db.execSQL(dropQuery);
Upvotes: 2