Skip to content

Commit a2feb7b

Browse files
committed
Addressed PR review comments.
1 parent 5445cd4 commit a2feb7b

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,7 @@ boolean onRetValue(TDSReader tdsReader) throws SQLServerException {
795795
* PreparedStatement does not require this additional token processing.
796796
*/
797797
@Override
798-
protected boolean hasUpdateCountTDSToken(StreamDone doneToken, int executeMethod) {
798+
protected boolean hasUpdateCountTDSTokenForInsertCmd() {
799799
return false;
800800
}
801801

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

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1602,7 +1602,8 @@ boolean onDone(TDSReader tdsReader) throws SQLServerException {
16021602
return false;
16031603

16041604
// For Insert operations, check if additional TDS_DONE token processing is required.
1605-
if (hasUpdateCountTDSToken(doneToken, executeMethod)) {
1605+
if (hasUpdateCountTDSTokenForInsertCmd() && (StreamDone.CMD_INSERT == doneToken.getCurCmd()) && (-1 != doneToken.getUpdateCount())
1606+
&& EXECUTE == executeMethod) {
16061607
return true;
16071608
}
16081609

@@ -1846,20 +1847,15 @@ boolean consumeExecOutParam(TDSReader tdsReader) throws SQLServerException {
18461847

18471848
/**
18481849
* Determines whether to continue processing additional TDS_DONE tokens for INSERT statements.
1849-
* For INSERT operations, the driver must fetch an additional TDS_DONE token that contains
1850+
* For INSERT operations, regular Statement requires reading an additional TDS_DONE token that contains
18501851
* the actual update count. This method can be overridden by subclasses to customize
18511852
* TDS token processing behavior.
18521853
*
1853-
* @param doneToken The current DONE token being processed
1854-
* @param executeMethod The execution method used
1855-
* @return true to continue processing more tokens to get the actual update count,
1856-
* false to stop and return this token
1854+
* @return true to continue processing more tokens to get the actual update count for INSERT operations
18571855
*/
1858-
protected boolean hasUpdateCountTDSToken(StreamDone doneToken, int executeMethod) {
1856+
protected boolean hasUpdateCountTDSTokenForInsertCmd() {
18591857
// For Insert, we must fetch additional TDS_DONE token that comes with the actual update count
1860-
return (StreamDone.CMD_INSERT == doneToken.getCurCmd()) &&
1861-
(-1 != doneToken.getUpdateCount()) &&
1862-
(EXECUTE == executeMethod);
1858+
return true;
18631859
}
18641860

18651861
// --------------------------JDBC 2.0-----------------------------

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3150,7 +3150,9 @@ public void testMultiStatementPreparedStatementLoopResults() {
31503150
@Test
31513151
public void testPreparedStatementExecuteInsertAndSelect() {
31523152
try (Connection con = getConnection()) {
3153-
try (PreparedStatement ps = con.prepareStatement("INSERT INTO " + tableName + " (NAME) VALUES(?) SELECT NAME FROM " + tableName + " WHERE ID = 1")) {
3153+
String sql = "INSERT INTO " + tableName + " (NAME) VALUES(?) " +
3154+
"SELECT NAME FROM " + tableName + " WHERE ID = 1";
3155+
try (PreparedStatement ps = con.prepareStatement(sql)) {
31543156
ps.setString(1, "test");
31553157
boolean retval = ps.execute();
31563158
do {
@@ -3187,7 +3189,12 @@ public void testPreparedStatementExecuteInsertAndSelect() {
31873189
@Test
31883190
public void testPreparedStatementExecuteMergeAndSelect() {
31893191
try (Connection con = getConnection()) {
3190-
try (PreparedStatement ps = con.prepareStatement("MERGE INTO " + tableName + " AS target USING (VALUES (?)) AS source (name) ON target.name = source.name WHEN NOT MATCHED THEN INSERT (name) VALUES (?); SELECT NAME FROM " + tableName + " WHERE ID = 1")) {
3192+
String sql = "MERGE INTO " + tableName + " AS target " +
3193+
"USING (VALUES (?)) AS source (name) " +
3194+
"ON target.name = source.name " +
3195+
"WHEN NOT MATCHED THEN INSERT (name) VALUES (?); " +
3196+
"SELECT NAME FROM " + tableName + " WHERE ID = 1";
3197+
try (PreparedStatement ps = con.prepareStatement(sql)) {
31913198
ps.setString(1, "test1");
31923199
ps.setString(2, "test1");
31933200
boolean retval = ps.execute();

0 commit comments

Comments
 (0)