Repository navigation
GH-1412: [JDBC] Return update counts for all statements in PreparedSt… #1438
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ | |
| import java.sql.SQLException; | ||
| import java.sql.SQLTimeoutException; | ||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
@@ -165,7 +166,15 @@ public ExecuteBatchResult executeBatch( | |
| } | ||
|
|
||
| // Update query | ||
| long[] updatedCounts = {preparedStatement.executeUpdate()}; | ||
| long totalUpdated = preparedStatement.executeUpdate(); | ||
| final int batchSize = parameterValuesList.size(); | ||
| long[] updatedCounts = new long[batchSize]; | ||
| if (batchSize > 0) { | ||
| Arrays.fill(updatedCounts, totalUpdated / batchSize); | ||
| if (totalUpdated % batchSize != 0) { | ||
| updatedCounts[0] += totalUpdated % batchSize; | ||
| } | ||
|
Comment on lines
+169
to
+176
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Callers that inspect individual counts, such as optimistic-locking checks that expect 0 or 1, will silently get wrong answers. Since the per-statement counts are not known, JDBC has long[] updatedCounts = new long[batchSize];
Arrays.fill(updatedCounts, Statement.SUCCESS_NO_INFO);If there's a reason to keep the split, please add a note in Javadoc. |
||
| } | ||
| return new ExecuteBatchResult(updatedCounts); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
executeUpdate()runs before we know whether the batch is empty. IfparameterValuesListis empty, nothing was bound, but the update still executes on the server. If the statement has no parameters, or still holds parameters from an earlier use, that can modify rows.The caller then gets back an empty array and no sign it happened.
Could we return early for an empty batch, before
executeUpdate()is called?