http://code.google.com/p/android/issues/detail?id=7636
When querying a row and the value of one of the columns in the where clause is null in the row(s) of the database being queried, bindArgs or setSelectionArgs fails with java.lang.IllegalArgumentException: the bind value at index # is null E/AndroidRuntime( 399): java.lang.IllegalArgumentException: the bind value at index # is null E/AndroidRuntime( 399): at android.database.sqlite.SQLiteProgram.bindString(SQLiteProgram.java:174) E/AndroidRuntime( 399): at android.database.sqlite.SQLiteQuery.bindString(SQLiteQuery.java:190) E/AndroidRuntime( 399): at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:55) E/AndroidRuntime( 399): at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1118) E/AndroidRuntime( 399): at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1092) Since it's not easy to override SQLiteDirectCursorDriver to support the null selection arguments, it would be nicer to make the change to SQLiteDirectCursorDriver itself. In the query method, change from: for (int i = 0; i < numArgs; i++) { query.bindString(i + 1, selectionArgs[i]); } to: for (int i = 0; i < numArgs; i++) { if (selectionArgs[i] == null) query.bindNull(i + 1); else query.bindString(i + 1, selectionArgs[i]); } and in bindSelectionArgs, change from: for (int i = 0; i < numArgs; i++) { mQuery.bindString(i + 1, bindArgs[i]); } to: for (int i = 0; i < numArgs; i++) { if (bindArgs[i] == null) mQuery.bindNull(i + 1); else mQuery.bindString(i + 1, bindArgs[i]); } Thanks.
Nov 9, 2010
,
This is helpful.. Thanks :)
Nov 12, 2010
,
siri.balaji - You're welcome...
Jan 25, 2011
,
Is this bug already addressed? by romain#@android.com? Do we still need to have explicit check for null and use bindNull() instead of bindString() if the value to be bind is null? I am still facing this issue in Android 2.2 Froyo Build.
Owner: j...@android.com