add bindNull to SQLiteDirectCursorDriver to avoid java.lang.IllegalArgumentException: the bind valu

http://code.google.com/p/android/issues/detail?id=7636


Reported by Accilent...@gmail.com, Apr 8, 2010
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.

Comment 1 by romaingu...@gtempaccount.com, Apr 9, 2010
(No comment was entered for this change.)
Status: Reviewed
Owner: j...@android.com
Comment 2 by siri.bal...@gmail.com, Nov 9, 2010
This is helpful.. Thanks :)
Comment 3 by Accilent...@gmail.com, Nov 12, 2010
siri.balaji - You're welcome...
Comment 4 by gnanaswa...@gmail.com, 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. 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值