Skip to content

Commit 1b75820

Browse files
Support binding null arguments for rawQuery
1 parent 7f7e12b commit 1b75820

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

sqlcipher/src/androidTest/java/net/zetetic/database/sqlcipher_cts/SQLiteDatabaseTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,4 +1490,16 @@ public void testEnableAndDisableForeignKeys() {
14901490
mDatabase.setForeignKeyConstraintsEnabled(true);
14911491
assertEquals(1, DatabaseUtils.longForQuery(mDatabase, "PRAGMA foreign_keys", null));
14921492
}
1493+
1494+
public void testShouldSupportBindingNullValue(){
1495+
String b = "";
1496+
mDatabase.execSQL("CREATE TABLE t1(a,b);");
1497+
mDatabase.execSQL("INSERT INTO t1 VALUES(?, ?);", new Object[]{null, "123"});
1498+
Cursor cursor = mDatabase.rawQuery("SELECT * FROM t1 WHERE a is ?;", new Object[]{null});
1499+
if(cursor != null && cursor.moveToNext()){
1500+
b = cursor.getString(1);
1501+
cursor.close();
1502+
}
1503+
assertEquals("123", b);
1504+
}
14931505
}

sqlcipher/src/main/java/net/zetetic/database/sqlcipher/SQLiteProgram.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,14 +211,11 @@ public void bindAllArgsAsStrings(String[] bindArgs) {
211211
/**
212212
* Given a varargs of Object bindArgs, this method binds all of them in one single call.
213213
*
214-
* @param bindArgs the varargs of bind args, none of which must be null.
214+
* @param bindArgs the varargs of bind args.
215215
*/
216216
public void bindAllArgs(Object... bindArgs){
217217
if (bindArgs != null) {
218218
for (int i = bindArgs.length; i != 0; i--) {
219-
if (bindArgs[i - 1] == null) {
220-
throw new IllegalArgumentException("the bind value at index " + i + " is null");
221-
}
222219
bind(i, bindArgs[i - 1]);
223220
}
224221
}

0 commit comments

Comments
 (0)