Skip to content

Commit

Permalink
add toUpperCase to JDBC type lookup in createArrayOf in SnowflakeConn…
Browse files Browse the repository at this point in the history
…ectionV1, add unit test
  • Loading branch information
sfc-gh-mkubik committed Dec 19, 2024
1 parent b3a2763 commit 63f8342
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -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()));
}
}
}

0 comments on commit 63f8342

Please sign in to comment.