@@ -1130,7 +1130,6 @@ public void testStatementsWithDatabaseInTableIdentifier() throws Exception {
11301130
11311131 for (int i = 0 ; i < tableIdentifier .length ; i ++) {
11321132 String tableId = tableIdentifier [i ];
1133- System .out .println (">> " + tableId );
11341133 final String insertStmt = "INSERT INTO " + tableId + " VALUES (?, ?)" ;
11351134 try (PreparedStatement stmt = conn .prepareStatement (insertStmt )) {
11361135 stmt .setInt (1 , i + 10 );
@@ -1300,6 +1299,39 @@ public static Object[][] testTypeCastsDP() {
13001299 {"ed0c77a3-2e4b-4954-98ee-22a4fdad9565" , ClickHouseDataType .UUID , ClickHouseDataType .UUID },
13011300 {"::ffff:127.0.0.1" , ClickHouseDataType .IPv6 , ClickHouseDataType .IPv6 },
13021301 {"116.253.40.133" , ClickHouseDataType .IPv4 , ClickHouseDataType .IPv4 },
1302+ {100 , JDBCType .TINYINT , ClickHouseDataType .Int8 }
1303+ };
1304+ }
1305+
1306+ @ Test (groups = {"integration" }, dataProvider = "testJDBCTypeCastDP" )
1307+ public void testJDBCTypeCast (Object value , int targetType , ClickHouseDataType expectedType ) throws Exception {
1308+ try (Connection conn = getJdbcConnection ()) {
1309+ try (PreparedStatement stmt = conn .prepareStatement ("select ?, toTypeName(?)" )) {
1310+ stmt .setObject (1 , value , targetType );
1311+ stmt .setObject (2 , value , targetType );
1312+
1313+ try (ResultSet rs = stmt .executeQuery ()) {
1314+ rs .next ();
1315+ assertEquals (rs .getString (2 ), expectedType .getName ());
1316+ switch (expectedType ) {
1317+ case IPv4 :
1318+ assertEquals (rs .getString (1 ), "/" + value );
1319+ break ;
1320+ case IPv6 :
1321+ // do not check
1322+ break ;
1323+ default :
1324+ assertEquals (rs .getString (1 ), String .valueOf (value ));
1325+ }
1326+ }
1327+ }
1328+ }
1329+ }
1330+
1331+ @ DataProvider (name = "testJDBCTypeCastDP" )
1332+ public static Object [][] testJDBCTypeCastDP () {
1333+ return new Object [][] {
1334+ {100 , JDBCType .TINYINT .getVendorTypeNumber ().intValue (), ClickHouseDataType .Int8 }
13031335 };
13041336 }
13051337
@@ -1310,6 +1342,9 @@ public void testTypesInvalidForCast() throws Exception {
13101342 for (ClickHouseDataType type : JdbcUtils .INVALID_TARGET_TYPES ) {
13111343 expectThrows (SQLException .class , ()->stmt .setObject (1 , "" , type ));
13121344 }
1345+
1346+ expectThrows (SQLException .class , ()->stmt .setObject (1 , "" , JDBCType .OTHER .getVendorTypeNumber ()));
1347+ expectThrows (SQLException .class , ()->stmt .setObject (1 , "" , ClickHouseDataType .DateTime64 ));
13131348 }
13141349 }
13151350 }
@@ -1335,7 +1370,7 @@ public static Object[][] testTypeCastWithScaleOrLengthDP() {
13351370 return new Object [][] {
13361371 {0.123456789 , ClickHouseDataType .Decimal64 , 3 , "0.123" , "Decimal(18, 3)" },
13371372 {"hello" , ClickHouseDataType .FixedString , 5 , "hello" , "FixedString(5)" },
1338- {"2017-10-02 10:20:30.333333" , ClickHouseDataType .DateTime64 , 3 , "2017-10-02T10 :20:30.333" , "DateTime64(3)" }
1373+ {"2017-10-02 10:20:30.333333" , ClickHouseDataType .DateTime64 , 3 , "2017-10-02 10 :20:30.333" , "DateTime64(3)" }
13391374 };
13401375 }
13411376
0 commit comments