使用sqlite进行Android开发:查询结果不应为空

时间:2013-04-23 15:09:14

标签: android sqlite android-cursor

我有一个相当大的查询,它在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);

1 个答案:

答案 0 :(得分:0)

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

您的查询对应于:

... AND sp.route='1'

尝试将参数字符串转换回如下数字:

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

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