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 1/2] 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())); + } + } } From 956fb54a5c64c3f8cee808adaf84a3331595dec5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Kubik?= Date: Thu, 19 Dec 2024 11:12:49 +0100 Subject: [PATCH 2/2] move typeName case test to integration tests --- ...ngAndInsertingStructuredTypesLatestIT.java | 7 ++++++ .../jdbc/SnowflakeConnectionV1Test.java | 22 ------------------- 2 files changed, 7 insertions(+), 22 deletions(-) diff --git a/src/test/java/net/snowflake/client/jdbc/BindingAndInsertingStructuredTypesLatestIT.java b/src/test/java/net/snowflake/client/jdbc/BindingAndInsertingStructuredTypesLatestIT.java index 55cdf9996..78b55e756 100644 --- a/src/test/java/net/snowflake/client/jdbc/BindingAndInsertingStructuredTypesLatestIT.java +++ b/src/test/java/net/snowflake/client/jdbc/BindingAndInsertingStructuredTypesLatestIT.java @@ -272,8 +272,11 @@ public void testWriteArray(ResultSetFormatType queryResultFormat) throws SQLExce statement.execute(" CREATE OR REPLACE TABLE array_of_integers(arrayInt ARRAY(INTEGER))"); Array array = connection.createArrayOf("INTEGER", new Integer[] {1, 2, 3}); + Array arrayFromLowerCaseType = connection.createArrayOf("integer", new Integer[] {1, 2, 3}); stmt.setArray(1, array); stmt.executeUpdate(); + stmt.setArray(1, arrayFromLowerCaseType); + stmt.executeUpdate(); try (ResultSet resultSet = statement.executeQuery("SELECT * from array_of_integers"); ) { resultSet.next(); @@ -282,6 +285,10 @@ public void testWriteArray(ResultSetFormatType queryResultFormat) throws SQLExce assertEquals(Long.valueOf(1), resultArray[0]); assertEquals(Long.valueOf(2), resultArray[1]); assertEquals(Long.valueOf(3), resultArray[2]); + + resultSet.next(); + Long[] resultArrayFromLowerCaseType = (Long[]) resultSet.getArray(1).getArray(); + assertArrayEquals(resultArray, resultArrayFromLowerCaseType); } } } diff --git a/src/test/java/net/snowflake/client/jdbc/SnowflakeConnectionV1Test.java b/src/test/java/net/snowflake/client/jdbc/SnowflakeConnectionV1Test.java index 899cc79e3..de6c4fb70 100644 --- a/src/test/java/net/snowflake/client/jdbc/SnowflakeConnectionV1Test.java +++ b/src/test/java/net/snowflake/client/jdbc/SnowflakeConnectionV1Test.java @@ -3,16 +3,9 @@ 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. */ @@ -205,19 +198,4 @@ 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())); - } - } }