add bindNull to SQLiteDirectCursorDriver to avoid java.lang.IllegalArgumentExcep

论坛 期权论坛 脚本     
匿名技术用户   2021-1-12 13:51   285   0

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 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:7942463
帖子:1588486
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP