Skip to content

Commit

Permalink
fix(batch): improve column metadata handling for batch execution
Browse files Browse the repository at this point in the history
- Update column index search to be case-insensitive in SQLServerPreparedStatement
- Remove failing test case in BatchExecutionTest that was checking for specific exception
  • Loading branch information
wooln committed Jan 21, 2025
1 parent 2b29dfb commit 719687f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2210,7 +2210,14 @@ public int[] executeBatch() throws SQLServerException, BatchUpdateException, SQL
jdbctype = ti.getSSType().getJDBCType().getIntValue();
}
if (null != bcOperationColumnList && !bcOperationColumnList.isEmpty()) {
int columnIndex = bcOperationColumnList.indexOf(c.getColumnName());
// find index ignore case
int columnIndex = -1;
for (int opi = 0; opi < bcOperationColumnList.size(); opi++) {
if (bcOperationColumnList.get(opi).equalsIgnoreCase(c.getColumnName())) {
columnIndex = opi;
}
}

if (columnIndex > -1) {
columnMappings.put(columnIndex + 1, i);
batchRecord.addColumnMetadata(columnIndex + 1, c.getColumnName(), jdbctype,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -600,13 +600,7 @@ public void testExecuteBatchColumnCaseMismatch() throws Exception {
preparedStatement.addBatch();
preparedStatement.setObject(1, "value2");
preparedStatement.addBatch();
try {
preparedStatement.executeBatch();
fail("Should have failed");
} catch (Exception ex) {
assertInstanceOf(SQLServerException.class, ex);
assertEquals("Unable to retrieve column metadata.", ex.getMessage());
}
preparedStatement.executeBatch();
}
}
}
Expand Down

0 comments on commit 719687f

Please sign in to comment.