From 63f83425536785f9bd201298b12597370943ed0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Kubik?= Date: Thu, 19 Dec 2024 09:25:23 +0100 Subject: [PATCH] add toUpperCase to JDBC type lookup in createArrayOf in SnowflakeConnectionV1, add unit test --- .../client/jdbc/SnowflakeConnectionV1.java | 2 +- .../jdbc/SnowflakeConnectionV1Test.java | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/snowflake/client/jdbc/SnowflakeConnectionV1.java b/src/main/java/net/snowflake/client/jdbc/SnowflakeConnectionV1.java index 23ce7d2ef..e93a38d08 100644 --- a/src/main/java/net/snowflake/client/jdbc/SnowflakeConnectionV1.java +++ b/src/main/java/net/snowflake/client/jdbc/SnowflakeConnectionV1.java @@ -726,7 +726,7 @@ public String getClientInfo(String name) throws SQLException { @Override public Array createArrayOf(String typeName, Object[] elements) throws SQLException { logger.trace("Array createArrayOf(String typeName, Object[] " + "elements)", false); - return new SfSqlArray(JDBCType.valueOf(typeName).getVendorTypeNumber(), elements); + return new SfSqlArray(JDBCType.valueOf(typeName.toUpperCase()).getVendorTypeNumber(), elements); } @Override diff --git a/src/test/java/net/snowflake/client/jdbc/SnowflakeConnectionV1Test.java b/src/test/java/net/snowflake/client/jdbc/SnowflakeConnectionV1Test.java index de6c4fb70..899cc79e3 100644 --- a/src/test/java/net/snowflake/client/jdbc/SnowflakeConnectionV1Test.java +++ b/src/test/java/net/snowflake/client/jdbc/SnowflakeConnectionV1Test.java @@ -3,9 +3,16 @@ import static net.snowflake.client.jdbc.DefaultSFConnectionHandler.mergeProperties; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; +import java.sql.Array; +import java.sql.JDBCType; +import java.sql.SQLException; +import java.util.ArrayList; import java.util.Map; import java.util.Properties; +import net.snowflake.client.core.SFBaseSession; import org.junit.jupiter.api.Test; /** Created by hyu on 2/2/18. */ @@ -198,4 +205,19 @@ public void testMergeProperties() { assertThat(result.get("PROP1"), is("value1|value2")); assertThat(result.get("PROP2"), is("carrot^")); } + + @Test + public void testCreateArrayOfIsCaseInsensitive() throws SQLException { + SFConnectionHandler mockConnectionHandler = mock(SFConnectionHandler.class); + SFBaseSession sfBaseSession = mock(SFBaseSession.class); + when(mockConnectionHandler.getSFSession()).thenReturn(sfBaseSession); + when(sfBaseSession.checkProperties()).thenReturn(new ArrayList<>()); + try (SnowflakeConnectionV1 connectionV1 = new SnowflakeConnectionV1(mockConnectionHandler)) { + Array arrayLowerCase = connectionV1.createArrayOf("integer", new Integer[] {1, 2, 3}); + Array arrayUpperCase = connectionV1.createArrayOf("VARCHAR", new String[] {"one", "two"}); + + assertThat(arrayLowerCase.getBaseTypeName(), is(JDBCType.INTEGER.getName())); + assertThat(arrayUpperCase.getBaseTypeName(), is(JDBCType.VARCHAR.getName())); + } + } }