|
9 | 9 | import java.sql.Connection; |
10 | 10 | import java.sql.PreparedStatement; |
11 | 11 | import java.sql.ResultSet; |
12 | | -import java.sql.SQLException; |
13 | 12 | import java.sql.Statement; |
14 | 13 | import java.sql.Types; |
15 | 14 | import java.util.Arrays; |
@@ -496,63 +495,26 @@ void testStatementSplit() throws Exception { |
496 | 495 | void testClearParameters() throws Exception { |
497 | 496 | String sql = "insert into `test_issue_2299` (`id`, `name`, `age`) values (?, ?, ?)"; |
498 | 497 | 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)) { |
501 | 499 |
|
502 | 500 | try (Statement stmt = conn.createStatement()) { |
503 | 501 | stmt.execute("CREATE TABLE IF NOT EXISTS `test_issue_2299` (`id` Nullable(String), `name` Nullable(String), `age` Int32) ENGINE Memory;"); |
504 | 502 | } |
505 | 503 |
|
506 | | - Assert.assertEquals(ps.parameters.length, 3); |
507 | | - ps.clearParameters(); |
508 | 504 | Assert.assertEquals(ps.parameters.length, 3); |
509 | 505 |
|
510 | 506 | ps.setString(1, "testId"); |
511 | 507 | ps.setString(2, "testName"); |
512 | 508 | 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(); |
531 | 510 |
|
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); |
545 | 513 |
|
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(); |
556 | 518 | } |
557 | 519 | } |
558 | 520 | } |
0 commit comments