3
3
import com .clickhouse .client .api .sql .SQLUtils ;
4
4
import com .clickhouse .data .ClickHouseColumn ;
5
5
import com .clickhouse .data .ClickHouseDataType ;
6
+ import com .clickhouse .jdbc .ClientInfoProperties ;
6
7
import com .clickhouse .jdbc .ConnectionImpl ;
7
8
import com .clickhouse .jdbc .Driver ;
9
+ import com .clickhouse .jdbc .DriverProperties ;
8
10
import com .clickhouse .jdbc .JdbcV2Wrapper ;
9
11
import com .clickhouse .jdbc .ResultSetImpl ;
10
- import com .clickhouse .jdbc .ClientInfoProperties ;
11
- import com .clickhouse .jdbc .DriverProperties ;
12
12
import com .clickhouse .jdbc .internal .ExceptionUtils ;
13
13
import com .clickhouse .jdbc .internal .JdbcUtils ;
14
14
import com .clickhouse .jdbc .internal .MetadataResultSet ;
@@ -912,7 +912,8 @@ public ResultSet getColumnPrivileges(String catalog, String schema, String table
912
912
"NULL::Nullable(String) AS GRANTOR, " +
913
913
"NULL::Nullable(String) AS GRANTEE, " +
914
914
"NULL::Nullable(String) AS PRIVILEGE, " +
915
- "NULL::Nullable(String) AS IS_GRANTABLE" );
915
+ "NULL::Nullable(String) AS IS_GRANTABLE" +
916
+ " LIMIT 0" );
916
917
} catch (Exception e ) {
917
918
throw ExceptionUtils .toSqlState (e );
918
919
}
@@ -929,7 +930,8 @@ public ResultSet getTablePrivileges(String catalog, String schemaPattern, String
929
930
"NULL::Nullable(String) AS GRANTOR, " +
930
931
"NULL::Nullable(String) AS GRANTEE, " +
931
932
"NULL::Nullable(String) AS PRIVILEGE, " +
932
- "NULL::Nullable(String) AS IS_GRANTABLE" );
933
+ "NULL::Nullable(String) AS IS_GRANTABLE" +
934
+ " LIMIT 0" );
933
935
} catch (Exception e ) {
934
936
throw ExceptionUtils .toSqlState (e );
935
937
}
@@ -947,7 +949,8 @@ public ResultSet getBestRowIdentifier(String catalog, String schema, String tabl
947
949
"NULL::Nullable(Int32) AS COLUMN_SIZE, " +
948
950
"NULL::Nullable(Int32) AS BUFFER_LENGTH, " +
949
951
"NULL::Nullable(Int16) AS DECIMAL_DIGITS, " +
950
- "NULL::Nullable(Int16) AS PSEUDO_COLUMN" );
952
+ "NULL::Nullable(Int16) AS PSEUDO_COLUMN" +
953
+ " LIMIT 0" );
951
954
} catch (Exception e ) {
952
955
throw ExceptionUtils .toSqlState (e );
953
956
}
@@ -965,7 +968,8 @@ public ResultSet getVersionColumns(String catalog, String schema, String table)
965
968
"NULL::Nullable(Int32) AS COLUMN_SIZE, " +
966
969
"NULL::Nullable(Int32) AS BUFFER_LENGTH, " +
967
970
"NULL::Nullable(Int16) AS DECIMAL_DIGITS, " +
968
- "NULL::Nullable(Int16) AS PSEUDO_COLUMN" );
971
+ "NULL::Nullable(Int16) AS PSEUDO_COLUMN" +
972
+ " LIMIT 0" );
969
973
} catch (Exception e ) {
970
974
throw ExceptionUtils .toSqlState (e );
971
975
}
@@ -995,8 +999,7 @@ public ResultSet getPrimaryKeys(String catalog, String schema, String table) thr
995
999
996
1000
@ Override
997
1001
public ResultSet getImportedKeys (String catalog , String schema , String table ) throws SQLException {
998
- //Return an empty result set with the required columns
999
- log .warn ("getImportedKeys is not supported and may return invalid results" );
1002
+ // ClickHouse has no notion of foreign key. This method should return empty resultset
1000
1003
try {
1001
1004
String sql = "SELECT NULL::Nullable(String) AS PKTABLE_CAT, " +
1002
1005
"NULL::Nullable(String) AS PKTABLE_SCHEM, " +
@@ -1011,7 +1014,8 @@ public ResultSet getImportedKeys(String catalog, String schema, String table) th
1011
1014
"NULL::Nullable(Int16) AS DELETE_RULE, " +
1012
1015
"NULL::Nullable(String) AS FK_NAME, " +
1013
1016
"NULL::Nullable(String) AS PK_NAME, " +
1014
- "NULL::Nullable(Int16) AS DEFERRABILITY" ;
1017
+ "NULL::Nullable(Int16) AS DEFERRABILITY" +
1018
+ " LIMIT 0" ;
1015
1019
return connection .createStatement ().executeQuery (sql );
1016
1020
} catch (Exception e ) {
1017
1021
throw ExceptionUtils .toSqlState (e );
@@ -1020,7 +1024,7 @@ public ResultSet getImportedKeys(String catalog, String schema, String table) th
1020
1024
1021
1025
@ Override
1022
1026
public ResultSet getExportedKeys (String catalog , String schema , String table ) throws SQLException {
1023
- //Return an empty result set with the required columns
1027
+ // ClickHouse has no notion of foreign key. This method should return empty resultset
1024
1028
log .warn ("getExportedKeys is not supported and may return invalid results" );
1025
1029
try {
1026
1030
return connection .createStatement ().executeQuery ("SELECT NULL::Nullable(String) AS PKTABLE_CAT, " +
@@ -1036,7 +1040,8 @@ public ResultSet getExportedKeys(String catalog, String schema, String table) th
1036
1040
"NULL::Nullable(Int16) AS DELETE_RULE, " +
1037
1041
"NULL::Nullable(String) AS FK_NAME, " +
1038
1042
"NULL::Nullable(String) AS PK_NAME, " +
1039
- "NULL::Nullable(Int16) AS DEFERRABILITY" );
1043
+ "NULL::Nullable(Int16) AS DEFERRABILITY" +
1044
+ " LIMIT 0" );
1040
1045
} catch (Exception e ) {
1041
1046
throw ExceptionUtils .toSqlState (e );
1042
1047
}
@@ -1060,7 +1065,8 @@ public ResultSet getCrossReference(String parentCatalog, String parentSchema, St
1060
1065
"NULL::Nullable(Int16) AS DELETE_RULE, " +
1061
1066
"NULL::Nullable(String) AS FK_NAME, " +
1062
1067
"NULL::Nullable(String) AS PK_NAME, " +
1063
- "NULL::Nullable(Int16) AS DEFERRABILITY" ;
1068
+ "NULL::Nullable(Int16) AS DEFERRABILITY" +
1069
+ " LIMIT 0" ;
1064
1070
return connection .createStatement ().executeQuery ("SELECT " + columns );
1065
1071
} catch (Exception e ) {
1066
1072
throw ExceptionUtils .toSqlState (e );
@@ -1150,7 +1156,8 @@ public ResultSet getIndexInfo(String catalog, String schema, String table, boole
1150
1156
"null::Nullable(String) AS ASC_OR_DESC, " +
1151
1157
"null::Nullable(Int64) AS CARDINALITY, " +
1152
1158
"null::Nullable(Int64) AS PAGES, " +
1153
- "null::Nullable(String) AS FILTER_CONDITION " ;
1159
+ "null::Nullable(String) AS FILTER_CONDITION " +
1160
+ " LIMIT 0" ;
1154
1161
return connection .createStatement ().executeQuery (sql );
1155
1162
} catch (Exception e ) {
1156
1163
throw ExceptionUtils .toSqlState (e );
@@ -1229,7 +1236,8 @@ public ResultSet getUDTs(String catalog, String schemaPattern, String typeNamePa
1229
1236
"NULL::Nullable(String) AS CLASS_NAME, " +
1230
1237
"NULL::Nullable(Int32) AS DATA_TYPE, " +
1231
1238
"NULL::Nullable(String) AS REMARKS, " +
1232
- "NULL::Nullable(Int16) AS BASE_TYPE" );
1239
+ "NULL::Nullable(Int16) AS BASE_TYPE" +
1240
+ " LIMIT 0" );
1233
1241
} catch (Exception e ) {
1234
1242
throw ExceptionUtils .toSqlState (e );
1235
1243
}
@@ -1274,7 +1282,8 @@ public ResultSet getSuperTypes(String catalog, String schemaPattern, String type
1274
1282
+ "NULL::Nullable(String) AS TYPE_NAME, "
1275
1283
+ "NULL::Nullable(String) AS SUPERTYPE_CAT, "
1276
1284
+ "NULL::Nullable(String) AS SUPERTYPE_SCHEM, "
1277
- + "NULL::Nullable(String) AS SUPERTYPE_NAME" );
1285
+ + "NULL::Nullable(String) AS SUPERTYPE_NAME" +
1286
+ " LIMIT 0" );
1278
1287
} catch (Exception e ) {
1279
1288
throw ExceptionUtils .toSqlState (e );
1280
1289
}
@@ -1290,7 +1299,8 @@ public ResultSet getSuperTables(String catalog, String schemaPattern, String tab
1290
1299
+ "NULL::Nullable(String) AS TABLE_CAT, "
1291
1300
+ "NULL::Nullable(String) AS TABLE_SCHEM, "
1292
1301
+ "NULL::Nullable(String) AS TABLE_NAME, "
1293
- + "NULL::Nullable(String) AS SUPERTABLE_NAME" );
1302
+ + "NULL::Nullable(String) AS SUPERTABLE_NAME" +
1303
+ " LIMIT 0" );
1294
1304
} catch (Exception e ) {
1295
1305
throw ExceptionUtils .toSqlState (e );
1296
1306
}
@@ -1323,7 +1333,8 @@ public ResultSet getAttributes(String catalog, String schemaPattern, String type
1323
1333
+ "NULL::Nullable(String) AS SCOPE_CATALOG, "
1324
1334
+ "NULL::Nullable(String) AS SCOPE_SCHEMA, "
1325
1335
+ "NULL::Nullable(String) AS SCOPE_TABLE, "
1326
- + "NULL::Nullable(Int16) AS SOURCE_DATA_TYPE" );
1336
+ + "NULL::Nullable(Int16) AS SOURCE_DATA_TYPE" +
1337
+ " LIMIT 0" );
1327
1338
} catch (Exception e ) {
1328
1339
throw ExceptionUtils .toSqlState (e );
1329
1340
}
0 commit comments