Skip to content

Commit e61519f

Browse files
committed
implemented getting functions
1 parent 91de2d3 commit e61519f

File tree

2 files changed

+77
-17
lines changed

2 files changed

+77
-17
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public ResultSet executeQuery(String sql) throws SQLException {
113113
return executeQuery(sql, new QuerySettings().setDatabase(schema));
114114
}
115115

116-
public ResultSet executeQuery(String sql, QuerySettings settings) throws SQLException {
116+
public ResultSetImpl executeQuery(String sql, QuerySettings settings) throws SQLException {
117117
checkClosed();
118118
QuerySettings mergedSettings = QuerySettings.merge(connection.getDefaultQuerySettings(), settings);
119119

@@ -143,6 +143,7 @@ public int executeUpdate(String sql) throws SQLException {
143143
}
144144

145145
public int executeUpdate(String sql, QuerySettings settings) throws SQLException {
146+
// TODO: close current result set?
146147
checkClosed();
147148

148149
if (parseStatementType(sql) == StatementType.SELECT) {
@@ -255,9 +256,8 @@ private boolean execute(String sql, QuerySettings settings) throws SQLException
255256
StatementType type = parseStatementType(sql);
256257

257258
if (type == StatementType.SELECT) {
258-
try (ResultSet rs = executeQuery(sql, settings)) {
259-
return true;
260-
}
259+
executeQuery(sql, settings); // keep open to allow getResultSet()
260+
return true;
261261
} else if(type == StatementType.SET) {
262262
//SET ROLE
263263
List<String> tokens = JdbcUtils.tokenizeSQL(sql);

jdbc-v2/src/main/java/com/clickhouse/jdbc/metadata/DatabaseMetaData.java

Lines changed: 73 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ public boolean supportsSchemasInDataManipulation() throws SQLException {
398398

399399
@Override
400400
public boolean supportsSchemasInProcedureCalls() throws SQLException {
401-
return true;
401+
return false;
402402
}
403403

404404
@Override
@@ -658,14 +658,43 @@ public boolean dataDefinitionIgnoredInTransactions() throws SQLException {
658658

659659
@Override
660660
public ResultSet getProcedures(String catalog, String schemaPattern, String procedureNamePattern) throws SQLException {
661-
//TODO: Drill into this
662-
throw new RuntimeException("Not implemented");
661+
String sql = "SELECT " +
662+
"'' AS FUNCTION_CAT, " +
663+
"'' AS FUNCTION_SCHEM, " +
664+
"'' AS FUNCTION_NAME, " +
665+
"'' AS REMARKS, " +
666+
"0 AS FUNCTION_TYPE, " +
667+
"'' AS SPECIFIC_NAME " +
668+
"LIMIT 0";
669+
log.info("getProcedures: {}", sql);
670+
return connection.createStatement().executeQuery(sql);
663671
}
664672

665673
@Override
666674
public ResultSet getProcedureColumns(String catalog, String schemaPattern, String procedureNamePattern, String columnNamePattern) throws SQLException {
667-
//TODO: Drill into this
668-
throw new RuntimeException("Not implemented");
675+
String sql = "SELECT " +
676+
"'' AS PROCEDURE_CAT, " +
677+
"'' AS PROCEDURE_SCHEM, " +
678+
"'' AS PROCEDURE_NAME, " +
679+
"'' AS COLUMN_NAME, " +
680+
"0 AS COLUMN_TYPE, " +
681+
"0 AS DATA_TYPE, " +
682+
"'' AS TYPE_NAME, " +
683+
"0 AS PRECISION, " +
684+
"0 AS LENGTH, " +
685+
"0 AS SCALE, " +
686+
"0 AS RADIX, " +
687+
"0 AS NULLABLE, " +
688+
"'' AS REMARKS, " +
689+
"'' AS COLUMN_DEF, " +
690+
"0 AS SQL_DATA_TYPE, " +
691+
"0 AS SQL_DATETIME_SUB, " +
692+
"0 AS CHAR_OCTET_LENGTH, " +
693+
"0 AS ORDINAL_POSITION, " +
694+
"'' AS IS_NULLABLE, " +
695+
"'' AS SPECIFIC_NAME " +
696+
"LIMIT 0";
697+
return connection.createStatement().executeQuery(sql);
669698
}
670699

671700
/**
@@ -1079,27 +1108,58 @@ public ResultSet getFunctions(String catalog, String schemaPattern, String funct
10791108
"NULL AS FUNCTION_CAT, " +
10801109
"NULL AS FUNCTION_SCHEM, " +
10811110
"name AS FUNCTION_NAME, " +
1082-
"description AS REMARKS, " +
1111+
"concat(description, '(', origin, ')') AS REMARKS, " +
10831112
java.sql.DatabaseMetaData.functionResultUnknown + " AS FUNCTION_TYPE, " +
10841113
"name AS SPECIFIC_NAME " +
10851114
"FROM system.functions " +
10861115
"WHERE name LIKE '" + (functionNamePattern == null ? "%" : functionNamePattern) + "'";
1087-
System.out.println("getFunctions: " + sql);
1116+
log.info("getFunctions: " + sql);
10881117
return connection.createStatement().executeQuery(sql);
10891118
}
10901119

10911120
@Override
10921121
public ResultSet getFunctionColumns(String catalog, String schemaPattern, String functionNamePattern, String columnNamePattern) throws SQLException {
1093-
//Return an empty result set with the required columns
1094-
log.warn("getFunctionColumns is not supported and may return invalid results");
1095-
return connection.createStatement().executeQuery("SELECT NULL AS FUNCTION_CAT, NULL AS FUNCTION_SCHEM, NULL AS FUNCTION_NAME, NULL AS COLUMN_NAME, NULL AS COLUMN_TYPE, NULL AS DATA_TYPE, NULL AS TYPE_NAME, NULL AS PRECISION, NULL AS LENGTH, NULL AS SCALE, NULL AS RADIX, NULL AS NULLABLE, NULL AS REMARKS, NULL AS CHAR_OCTET_LENGTH, NULL AS ORDINAL_POSITION, NULL AS IS_NULLABLE, NULL AS SPECIFIC_NAME");
1122+
String sql = "SELECT " +
1123+
"'' AS FUNCTION_CAT, " +
1124+
"'' AS FUNCTION_SCHEM, " +
1125+
"'' AS FUNCTION_NAME, " +
1126+
"'' AS COLUMN_NAME, " +
1127+
"0 AS COLUMN_TYPE, " +
1128+
"0 AS DATA_TYPE, " +
1129+
"'' AS TYPE_NAME, " +
1130+
"0 AS PRECISION, " +
1131+
"0 AS LENGTH, " +
1132+
"0 AS SCALE, " +
1133+
"0 AS RADIX, " +
1134+
"0 AS NULLABLE, " +
1135+
"'' AS REMARKS, " +
1136+
"0 AS CHAR_OCTET_LENGTH, " +
1137+
"0 AS ORDINAL_POSITION, " +
1138+
"0 AS IS_NULLABLE, " +
1139+
"'' AS SPECIFIC_NAME " +
1140+
"LIMIT 0";
1141+
1142+
return connection.createStatement().executeQuery(sql);
10961143
}
10971144

10981145
@Override
10991146
public ResultSet getPseudoColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) throws SQLException {
1100-
//Return an empty result set with the required columns
1101-
log.warn("getPseudoColumns is not supported and may return invalid results");
1102-
return connection.createStatement().executeQuery("SELECT NULL AS TABLE_CAT, NULL AS TABLE_SCHEM, NULL AS TABLE_NAME, NULL AS COLUMN_NAME, NULL AS DATA_TYPE, NULL AS COLUMN_SIZE, NULL AS DECIMAL_DIGITS, NULL AS NUM_PREC_RADIX, NULL AS COLUMN_USAGE, NULL AS REMARKS, NULL AS CHAR_OCTET_LENGTH, NULL AS IS_NULLABLE");
1147+
String sql = "SELECT " +
1148+
"'' AS TABLE_CAT, " +
1149+
"'' AS TABLE_SCHEM, " +
1150+
"'' AS TABLE_NAME, " +
1151+
"'' AS COLUMN_NAME, " +
1152+
"0 AS DATA_TYPE, " +
1153+
"0 AS COLUMN_SIZE, " +
1154+
"0 AS DECIMAL_DIGITS, " +
1155+
"0 AS NUM_PREC_RADIX, " +
1156+
"'' AS COLUMN_USAGE, " +
1157+
"'' AS REMARKS, " +
1158+
"0 AS CHAR_OCTET_LENGTH, " +
1159+
"'' AS IS_NULLABLE " +
1160+
" LIMIT 0";
1161+
1162+
return connection.createStatement().executeQuery(sql);
11031163
}
11041164

11051165
@Override

0 commit comments

Comments
 (0)