Skip to content

Commit 1c2a7df

Browse files
committed
added test to some methods
1 parent 797e50c commit 1c2a7df

File tree

2 files changed

+37
-5
lines changed

2 files changed

+37
-5
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -413,14 +413,13 @@ public void setNString(int parameterIndex, String value) throws SQLException {
413413
@Override
414414
public void setObject(int parameterIndex, Object x, int targetSqlType, int scaleOrLength) throws SQLException {
415415
ensureOpen();
416-
// TODO: make proper data conversion in setObject methods
417-
writer.setValue(parameterIndex, x);
416+
throw new SQLException("This form of setObject is not supported yet", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED);
418417
}
419418

420419
@Override
421420
public void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException {
422421
ensureOpen();
423-
writer.setValue(parameterIndex, x);
422+
throw new SQLException("This form of setObject is not supported yet", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED);
424423
}
425424

426425
@Override
@@ -431,13 +430,14 @@ public void setObject(int parameterIndex, Object x) throws SQLException {
431430

432431
@Override
433432
public void setObject(int parameterIndex, Object x, SQLType targetSqlType) throws SQLException {
434-
setObject(parameterIndex, x, targetSqlType, 0);
433+
ensureOpen();
434+
throw new SQLException("This form of setObject is not supported yet", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED);
435435
}
436436

437437
@Override
438438
public void setObject(int parameterIndex, Object x, SQLType targetSqlType, int scaleOrLength) throws SQLException {
439439
ensureOpen();
440-
writer.setValue(parameterIndex, x);
440+
throw new SQLException("This form of setObject is not supported yet", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED);
441441
}
442442

443443
@Override
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.clickhouse.jdbc;
2+
3+
import com.clickhouse.jdbc.internal.DriverProperties;
4+
import org.testng.Assert;
5+
import org.testng.annotations.Test;
6+
7+
import java.sql.Connection;
8+
import java.sql.JDBCType;
9+
import java.sql.PreparedStatement;
10+
import java.sql.SQLException;
11+
import java.util.Properties;
12+
13+
@Test(groups = {"integration"})
14+
public class WriterStatementImplTest extends JdbcIntegrationTest {
15+
16+
17+
@Test(groups = {"integration"})
18+
public void testTargetTypeMethodThrowException() throws SQLException {
19+
20+
Properties properties = new Properties();
21+
properties.setProperty(DriverProperties.BETA_ROW_BINARY_WRITER.getKey(), "true");
22+
try (Connection connection = getJdbcConnection(properties);
23+
PreparedStatement stmt = connection.prepareStatement("INSERT INTO system.numbers VALUES (?, ?)")) {
24+
Assert.assertTrue(stmt instanceof WriterStatementImpl);
25+
26+
Assert.expectThrows(SQLException.class, () -> stmt.setObject(1, "", JDBCType.VARCHAR.getVendorTypeNumber()));
27+
Assert.expectThrows(SQLException.class, () -> stmt.setObject(1, "", JDBCType.VARCHAR));
28+
Assert.expectThrows(SQLException.class, () -> stmt.setObject(1, "", JDBCType.DECIMAL.getVendorTypeNumber(), 3));
29+
Assert.expectThrows(SQLException.class, () -> stmt.setObject(1, "", JDBCType.DECIMAL, 3));
30+
}
31+
}
32+
}

0 commit comments

Comments
 (0)