This code
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();
}
}
is giving me Exception
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
on emulator with Api15 and on HTC Api 10, but not on emulator with api 21 and Nexus phone Api21. Simple queries are executed well, but queries like this don't.
DBHelper is singleton that extends SQLiteOpenHelper.
Has anyone an idea what could cause this?