|
1 | 1 | package com.clickhouse.jdbc; |
2 | 2 |
|
| 3 | +import com.clickhouse.client.api.data_formats.internal.BinaryStreamReader; |
3 | 4 | import org.testng.annotations.Ignore; |
4 | 5 | import org.testng.annotations.Test; |
5 | 6 |
|
|
8 | 9 | import java.sql.ResultSet; |
9 | 10 | import java.sql.Timestamp; |
10 | 11 | import java.sql.Types; |
| 12 | +import java.util.Arrays; |
11 | 13 | import java.util.Calendar; |
12 | 14 |
|
13 | 15 | import static org.testng.Assert.assertEquals; |
14 | 16 | import static org.testng.Assert.assertFalse; |
| 17 | +import static org.testng.Assert.assertNotNull; |
15 | 18 | import static org.testng.Assert.assertNull; |
16 | 19 | import static org.testng.Assert.assertTrue; |
17 | 20 |
|
@@ -222,4 +225,37 @@ public void testBigDecimal() throws Exception { |
222 | 225 | } |
223 | 226 | } |
224 | 227 | } |
| 228 | + |
| 229 | + @Test(groups = { "integration" }) |
| 230 | + public void testPrimitiveArrays() throws Exception { |
| 231 | + try (Connection conn = getJdbcConnection()) { |
| 232 | + try (PreparedStatement stmt = conn.prepareStatement("SELECT ?")) { |
| 233 | + stmt.setObject(1, new String[][] {new String[]{"a"}, new String[]{"b"}, new String[]{"c"}}); |
| 234 | + try (ResultSet rs = stmt.executeQuery()) { |
| 235 | + assertTrue(rs.next()); |
| 236 | + assertEquals(((BinaryStreamReader.ArrayValue)((BinaryStreamReader.ArrayValue)rs.getObject(1)).get(0)).get(0), "a"); |
| 237 | + assertEquals(((BinaryStreamReader.ArrayValue)((BinaryStreamReader.ArrayValue)rs.getObject(1)).get(1)).get(0), "b"); |
| 238 | + assertEquals(((BinaryStreamReader.ArrayValue)((BinaryStreamReader.ArrayValue)rs.getObject(1)).get(2)).get(0), "c"); |
| 239 | + assertFalse(rs.next()); |
| 240 | + } |
| 241 | + } |
| 242 | + } |
| 243 | + } |
| 244 | + |
| 245 | + |
| 246 | + @Test(groups = { "integration" }) |
| 247 | + public void testEscapeStrings() throws Exception { |
| 248 | + try (Connection conn = getJdbcConnection()) { |
| 249 | + try (PreparedStatement stmt = conn.prepareStatement("SELECT FALSE OR ? = 'test', ?")) { |
| 250 | + stmt.setString(1, "test\\' OR 1 = 1 --"); |
| 251 | + stmt.setString(2, "test\\\\' OR 1 = 1 --"); |
| 252 | + try (ResultSet rs = stmt.executeQuery()) { |
| 253 | + assertTrue(rs.next()); |
| 254 | + assertEquals(rs.getString(1), "false"); |
| 255 | + assertEquals(rs.getString(2), "test\\\\' OR 1 = 1 --"); |
| 256 | + assertFalse(rs.next()); |
| 257 | + } |
| 258 | + } |
| 259 | + } |
| 260 | + } |
225 | 261 | } |
0 commit comments