【问题标题】:execute multiple statement in single rawquery SQLite在单个 rawquery SQLite 中执行多个语句
【发布时间】:2018-04-11 18:44:29
【问题描述】:

我们可以使用 Android SQLite rawquery 执行多个语句,例如 SQL Server 存储过程

例子:

string statement1 ="create temp table .....";

string statement2 ="insert into temptable select ..... table1"

string statement3="insert into temptable select..... table2"

string statement4="select ...... from temptable";

Cursor cur=SQLiteDatabase db = this.getReadableDatabase().rawQuery(statement1+" "+statement2+" "+statement3+" "+statement4, null);

还有其他方法可以实现吗?

【问题讨论】:

标签: android sqlite


【解决方案1】:
db.beginTransaction();
try {
    db.execSQL(statement1);
    db.execSQL(statement2);
    db.execSQL(statement3);
    Cursor cursor = db.query(temptable, columns, selection, selectionArgs, groupBy, having, orderBy, limit);
    db.setTransactionSuccessful();
} finally {
    db.endTransaction();
}

最后使用光标获取结果。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-02-02
    • 2017-01-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多