Skip to content

Commit

Permalink
11.2.2 backport 1898 Fixed callable statement index out of bounds err…
Browse files Browse the repository at this point in the history
…or; Fixed parameter not defined error (#2002)
  • Loading branch information
tkyc committed Dec 14, 2022
1 parent eeef9c8 commit fa48f7c
Show file tree
Hide file tree
Showing 9 changed files with 161 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1351,13 +1351,11 @@ private int findColumn(String columnName) throws SQLServerException {

}

int l = 0;
if (null != parameterNames) {
l = parameterNames.size();
}
if (l == 0) { // Server didn't return anything, user might not have access
map.putIfAbsent(columnName, ai.incrementAndGet());
return map.get(columnName);// attempting to look up the first column will return no access exception
// @RETURN_VALUE will always be in the parameterNames map, so parameterNamesSize will always be at least of size 1.
// If the server didn't return anything (eg. the param names for the sproc), user might not have access.
// So, parameterNamesSize must be of size 1.
if (null != parameterNames && parameterNames.size() == 1) {
return map.computeIfAbsent(columnName, ifAbsent -> ai.incrementAndGet());
}

// handle `@name` as well as `name`, since `@name` is what's returned
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ protected Object[][] getContents() {
{"R_noServerResponse", "SQL Server did not return a response. The connection has been closed."},
{"R_truncatedServerResponse", "SQL Server returned an incomplete response. The connection has been closed."},
{"R_queryTimedOut", "The query has timed out."},
{"R_queryCancelled", "The query was canceled."},
{"R_queryCanceled", "The query was canceled."},
{"R_errorReadingStream", "An error occurred while reading the value from the stream object. Error: \"{0}\""},
{"R_streamReadReturnedInvalidValue", "The stream read operation returned an invalid value for the amount of data read."},
{"R_mismatchedStreamLength", "The stream value is not the specified length. The specified length was {0}, the actual length is {1}."},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1242,7 +1242,7 @@ public final void cancel() throws SQLServerException {

// Cancel the currently executing statement.
if (null != currentCommand)
currentCommand.interrupt(SQLServerException.getErrString("R_queryCancelled"));
currentCommand.interrupt(SQLServerException.getErrString("R_queryCanceled"));
loggerExternal.exiting(getClassNameLogging(), "cancel");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ protected Object[][] getContents() {
{"R_cancellationFailed", "Cancellation failed."}, {"R_executionNotTimeout", "Execution did not timeout."},
{"R_executionTooLong", "Execution took too long."},
{"R_executionNotLong", "Execution did not take long enough."},
{"R_queryCancelled", "The query was canceled."},
{"R_queryCanceled", "The query was canceled."},
{"R_statementShouldBeClosed", "statement should be closed since resultset is closed."},
{"R_statementShouldBeOpened", "statement should be opened since resultset is opened."},
{"R_shouldBeWrapper", "{0} should be a wrapper for {1}."},
Expand Down
11 changes: 11 additions & 0 deletions src/test/java/com/microsoft/sqlserver/jdbc/TestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,17 @@ public static void dropTypeIfExists(String typeName, java.sql.Statement stmt) th
dropObjectIfExists(typeName, "TT", stmt);
}

/**
* Drops user defined types
*
* @param typeName
* @param stmt
* @throws SQLException
*/
public static void dropUserDefinedTypeIfExists(String typeName, Statement stmt) throws SQLException {
stmt.executeUpdate("IF EXISTS (select * from sys.types where name = '" + escapeSingleQuotes(typeName) + "') DROP TYPE " + typeName);
}

/**
* mimic "DROP DATABASE ..."
*
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public void testBatchStatementCancellation() throws Exception {
try {
statement.executeBatch();
} catch (SQLException e) {
assertEquals(TestResource.getResource("R_queryCancelled"), e.getMessage());
assertEquals(TestResource.getResource("R_queryCanceled"), e.getMessage());
}
cancelThread.join();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void run() {
stmt.execute("WAITFOR DELAY '00:00:" + (DELAY_WAIT_MILLISECONDS / 1000) + "'");
} catch (SQLException e) {
// The query was canceled"), "Unexpected error message
assertTrue(e.getMessage().startsWith(TestResource.getResource("R_queryCancelled")),
assertTrue(e.getMessage().startsWith(TestResource.getResource("R_queryCanceled")),
TestResource.getResource("R_unexpectedExceptionContent"));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ public void testCancelLongResponse() throws Exception {

assertEquals(false, true, TestResource.getResource("R_expectedExceptionNotThrown"));
} catch (SQLException e) {
assertEquals(TestResource.getResource("R_queryCancelled"), e.getMessage());
assertEquals(TestResource.getResource("R_queryCanceled"), e.getMessage());
}

assertEquals(false, NUM_TABLE_ROWS * NUM_TABLE_ROWS == numSelectedRows,
Expand Down Expand Up @@ -345,7 +345,7 @@ public void testCancelBlockedResponse() throws Exception {

assertEquals(false, true, TestResource.getResource("R_expectedExceptionNotThrown"));
} catch (SQLException e) {
assertTrue(TestResource.getResource("R_queryCancelled").equalsIgnoreCase(
assertTrue(TestResource.getResource("R_queryCanceled").equalsIgnoreCase(
e.getMessage()), TestResource.getResource("R_unexpectedException"));
}

Expand Down Expand Up @@ -434,7 +434,7 @@ public void testCancelBlockedResponsePS() throws Exception {

assertEquals(false, true, TestResource.getResource("R_expectedExceptionNotThrown"));
} catch (SQLException e) {
assertTrue(TestResource.getResource("R_queryCancelled").contains(e.getMessage()),
assertTrue(TestResource.getResource("R_queryCanceled").contains(e.getMessage()),
TestResource.getResource("R_unexpectedException"));
}

Expand Down Expand Up @@ -533,7 +533,7 @@ public void testCancelBlockedCursoredResponse() throws Exception {

assertEquals(false, true, TestResource.getResource("R_expectedExceptionNotThrown"));
} catch (SQLException e) {
assertTrue(TestResource.getResource("R_queryCancelled").contains(e.getMessage()),
assertTrue(TestResource.getResource("R_queryCanceled").contains(e.getMessage()),
TestResource.getResource("R_unexpectedException"));
}
elapsedMillis += System.currentTimeMillis();
Expand Down

0 comments on commit fa48f7c

Please sign in to comment.