简体   繁体   中英

How to execute a simple SQL script line in Android

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM