简体   繁体   English

如何在 Android 中执行简单的 SQL 脚本行

[英]How to execute a simple SQL script line in Android

I have the following command to drop all tables, to be performed in onUpgrade:我有以下命令来删除所有表,在 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.您必须读取此查询的输出,并执行每个返回的字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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