|
32 | 32 | import java.util.UUID;
|
33 | 33 |
|
34 | 34 | import org.junit.jupiter.api.AfterAll;
|
| 35 | +import org.junit.jupiter.api.Assertions; |
35 | 36 | import org.junit.jupiter.api.BeforeEach;
|
36 | 37 | import org.junit.jupiter.api.BeforeAll;
|
37 | 38 | import org.junit.jupiter.api.Tag;
|
@@ -1407,6 +1408,54 @@ private void getCreateTableTemporalSQL(String tableName) throws SQLException {
|
1407 | 1408 | }
|
1408 | 1409 | }
|
1409 | 1410 |
|
| 1411 | + /** |
| 1412 | + * Test insert-select fallback to normal execution for bulk copy API |
| 1413 | + */ |
| 1414 | + @Test |
| 1415 | + public void testInsertSelectFallbackToNormalExecution() throws Exception { |
| 1416 | + String tableNameSource = AbstractSQLGenerator.escapeIdentifier("SourceTable"); |
| 1417 | + String tableNameDestination = AbstractSQLGenerator.escapeIdentifier("DestinationTable"); |
| 1418 | + |
| 1419 | + String connectStringUrl = connectionString |
| 1420 | + + ";useBulkCopyForBatchInsert=true;sendStringParametersAsUnicode=false;"; |
| 1421 | + |
| 1422 | + try (Connection connection = PrepUtil.getConnection(connectStringUrl); |
| 1423 | + Statement stmt = connection.createStatement()) { |
| 1424 | + |
| 1425 | + TestUtils.dropTableIfExists(tableNameSource, stmt); |
| 1426 | + String createSourceTableSQL = "CREATE TABLE " + tableNameSource + " (id INT, value VARCHAR(50))"; |
| 1427 | + stmt.execute(createSourceTableSQL); |
| 1428 | + |
| 1429 | + String insertSourceDataSQL = "INSERT INTO " + tableNameSource + " VALUES (1, 'TestValue1'), (2, 'TestValue2')"; |
| 1430 | + stmt.execute(insertSourceDataSQL); |
| 1431 | + |
| 1432 | + TestUtils.dropTableIfExists(tableNameDestination, stmt); |
| 1433 | + String createDestinationTableSQL = "CREATE TABLE " + tableNameDestination + " (id INT, value VARCHAR(50))"; |
| 1434 | + stmt.execute(createDestinationTableSQL); |
| 1435 | + |
| 1436 | + // Attempt unsupported INSERT-SELECT query for bulk copy api |
| 1437 | + String insertSelectSQL = "INSERT INTO " + tableNameDestination + " SELECT * FROM " + tableNameSource |
| 1438 | + + " WHERE id = ?"; |
| 1439 | + |
| 1440 | + try (SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) connection |
| 1441 | + .prepareStatement(insertSelectSQL)) { |
| 1442 | + pstmt.setInt(1, 1); |
| 1443 | + pstmt.addBatch(); |
| 1444 | + pstmt.executeBatch(); // This should fall back to normal execution flow |
| 1445 | + } |
| 1446 | + |
| 1447 | + // Validate inserted data in destination table |
| 1448 | + String selectSQL = "SELECT * FROM " + tableNameDestination; |
| 1449 | + try (ResultSet rs = stmt.executeQuery(selectSQL)) { |
| 1450 | + assertTrue(rs.next(), "Expected at least one row in result set"); |
| 1451 | + assertEquals(1, rs.getInt("id")); |
| 1452 | + assertEquals("TestValue1", rs.getString("value")); |
| 1453 | + |
| 1454 | + Assertions.assertFalse(rs.next(), "No more rows expected"); |
| 1455 | + } |
| 1456 | + } |
| 1457 | + } |
| 1458 | + |
1410 | 1459 | /**
|
1411 | 1460 | * Test string values using prepared statement using accented and unicode characters.
|
1412 | 1461 | * This test covers all combinations of useBulkCopyForBatchInsert and sendStringParametersAsUnicode.
|
|
0 commit comments