@@ -1130,7 +1130,6 @@ public void testStatementsWithDatabaseInTableIdentifier() throws Exception {
1130
1130
1131
1131
for (int i = 0 ; i < tableIdentifier .length ; i ++) {
1132
1132
String tableId = tableIdentifier [i ];
1133
- System .out .println (">> " + tableId );
1134
1133
final String insertStmt = "INSERT INTO " + tableId + " VALUES (?, ?)" ;
1135
1134
try (PreparedStatement stmt = conn .prepareStatement (insertStmt )) {
1136
1135
stmt .setInt (1 , i + 10 );
@@ -1300,6 +1299,39 @@ public static Object[][] testTypeCastsDP() {
1300
1299
{"ed0c77a3-2e4b-4954-98ee-22a4fdad9565" , ClickHouseDataType .UUID , ClickHouseDataType .UUID },
1301
1300
{"::ffff:127.0.0.1" , ClickHouseDataType .IPv6 , ClickHouseDataType .IPv6 },
1302
1301
{"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 }
1303
1335
};
1304
1336
}
1305
1337
@@ -1310,6 +1342,9 @@ public void testTypesInvalidForCast() throws Exception {
1310
1342
for (ClickHouseDataType type : JdbcUtils .INVALID_TARGET_TYPES ) {
1311
1343
expectThrows (SQLException .class , ()->stmt .setObject (1 , "" , type ));
1312
1344
}
1345
+
1346
+ expectThrows (SQLException .class , ()->stmt .setObject (1 , "" , JDBCType .OTHER .getVendorTypeNumber ()));
1347
+ expectThrows (SQLException .class , ()->stmt .setObject (1 , "" , ClickHouseDataType .DateTime64 ));
1313
1348
}
1314
1349
}
1315
1350
}
@@ -1335,7 +1370,7 @@ public static Object[][] testTypeCastWithScaleOrLengthDP() {
1335
1370
return new Object [][] {
1336
1371
{0.123456789 , ClickHouseDataType .Decimal64 , 3 , "0.123" , "Decimal(18, 3)" },
1337
1372
{"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)" }
1339
1374
};
1340
1375
}
1341
1376
0 commit comments