(Feel free to improve the title of the question if you can think of something better.)
Question Consider the following SQLite query:
SELECT COUNT(*) FROM (SELECT 1 AS value UNION SELECT 2 AS value) WHERE value <= ?
When I use 1 as a parameter, I expect the query to give 1 , but it will give 2 . Why is this happening?
Additional information :
This is a minimal working example for reproducing a problem (Android):
Cursor c = db.rawQuery( "SELECT COUNT(*) " + " FROM (SELECT 1 AS value UNION SELECT 2 AS value) " + " WHERE value <= ? ", new String[] {String.valueOf(1)}); c.moveToFirst(); Log.i("", "Result: " + String.valueOf(c.getInt(0)));
Perhaps this is due to the fact that the parameter is passed as a string, but, alas, there is no other way to pass the SQLite API parameters, so I think that I am not doing anything โwrongโ here and this is a SQLite task to convert the value accordingly. I also noticed the following when using a non-parameterized version of the request (this may or may not be relevant to the problem):
SELECT COUNT(*) FROM (SELECT 1 AS value UNION SELECT 2 AS value) WHERE value <= 1
source share