Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Batch insert: fix inserting constant 'null' #1762

Merged
merged 1 commit into from
Sep 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private IterableLike() {
public static boolean isIterable(Object maybeIterable) {
return maybeIterable instanceof Iterator<?>
|| maybeIterable instanceof Iterable<?>
|| maybeIterable.getClass().isArray();
|| maybeIterable != null && maybeIterable.getClass().isArray();
}

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

@Test
public void testBindConstantNull() {
UsesBatching b = handle.attach(UsesBatching.class);
Copy link

@leaumar leaumar Sep 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

avoid single-letter variables please (aside from the meme i for iterations, I'd say Handle h at most could also be a meme in our context since it's so common)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, this is all just clone of existing tests, with only one other change...

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like the improvement could be made in 2 places :)

List<Integer> ids = Arrays.asList(1, 2, 3, 4, 5);

b.withConstantValue(ids, null);

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't there a hasSize?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't a Collection, so that doesn't apply.


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