From fc9fe27b17bf8be350f5ae7abebb5ba4f6465cc7 Mon Sep 17 00:00:00 2001 From: reimai Date: Mon, 20 Jun 2022 17:56:11 +0300 Subject: [PATCH] add multiple insert test for both drivers --- .../jdbc/ClickHouseStatementTest.java | 25 +++++++++++++++++++ .../ClickHouseStatementImplTest.java | 24 ++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/clickhouse-jdbc/src/test/java/com/clickhouse/jdbc/ClickHouseStatementTest.java b/clickhouse-jdbc/src/test/java/com/clickhouse/jdbc/ClickHouseStatementTest.java index b02f80390..ddcee64f2 100644 --- a/clickhouse-jdbc/src/test/java/com/clickhouse/jdbc/ClickHouseStatementTest.java +++ b/clickhouse-jdbc/src/test/java/com/clickhouse/jdbc/ClickHouseStatementTest.java @@ -753,4 +753,29 @@ public void testTimeZone(boolean useBinary) throws SQLException { } } } + + @Test(groups = "integration") + public void testInsertMultiple() throws SQLException { + try (ClickHouseConnection conn = newConnection(new Properties()); + ClickHouseStatement s = conn.createStatement()) { + conn.createStatement().execute( + "DROP TABLE IF EXISTS test_insert_multiple"); + conn.createStatement().execute( + "CREATE TABLE IF NOT EXISTS test_insert_multiple" + + "(id UInt32, name String) " + + "ENGINE = Memory"); + try (PreparedStatement ps = conn.prepareStatement( + "INSERT INTO test_insert VALUES (?, ?), (?, ?)")) { + ps.setInt(1, 1); + ps.setString(2, "John"); + ps.setInt(3, 2); + ps.setString(4, "Donne"); + ps.executeUpdate(); + } + ResultSet rs = s.executeQuery( + "SELECT count(*) FROM test_insert_multiple"); + rs.next(); + Assert.assertEquals(rs.getInt(1), 2); + } + } } diff --git a/clickhouse-jdbc/src/test/java/ru/yandex/clickhouse/ClickHouseStatementImplTest.java b/clickhouse-jdbc/src/test/java/ru/yandex/clickhouse/ClickHouseStatementImplTest.java index 9bb493d2f..82e1c4f3f 100644 --- a/clickhouse-jdbc/src/test/java/ru/yandex/clickhouse/ClickHouseStatementImplTest.java +++ b/clickhouse-jdbc/src/test/java/ru/yandex/clickhouse/ClickHouseStatementImplTest.java @@ -15,6 +15,7 @@ import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; +import java.sql.PreparedStatement; import java.sql.Statement; import java.sql.Types; import java.util.ArrayList; @@ -559,6 +560,29 @@ public void testJsonResponseWithNull() throws SQLException { } } + @Test(groups = "integration") + public void testInsertMultiple() throws SQLException { + connection.createStatement().execute( + "DROP TABLE IF EXISTS test_insert_multiple_old_driver"); + connection.createStatement().execute( + "CREATE TABLE IF NOT EXISTS test_insert_multiple_old_driver" + + "(id UInt32, name String) " + + "ENGINE = Memory"); + try (PreparedStatement ps = connection.prepareStatement( + "INSERT INTO test_insert_multiple_old_driver VALUES (?, ?), (?, ?)")) { + ps.setInt(1, 1); + ps.setString(2, "John"); + ps.setInt(3, 2); + ps.setString(4, "Donne"); + ps.executeUpdate(); + } + + ResultSet rs = connection.createStatement().executeQuery( + "SELECT count(*) FROM test_insert_multiple_old_driver"); + rs.next(); + assertEquals(rs.getInt(1), 2); + } + private static String readQueryId(ClickHouseStatementImpl stmt, long timeoutSecs) { long start = System.currentTimeMillis(); String value;