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

Fix issue with ParameterMetadata not checking for invalid index 0 #2217

Merged
merged 2 commits into from
Sep 14, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,8 @@ private Map<String, Object> getParameterInfo(int param) {

private boolean isValidParamProc(int n) {
// Note row 1 is the 'return value' meta data
return ((stmtParent.bReturnValueSyntax && isTVP && procMetadata.size() >= n) || procMetadata.size() > n);
return (n >= 1 // JDBC index is 1 based
&& ((stmtParent.bReturnValueSyntax && isTVP && procMetadata.size() >= n) || procMetadata.size() > n));
}

private boolean isValidParamQuery(int n) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
package com.microsoft.sqlserver.jdbc.parametermetadata;

import static org.junit.Assert.assertThrows;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;

Expand Down Expand Up @@ -127,6 +128,10 @@ public void testParameterMetaData() throws SQLException {
assert (metadata.getPrecision(2) == 38);
assert (metadata.getScale(2) == 5);
assert (!metadata.isSigned(1));

// test invalid index
assertThrows(SQLException.class, () -> metadata.getParameterType(0));
assertThrows(SQLException.class, () -> metadata.getParameterType(3));
}
} finally {
TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt);
Expand Down Expand Up @@ -160,6 +165,10 @@ public void testParameterMetaDataProc() throws SQLException {
assert (metadata.getScale(1) == 0);
assert (metadata.isNullable(1) == ParameterMetaData.parameterNullable);
assert (!metadata.isSigned(1));

// test invalid index
assertThrows(SQLException.class, () -> metadata.getParameterType(0));
assertThrows(SQLException.class, () -> metadata.getParameterType(3));
}
}
}
Expand Down
Loading