0

我有一个相当大的查询,它在 android 外部执行时返回数据,而在 android 内部执行时不返回任何内容。

此查询旨在替换当前不支持的 FULL OUTER JOIN。

SELECT IFNULL(stype, gtype) AS type, IFNULL(sdate, gdate) AS date, IFNULL(sroute, groute) AS route FROM (

SELECT sp.type AS stype, sp.date AS sdate, -1 AS gtype, gp.date AS gdate, sp.route AS sroute, gp.route AS groute
FROM Sensor_Point AS sp LEFT JOIN GPS_Point AS gp ON gp._id IS NULL AND sp.sent=0 AND sp.route=gp.route AND sp.route=1
UNION ALL
SELECT sp.type AS stype, sp.date AS sdate, -1 AS gtype, gp.date AS gdate, sp.route AS sroute, gp.route AS groute
FROM GPS_Point AS gp LEFT JOIN Sensor_Point AS sp ON sp._id IS NULL AND gp.sent=0 AND sp.route=gp.route AND gp.route=1

) WHERE route=1 ORDER BY date ASC LIMIT 255

任何提示将不胜感激。

更新:

看起来问题最终出在查询参数上,如果我这样设置:

String[] args = new String[3];
args[0] = args[1] = args[2] = "1"; 
Cursor data dataBase.rawQuery(SELECT_POINTS, args);

它不起作用,而当直接在查询中硬编码值时它起作用。

Cursor data = dataBase.rawQuery(SELECT_POINTS, null);
4

1 回答 1

0

在 Android 数据库 API 中,所有查询参数都是字符串。(这是一个可怕的设计错误。)

您的查询对应于:

... AND sp.route='1'

尝试将参数字符串转换回这样的数字:

... AND sp.route = CAST(? AS INT)

或者只是将数字直接放入查询字符串中。

于 2013-04-23T17:09:06.713 回答