Skip to content

Commit

Permalink
add integration test for ascii char issue fix
Browse files Browse the repository at this point in the history
testing

remove unit test

format
  • Loading branch information
sfc-gh-ext-simba-lb committed May 29, 2023
1 parent 77e286b commit 49a0f2e
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ private void continueParsingInternal(ByteBuffer in, boolean lastData, SFBaseSess
// the last remaining data in the buffer),
// there is not enough bytes to parse the codepoint. Move the position back 1,
// so we can re-enter parsing at this position with the ESCAPE state.
((Buffer) in).position(((Buffer) in).position() - 1);
in.position(in.position() - 1);
state = State.ESCAPE;
return;
}
Expand Down
51 changes: 51 additions & 0 deletions src/test/java/net/snowflake/client/jdbc/ResultSetLatestIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -951,4 +951,55 @@ public void testGranularTimeFunctionsInUTC() throws SQLException {
connection.close();
}
}

@Test
public void testJsonParsingOfAsciiCharacters() throws SQLException {
Connection connection = init();
Statement statement = connection.createStatement();
statement.execute("alter session set jdbc_query_result_format ='json'");
// statement.execute("ALTER SESSION SET CLIENT_STAGE_ARRAY_BINDING_THRESHOLD = 0");
statement.execute(
"create or replace table asciiTable (colA string, colB string, colC string, colD string, colE string, colF string, colG string, colH string, colI string, colJ string, colK string, colL string)");

PreparedStatement preparedStatement =
connection.prepareStatement(
"insert into asciiTable values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
for (int i = 0; i < 35000; i++) {
preparedStatement.setInt(1, i);
preparedStatement.setString(2, "123456");
preparedStatement.setString(3, "dummy");
preparedStatement.setString(
4,
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000Ì\u0000\u0000\u0000\u0000\u0003ä\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000");
preparedStatement.setString(5, null);
preparedStatement.setString(6, " ");
preparedStatement.setString(
7,
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000Ì\u0000\u0000\u0000\u0000\u0003ä\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000");
preparedStatement.setString(8, "021-436-5589");
preparedStatement.setString(9, " ");
preparedStatement.setString(10, "dummy");
preparedStatement.setString(11, "934-999-567");
preparedStatement.setString(12, " ");
preparedStatement.addBatch();
}
preparedStatement.executeBatch();

ResultSet resultSet = statement.executeQuery("select count(*) from asciiTable");
resultSet.next();
assertEquals("35000", resultSet.getString(1));

resultSet = statement.executeQuery("select * from asciiTable");
while (resultSet.next()) {
String expectedHexVal =
"00 00 00 00 00 00 00 00 00 C3 8C 00 00 00 00 03 C3 A4 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ";
assertEquals(expectedHexVal, ResultJsonParserV2Test.stringToHex(resultSet.getString(4)));
assertEquals(expectedHexVal, ResultJsonParserV2Test.stringToHex(resultSet.getString(7)));
}

statement.execute("drop table if exists asciiTable");
preparedStatement.close();
statement.close();
connection.close();
}
}

0 comments on commit 49a0f2e

Please sign in to comment.