From 719687f20382ef4cfe6e6cc62b916f603fc27e01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E4=BA=91=E9=87=91YunjinXu?= Date: Tue, 21 Jan 2025 10:22:29 +0800 Subject: [PATCH] fix(batch): improve column metadata handling for batch execution - Update column index search to be case-insensitive in SQLServerPreparedStatement - Remove failing test case in BatchExecutionTest that was checking for specific exception --- .../sqlserver/jdbc/SQLServerPreparedStatement.java | 9 ++++++++- .../jdbc/unit/statement/BatchExecutionTest.java | 8 +------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerPreparedStatement.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerPreparedStatement.java index 244cfb696..0e454226a 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerPreparedStatement.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerPreparedStatement.java @@ -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, diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/BatchExecutionTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/BatchExecutionTest.java index 12de4c974..aeb841ed1 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/BatchExecutionTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/BatchExecutionTest.java @@ -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(); } } }