In android if I call the SQLiteDatabase method query like the following:
sqlitedb.query("mytable", null, "name = ?",
new String[] {null}, null, null, null);
What is the expected result?
I would expect a NullPointerException but it seems like I am getting a cursor back that seems to have the same data as the last non-null selectionArgs query I performed. Is this expected behavior, I guess I have to do my own null checking before calling this method and instead pass “name IS NULL” to get the correct result?
This has nothing to do with NPE @satur9nine. It has to do with SQL argument procressing. I’ve verified that you are correct. With SQLite, if you issue:
with a null argument across a table which has rows with null
namefields, you will get no results. You are going to have to issue the query:This is not just Android but also JDBC. It is a database issue. SQLite, H2, and MySQL all behave this way. From this great SQL tutorial:
To quote: