此代码
int idPlayer1=2;
int idPlayer2=3;
DBHelper dbHelper = DBHelper.getInstance();
if (idPlayer1 != 0 && idPlayer2 !=0){
String sqlQuery = "WITH t1 AS (\n" +
"SELECT P1.idPlayer1, P1.players1Goal, P1.players2Goal, P1.scorePlayer1 FROM Periods as P1 \n" +
"WHERE P1.type in (1,2,3,4,31,32,33,34) and idPlayer1 = "+ idPlayer1+
" and idPlayer2 = " + idPlayer2 + " \n" +
"UNION ALL \n" +
"SELECT P2.idPlayer2, P2.players2Goal, P2.Players1Goal, P2.scorePlayer2 FROM Periods as P2 \n" +
"WHERE P2.type in (1,2,3,4,31,32,33,34) and idPlayer1 = " + idPlayer2 + " and idPlayer2 = "+idPlayer1+" \n" +
") \n" +
"SELECT idPlayer1, sum(players1Goal), sum(Players2Goal) FROM t1 \n" +
"GROUP BY idPlayer1";
Cursor c = dbHelper.getDB().rawQuery(sqlQuery,null);
DBHelper.logCursor(c);
if (c != null) {
if (c.moveToFirst()) {
do {
int player12goal = c.getInt(1);
int player21goal = c.getInt(2);
} while (c.moveToNext());
}
c.close();
}
}
给我一个例外
10-25 07:17:08.538 3950-3950/? I/SqliteDatabaseCpp: sqlite returned: error code = 21, msg = API called with NULL prepared statement, db=/data/data/com.jnblab.f_stat/databases/test
10-25 07:17:08.538 3950-3950/? I/SqliteDatabaseCpp: sqlite returned: error code = 21, msg = misuse at line 58929 of [8609a15dfa], db=/data/data/com.jnblab.f_stat/databases/test
10-25 07:17:08.538 3950-3950/? E/SQLiteQuery: exception: not an error; query: WITH t1 AS (
10-25 07:17:08.538 3950-3950/? E/SQLiteQuery: SELECT P1.idPlayer1, P1.players1Goal, P1.players2Goal, P1.scorePlayer1 FROM Periods as P1
10-25 07:17:08.538 3950-3950/? E/SQLiteQuery: WHERE P1.type in (1,2,3,4,31,32,33,34) and idPlayer1 = 2 and idPlayer2 = 3
10-25 07:17:08.538 3950-3950/? E/SQLiteQuery: UNION ALL
10-25 07:17:08.538 3950-3950/? E/SQLiteQuery: SELECT P2.idPlayer2, P2.players2Goal, P2.Players1Goal, P2.scorePlayer2 FROM Periods as P2
10-25 07:17:08.538 3950-3950/? E/SQLiteQuery: WHERE P2.type in (1,2,3,4,31,32,33,34) and idPlayer1 = 3 and idPlayer2 = 2
10-25 07:17:08.538 3950-3950/? E/SQLiteQuery: )
10-25 07:17:08.538 3950-3950/? E/SQLiteQuery: SELECT idPlayer1, sum(players1Goal), sum(Players2Goal) FROM t1
10-25 07:17:08.538 3950-3950/? E/SQLiteQuery: GROUP BY idPlayer1
10-25 07:17:08.538 3950-3950/? D/AndroidRuntime: Shutting down VM
在带有Api15和HTC Api 10的模拟器上,但不适用于带有api 21和Nexus手机Api21的模拟器。简单的查询执行得很好,但像这样的查询不会。
DBHelper是扩展SQLiteOpenHelper的单例。
有谁知道可能导致这种情况的原因?
答案 0 :(得分:0)
在sqlite 3.8.3 http://www.sqlite.org/changes.html中添加了sqlite WITH, 并且使用的sqlite版本是Version of SQLite used in Android?。