@@ -3405,6 +3405,56 @@ public void testPreparedStatementWithTriggersAndGeneratedKeys() throws SQLExcept
34053405 }
34063406 }
34073407
3408+ /**
3409+ * Tests PreparedStatement INSERT with multiple values and trigger to validate update count.
3410+ * Reproduces the scenario where INSERT INTO TABLE (col) VALUES (?), (?) should return 2 but returns 1.
3411+ * This test validates the fix for TDS token processing with triggers that affect update counts.
3412+ *
3413+ * @throws SQLException
3414+ */
3415+ @ Test
3416+ public void testPreparedStatementInsertMultipleValuesWithTrigger () throws SQLException {
3417+ // Create separate test tables to avoid conflicts with existing setup
3418+ String testTableA = AbstractSQLGenerator .escapeIdentifier (RandomUtil .getIdentifier ("UpdateCountTestTableA" ));
3419+ String testTableB = AbstractSQLGenerator .escapeIdentifier (RandomUtil .getIdentifier ("UpdateCountTestTableB" ));
3420+ String testTrigger = AbstractSQLGenerator .escapeIdentifier (RandomUtil .getIdentifier ("UpdateCountTestTrigger" ));
3421+
3422+ try (Connection conn = getConnection ();
3423+ Statement stmt = conn .createStatement ()) {
3424+
3425+ TestUtils .dropTriggerIfExists (testTrigger , stmt );
3426+ TestUtils .dropTableIfExists (testTableB , stmt );
3427+ TestUtils .dropTableIfExists (testTableA , stmt );
3428+
3429+ stmt .executeUpdate ("CREATE TABLE " + testTableA + " (ID int NOT NULL IDENTITY(1,1) PRIMARY KEY, NAME varchar(32))" );
3430+ stmt .executeUpdate ("CREATE TABLE " + testTableB + " (ID int NOT NULL IDENTITY(1,1) PRIMARY KEY)" );
3431+
3432+
3433+ stmt .executeUpdate ("CREATE TRIGGER " + testTrigger + " ON " + testTableA + " FOR INSERT AS "
3434+ + "INSERT INTO " + testTableB + " DEFAULT VALUES" );
3435+
3436+ // Test case: INSERT with multiple values should return correct update count
3437+ String sql = "INSERT INTO " + testTableA + " (NAME) VALUES (?), (?)" ;
3438+ try (PreparedStatement ps = conn .prepareStatement (sql )) {
3439+ ps .setString (1 , "value1" );
3440+ ps .setString (2 , "value2" );
3441+
3442+ boolean hasResultSet = ps .execute ();
3443+
3444+ if (!hasResultSet ) {
3445+ int updateCount = ps .getUpdateCount ();
3446+ // This should return 2 (for 2 inserted rows), not 1
3447+ assertEquals (2 , updateCount , "Update count should be 2 for INSERT with 2 values, but got: " + updateCount );
3448+ } else {
3449+ fail ("Expected update count, but got ResultSet instead" );
3450+ }
3451+ }
3452+ TestUtils .dropTriggerIfExists (testTrigger , stmt );
3453+ TestUtils .dropTableIfExists (testTableB , stmt );
3454+ TestUtils .dropTableIfExists (testTableA , stmt );
3455+ }
3456+ }
3457+
34083458 @ AfterEach
34093459 public void terminate () {
34103460 try (Connection con = getConnection (); Statement stmt = con .createStatement ()) {
0 commit comments