-1

I have the following command to drop all tables, to be performed in onUpgrade:

@Override
public void onUpgrade(SQLiteDatabase db, int i, int i2) {
    // Drop all tables...
    String query = "select 'drop table ' || name || ';' from sqlite_master " +
                       "where type = 'table';";
    db.rawQuery(query, null);
    onCreate(db);
}

However it doesn't seem to do anything. All my old tables are still there. How do I execute this query properly?

jazzgil
  • 2,250
  • 2
  • 19
  • 20
  • Seems like it would be much simpler to do it the normal way... `db.execSQL("DROP TABLE IF EXISTS " + classname.tablename);` once for each table. – Barak Nov 29 '15 at 16:22

1 Answers1

0

As the source of this query says:

The output of this is a script that will drop the tables for you.

But you are never looking at its output.

You have to read the output of this query, and execute every returned string.

Community
  • 1
  • 1
CL.
  • 173,858
  • 17
  • 217
  • 259