Skip to content

Commit

Permalink
fix: fix parameter formatting for new Firebolt
Browse files Browse the repository at this point in the history
  • Loading branch information
ptiurin committed Oct 15, 2024
1 parent dc4463f commit 9b4b735
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,24 @@ void shouldInsertAndRetrieveUrl() throws SQLException, MalformedURLException {
}
}

@Test
void shouldFetchSpecialCharacters() throws SQLException, MalformedURLException {
try (Connection connection = createConnection()) {
try (PreparedStatement statement = connection
.prepareStatement("SELECT ? as a, ? as b, ? as c ")) {
statement.setString(1, "\0");
statement.setString(2, "\\");
statement.setString(3, "don't");
statement.execute();
ResultSet rs = statement.getResultSet();
assertTrue(rs.next());
assertEquals("\0", rs.getString(1));
assertEquals("\\", rs.getString(2));
assertEquals("don't", rs.getString(3));
}
}
}

@Builder
@Value
@EqualsAndHashCode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public enum JavaTypeToFireboltSQLString {
BYTE_ARRAY(byte[].class, value -> ofNullable(byteArrayToHexString((byte[])value, true)).map(x -> format("E'%s'::BYTEA", x)).orElse(null)),
;
private static final List<Entry<String, String>> characterToEscapedCharacterPairs = List.of(
Map.entry("\0", "\\0"), Map.entry("\\", "\\\\"), Map.entry("'", "''"));
Map.entry("'", "''"));
//https://docs.oracle.com/javase/1.5.0/docs/guide/jdbc/getstart/mapping.html
private static final Map<JDBCType, Class<?>> jdbcTypeToClass = Map.ofEntries(
Map.entry(JDBCType.CHAR, String.class),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,15 @@ void shouldTransformShortToString() throws SQLException {

@Test
void shouldEscapeCharactersWhenTransformingFromString() throws SQLException {
// quotes are escaped
assertEquals("'105'' OR 1=1--'' '", JavaTypeToFireboltSQLString.STRING.transform("105' OR 1=1--' "));

assertEquals("'105'' OR 1=1--'' '", JavaTypeToFireboltSQLString.transformAny("105' OR 1=1--' "));
// \0 is not escaped
assertEquals("'105\0'", JavaTypeToFireboltSQLString.STRING.transform("105\0"));
assertEquals("'105\0'", JavaTypeToFireboltSQLString.transformAny("105\0"));
// backslashes are not escaped
assertEquals("'105\\'", JavaTypeToFireboltSQLString.STRING.transform("105\\"));
assertEquals("'105\\'", JavaTypeToFireboltSQLString.transformAny("105\\"));
}

@Test
Expand Down

0 comments on commit 9b4b735

Please sign in to comment.