Skip to content

Commit 76479d5

Browse files
committed
Added test
1 parent d138032 commit 76479d5

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/main/java/com/microsoft/sqlserver/jdbc/SQLServerPreparedStatement.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2383,7 +2383,6 @@ public int[] executeBatch() throws SQLServerException, BatchUpdateException, SQL
23832383
bcOperation.setDestinationTableMetadata(rs);
23842384
}
23852385

2386-
23872386
bcOperation.writeToServer(batchRecord);
23882387

23892388
updateCounts = new int[batchParamValues.size()];

src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/BatchExecutionTest.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55
package com.microsoft.sqlserver.jdbc.unit.statement;
66

7+
import static org.junit.Assert.assertNotNull;
78
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
89
import static org.junit.jupiter.api.Assertions.assertTrue;
910
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -109,6 +110,36 @@ public void testBatchUpdateCountTrueOnFirstPstmtSpPrepare() throws Exception {
109110
testBatchUpdateCountWith(5, 4, true, "prepare", expectedUpdateCount);
110111
}
111112

113+
@Test
114+
public void testSqlServerBulkCopyCachingPstmtLevel() throws Exception {
115+
Calendar gmtCal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
116+
long ms = 1578743412000L;
117+
118+
try (Connection con = DriverManager.getConnection(
119+
connectionString + ";useBulkCopyForBatchInsert=true;sendTemporalDataTypesAsStringForBulkCopy=false;");
120+
Statement stmt = con.createStatement();
121+
PreparedStatement pstmt = con.prepareStatement("INSERT INTO " + timestampTable1 + " VALUES(?)")) {
122+
123+
TestUtils.dropTableIfExists(timestampTable1, stmt);
124+
String createSql = "CREATE TABLE " + timestampTable1 + " (c1 DATETIME2(3))";
125+
stmt.execute(createSql);
126+
127+
Field cachedBulkCopyOperationField = pstmt.getClass().getDeclaredField("bcOperation");
128+
cachedBulkCopyOperationField.setAccessible(true);
129+
Object cachedBulkCopyOperation = cachedBulkCopyOperationField.get(pstmt);
130+
assertEquals(null, cachedBulkCopyOperation, "SqlServerBulkCopy object should not be cached yet.");
131+
132+
Timestamp timestamp = new Timestamp(ms);
133+
134+
pstmt.setTimestamp(1, timestamp, gmtCal);
135+
pstmt.addBatch();
136+
pstmt.executeBatch();
137+
138+
cachedBulkCopyOperation = cachedBulkCopyOperationField.get(pstmt);
139+
assertNotNull("SqlServerBulkCopy object should be cached.", cachedBulkCopyOperation);
140+
}
141+
}
142+
112143
@Test
113144
public void testValidTimezoneForTimestampBatchInsertWithBulkCopy() throws Exception {
114145
Calendar gmtCal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));

0 commit comments

Comments
 (0)