Skip to content

Commit cfa48eb

Browse files
author
jielongping
committed
Update test case.
1 parent 378f961 commit cfa48eb

File tree

2 files changed

+9
-47
lines changed

2 files changed

+9
-47
lines changed

jdbc-v2/src/main/java/com/clickhouse/jdbc/PreparedStatementImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public PreparedStatementImpl(ConnectionImpl connection, String sql) throws SQLEx
8181
this.defaultCalendar = connection.defaultCalendar;
8282
}
8383

84-
String compileSql(String []segments) {
84+
private String compileSql(String []segments) {
8585
StringBuilder sb = new StringBuilder();
8686
for (int i = 0; i < segments.length; i++) {
8787
sb.append(segments[i]);

jdbc-v2/src/test/java/com/clickhouse/jdbc/PreparedStatementTest.java

Lines changed: 8 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import java.sql.Connection;
1010
import java.sql.PreparedStatement;
1111
import java.sql.ResultSet;
12-
import java.sql.SQLException;
1312
import java.sql.Statement;
1413
import java.sql.Types;
1514
import java.util.Arrays;
@@ -496,63 +495,26 @@ void testStatementSplit() throws Exception {
496495
void testClearParameters() throws Exception {
497496
String sql = "insert into `test_issue_2299` (`id`, `name`, `age`) values (?, ?, ?)";
498497
try (Connection conn = getJdbcConnection();
499-
PreparedStatementImpl ps = (PreparedStatementImpl) conn.prepareStatement(sql);
500-
TestPreparedStatementImpl ps2 = new TestPreparedStatementImpl((ConnectionImpl) conn, sql)) {
498+
PreparedStatementImpl ps = (PreparedStatementImpl) conn.prepareStatement(sql)) {
501499

502500
try (Statement stmt = conn.createStatement()) {
503501
stmt.execute("CREATE TABLE IF NOT EXISTS `test_issue_2299` (`id` Nullable(String), `name` Nullable(String), `age` Int32) ENGINE Memory;");
504502
}
505503

506-
Assert.assertEquals(ps.parameters.length, 3);
507-
ps.clearParameters();
508504
Assert.assertEquals(ps.parameters.length, 3);
509505

510506
ps.setString(1, "testId");
511507
ps.setString(2, "testName");
512508
ps.setInt(3, 18);
513-
String compiledSql1 = ps.compileSql(ps.sqlSegments);
514-
Assert.assertEquals(compiledSql1, "insert into `test_issue_2299` (`id`, `name`, `age`) values ('testId', 'testName', 18)");
515-
516-
517-
Assert.assertEquals(ps2.parameters.length, 3);
518-
ps2.clearParameters();
519-
Assert.assertEquals(ps2.parameters.length, 4);
520-
521-
ps2.setString(1, "testId");
522-
ps2.setString(2, "testName");
523-
ps2.setInt(3, 18);
524-
525-
String compiledSql2 = ps2.compileSql(ps2.sqlSegments);
526-
Assert.assertEquals(compiledSql2, "insert into `test_issue_2299` (`id`, `name`, `age`) values ('testId', 'testName', 18)null");
527-
}
528-
}
529-
530-
static class TestPreparedStatementImpl extends PreparedStatementImpl {
509+
ps.execute();
531510

532-
public TestPreparedStatementImpl(ConnectionImpl connection, String sql) throws SQLException {
533-
super(connection, sql);
534-
}
535-
536-
@Override
537-
public void clearParameters() throws SQLException {
538-
checkClosed();
539-
if (originalSql.contains("?")) {
540-
this.parameters = new Object[sqlSegments.length];
541-
} else {
542-
this.parameters = new Object[0];
543-
}
544-
}
511+
ps.clearParameters();
512+
Assert.assertEquals(ps.parameters.length, 3);
545513

546-
@Override
547-
String compileSql(String[] segments) {
548-
StringBuilder sb = new StringBuilder();
549-
for (int i = 0; i < segments.length; i++) {
550-
sb.append(segments[i]);
551-
if (i < parameters.length) {
552-
sb.append(parameters[i]);
553-
}
554-
}
555-
return sb.toString();
514+
ps.setString(1, "testId2");
515+
ps.setString(2, "testName2");
516+
ps.setInt(3, 19);
517+
ps.execute();
556518
}
557519
}
558520
}

0 commit comments

Comments
 (0)