From e1267062316bfc382328354e5be45cbf50a67e1b Mon Sep 17 00:00:00 2001 From: "v-susanh@microsoft.com" Date: Wed, 13 Sep 2023 13:08:04 -0700 Subject: [PATCH 1/2] fix for invalid index --- .../sqlserver/jdbc/SQLServerParameterMetaData.java | 4 +++- .../jdbc/parametermetadata/ParameterMetaDataTest.java | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerParameterMetaData.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerParameterMetaData.java index 56fce55c0..a27a31d47 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerParameterMetaData.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerParameterMetaData.java @@ -397,7 +397,9 @@ private Map 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) { diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/parametermetadata/ParameterMetaDataTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/parametermetadata/ParameterMetaDataTest.java index 61b9936af..736a431c9 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/parametermetadata/ParameterMetaDataTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/parametermetadata/ParameterMetaDataTest.java @@ -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; @@ -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); @@ -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)); } } } From ee0d9335458235dccb6dd52748525a324006cbb3 Mon Sep 17 00:00:00 2001 From: "v-susanh@microsoft.com" Date: Wed, 13 Sep 2023 13:09:41 -0700 Subject: [PATCH 2/2] remove blank line --- .../com/microsoft/sqlserver/jdbc/SQLServerParameterMetaData.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerParameterMetaData.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerParameterMetaData.java index a27a31d47..aeb7a99d9 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerParameterMetaData.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerParameterMetaData.java @@ -397,7 +397,6 @@ private Map getParameterInfo(int param) { private boolean isValidParamProc(int n) { // Note row 1 is the 'return value' meta data - return (n >= 1 // JDBC index is 1 based && ((stmtParent.bReturnValueSyntax && isTVP && procMetadata.size() >= n) || procMetadata.size() > n)); }