Android 带有 WITH 子句的 sqlite 查询?
Android sqlite query with a WITH clause?
在 Android 上,有什么方法可以执行以 WITH 子句开头的原始 android.database.sqlite
查询,例如:WITH one(x) AS (SELECT 1) SELECT x FROM one;
?
以下片段给我一条语法错误消息(在我的 activity 主代码中):
AlertDialog.Builder b = new AlertDialog.Builder(this);
AlertDialog ad = b.create();
SQLiteDatabase db;
Cursor c;
try {
db = this.openOrCreateDatabase("test.db", 0, null);
} catch (Exception e) {
ad.setMessage("Could not open database: " + e.toString());
ad.show();
return;
}
try {
c = db.rawQuery("WITH one(x) AS (SELECT 1) SELECT x FROM one;", new String[0]);
} catch (Exception e) {
ad.setMessage("Could not execute query: " + e.toString());
ad.show();
return;
}
if (c == null)
ad.setMessage("Got null query result");
else
ad.setMessage("Got valid query result");
ad.show();
如果我将 db.rawQuery
语句替换为:
,它会起作用
c = db.rawQuery("SELECT 1;", new String[0]);
更新 1(已编辑):same WITH one(x) AS (SELECT 1) SELECT x FROM one;
声明 works 以下对我来说:
- sqlite3 CLI
- 在
Android 和 iOS (iOS 9.2 上的 Web SQL 交易中,不是8.0)
- 在 https://github.com/litehelpers/Cordova-sqlite-storage 的 iOS 版本中 (iOS 9.2,不是 8.0)。
内置的 Android sqlite 数据库可能太旧,无法支持此查询。以下 Android 个 sqlite 数据库将支持此查询(已测试):
- https://github.com/liteglue/Android-sqlite-connector
- https://github.com/sqlcipher/android-database-sqlcipher
此外,Android的一些较新版本可能更新了sqlite。供参考:
- (accepted answer to Version of SQLite used in Android?)
- https://code.google.com/p/android/issues/detail?id=58909
- https://code.google.com/p/android/issues/detail?id=191289
最近才在 sqlite 3.8.3 版中引入了 WITH 语法。
https://www.sqlite.org/lang_with.html
所以你检查版本 sqlite 使用
在 Android 上,有什么方法可以执行以 WITH 子句开头的原始 android.database.sqlite
查询,例如:WITH one(x) AS (SELECT 1) SELECT x FROM one;
?
以下片段给我一条语法错误消息(在我的 activity 主代码中):
AlertDialog.Builder b = new AlertDialog.Builder(this);
AlertDialog ad = b.create();
SQLiteDatabase db;
Cursor c;
try {
db = this.openOrCreateDatabase("test.db", 0, null);
} catch (Exception e) {
ad.setMessage("Could not open database: " + e.toString());
ad.show();
return;
}
try {
c = db.rawQuery("WITH one(x) AS (SELECT 1) SELECT x FROM one;", new String[0]);
} catch (Exception e) {
ad.setMessage("Could not execute query: " + e.toString());
ad.show();
return;
}
if (c == null)
ad.setMessage("Got null query result");
else
ad.setMessage("Got valid query result");
ad.show();
如果我将 db.rawQuery
语句替换为:
c = db.rawQuery("SELECT 1;", new String[0]);
更新 1(已编辑):same WITH one(x) AS (SELECT 1) SELECT x FROM one;
声明 works 以下对我来说:
- sqlite3 CLI
- 在
Android 和iOS (iOS 9.2 上的 Web SQL 交易中,不是8.0) - 在 https://github.com/litehelpers/Cordova-sqlite-storage 的 iOS 版本中 (iOS 9.2,不是 8.0)。
内置的 Android sqlite 数据库可能太旧,无法支持此查询。以下 Android 个 sqlite 数据库将支持此查询(已测试):
- https://github.com/liteglue/Android-sqlite-connector
- https://github.com/sqlcipher/android-database-sqlcipher
此外,Android的一些较新版本可能更新了sqlite。供参考:
- (accepted answer to Version of SQLite used in Android?)
- https://code.google.com/p/android/issues/detail?id=58909
- https://code.google.com/p/android/issues/detail?id=191289
最近才在 sqlite 3.8.3 版中引入了 WITH 语法。 https://www.sqlite.org/lang_with.html
所以你检查版本 sqlite 使用