Skip to content

Commit

Permalink
Batch insert: fix inserting constant 'null'
Browse files Browse the repository at this point in the history
Fixes #1761
  • Loading branch information
stevenschlansker committed Sep 24, 2020
1 parent ad2ccfc commit 82a6d02
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
Expand Up @@ -43,9 +43,10 @@ private IterableLike() {
* @return whether {@code IterableLike} can iterate over the given object
*/
public static boolean isIterable(Object maybeIterable) {
return maybeIterable instanceof Iterator<?>
|| maybeIterable instanceof Iterable<?>
|| maybeIterable.getClass().isArray();
return maybeIterable != null
&& (maybeIterable instanceof Iterator<?>
|| maybeIterable instanceof Iterable<?>
|| maybeIterable.getClass().isArray());
}

/**
Expand Down
15 changes: 15 additions & 0 deletions sqlobject/src/test/java/org/jdbi/v3/sqlobject/TestBatching.java
Expand Up @@ -67,6 +67,21 @@ public void testInsertSingleIteratorNoTx() {
assertThat(b.size()).isEqualTo(2);
}

@Test
public void testBindConstantNull() {
UsesBatching b = handle.attach(UsesBatching.class);
List<Integer> ids = Arrays.asList(1, 2, 3, 4, 5);

b.withConstantValue(ids, null);

assertThat(b.size()).isEqualTo(5);

List<String> names = handle.createQuery("select distinct name from something")
.mapTo(String.class)
.list();
assertThat(names).containsExactly((String) null);
}

@Test
public void testBindConstantValue() {
UsesBatching b = handle.attach(UsesBatching.class);
Expand Down

0 comments on commit 82a6d02

Please sign in to comment.