我有一个相当大的查询,它在 android 外部执行时返回数据,而在 android 内部执行时不返回任何内容。
- 我将查询分成几部分,并确定联合没问题。
- 我尝试了一组具有相同行为的较小数据。
- 我已经使用不同的硬件和 API 版本进行了测试。
- 我正在使用具有常量值的 rawQuery 方法。 http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html#rawQuery(java.lang.String, java.lang.String[])
此查询旨在替换当前不支持的 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);