嘿,我正在尝试让这个 SQlite 查询在我的 Android 应用程序中工作,但由于某种原因,它给了我以下错误:
编译时没有这样的函数: json_object (code 1):
但是当我运行查询时它可以在我的数据库浏览器中工作吗?
我的查询是这样的:
SELECT json_group_array(
json_object(
'name', name,
'ip', ip,
'mac', mac,
'token', token
)
)
FROM tvs
输出为:
[{"name":"lr","ip":"192.168.1.0","mac":"00:00:00:00","token":"na"},
{"name":"mbr","ip":"192.168.1.0","mac":"00:00:00:00","token":"na"},
{"name":"jr","ip":"192.168.1.0","mac":"00:00:00:00","token":"na"},
{"name":"tr","ip":"192.168.1.0","mac":"00:00:00:00","token":"na"},
{"name":"dsr","ip":"192.168.1.0","mac":"00:00:00:00","token":"na"},
{"名称":"lr2","ip":"192.168.1.0","mac":"00:00:00:00","令牌":"na"},
{"name":"lr","ip":"192.168.1.0","mac":"00:00:00:00","token":"na"}]
将该查询放入我的 Android 应用程序中:
Cursor cursor;
try {
cursor = db.rawQuery(
"SELECT " +
"json_group_array(" +
"json_object(" +
"'name', name," +
"'ip', ip," +
"'mac', mac," +
"'token', token" +
")" +
")" +
"FROM " +
"tvs", null);
cursor.moveToFirst();
String result = cursor.getString(0);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
在 db.rawQuery 行时出现错误。
Android SQlite不支持json_group_array/json_object吗?
Android SQlite 不支持 json_group_array/json_object 吗?
基于
从 SQLite 版本 3.38.0 (2022-02-22) 开始,JSON 函数和运算符默认内置于 SQLite 中。
那么根据Android 中使用的 SQLite 版本,这些功能仅支持 API 34+(版本 14 或 U)?
内置 SQLite 的 Android 版本历来落后于 SQLite 的可用版本。