Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

11.2.2 backport 1898 Fixed callable statement index out of bounds error; Fixed parameter not defined error #2002

Merged
merged 2 commits into from
Dec 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@

<!-- JUnit Test Dependencies -->
<junit.platform.version>[1.3.2, 1.9.0]</junit.platform.version>
<junit.jupiter.version>5.5.2</junit.jupiter.version>
<junit.jupiter.version>5.8.2</junit.jupiter.version>
<hikaricp.version>3.4.2</hikaricp.version>
<dbcp2.version>2.7.0</dbcp2.version>
<slf4j.nop.version>1.7.30</slf4j.nop.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1348,13 +1348,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