Skip to content

Commit

Permalink
fix statement.executeUpdate
Browse files Browse the repository at this point in the history
  • Loading branch information
chernser committed Dec 20, 2024
1 parent 7f3e087 commit 7d74e68
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -359,11 +359,11 @@ public static void afterSuite() {
clickhouseContainer.stop();
}

// if (isCloud) {
// if (!runQuery("DROP DATABASE IF EXISTS " + database)) {
// LOGGER.warn("Failed to drop database for testing.");
// }
// }
if (isCloud) {
if (!runQuery("DROP DATABASE IF EXISTS " + database)) {
LOGGER.warn("Failed to drop database for testing.");
}
}
}

public static String getDatabase() {
Expand Down
3 changes: 2 additions & 1 deletion jdbc-v2/src/main/java/com/clickhouse/jdbc/StatementImpl.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.clickhouse.jdbc;

import com.clickhouse.client.api.data_formats.ClickHouseBinaryFormatReader;
import com.clickhouse.client.api.internal.ServerSettings;
import com.clickhouse.client.api.metrics.OperationMetrics;
import com.clickhouse.client.api.metrics.ServerMetrics;
import com.clickhouse.client.api.query.QueryResponse;
Expand Down Expand Up @@ -190,7 +191,7 @@ public int executeUpdate(String sql, QuerySettings settings) throws SQLException
}

QuerySettings mergedSettings = QuerySettings.merge(connection.getDefaultQuerySettings(), settings);

mergedSettings.serverSetting(ServerSettings.WAIT_END_OF_QUERY, "1");
lastSql = parseJdbcEscapeSyntax(sql);
try (QueryResponse response = queryTimeout == 0 ? connection.client.query(lastSql, mergedSettings).get()
: connection.client.query(lastSql, mergedSettings).get(queryTimeout, TimeUnit.SECONDS)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,6 @@ public ResultSet getProcedures(String catalog, String schemaPattern, String proc
"0 AS FUNCTION_TYPE, " +
"'' AS SPECIFIC_NAME " +
"LIMIT 0";
log.info("getProcedures: {}", sql);
try {
return connection.createStatement().executeQuery(sql);
} catch (Exception e) {
Expand Down Expand Up @@ -857,8 +856,6 @@ public ResultSet getColumns(String catalog, String schemaPattern, String tableNa
" AND table LIKE '" + (tableNamePattern == null ? "%" : tableNamePattern) + "'" +
" AND name LIKE '" + (columnNamePattern == null ? "%" : columnNamePattern) + "'" +
" ORDER BY TABLE_SCHEM, TABLE_NAME, ORDINAL_POSITION";
log.info("getColumns: {}", sql);

try {
return connection.createStatement().executeQuery(sql);
} catch (Exception e) {
Expand Down Expand Up @@ -1294,8 +1291,6 @@ public ResultSet getFunctions(String catalog, String schemaPattern, String funct
"name AS SPECIFIC_NAME " +
"FROM system.functions " +
"WHERE name LIKE '" + (functionNamePattern == null ? "%" : functionNamePattern) + "'";
log.info("getFunctions: " + sql);

try {
return connection.createStatement().executeQuery(sql);
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ public Connection getJdbcConnection(Properties properties) throws SQLException {
Properties info = new Properties();
info.setProperty("user", "default");
info.setProperty("password", ClickHouseServerForTest.getPassword());
if (info.getProperty(ClientConfigProperties.PASSWORD.getKey()).isEmpty()) {
LOGGER.error("password is empty!!");
}

LOGGER.info("Connecting to " + getEndpointString() + " database: " + ClickHouseServerForTest.getDatabase() );
if (properties != null) {
info.putAll(properties);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.clickhouse.jdbc.metadata;

import com.clickhouse.client.ClickHouseServerForTest;
import com.clickhouse.client.api.command.CommandResponse;
import com.clickhouse.data.ClickHouseVersion;
import com.clickhouse.jdbc.JdbcIntegrationTest;
import com.clickhouse.jdbc.internal.ClientInfoProperties;
import com.clickhouse.jdbc.internal.DriverProperties;
Expand Down Expand Up @@ -52,7 +54,7 @@ public void testGetColumns() throws Exception {
conn.createStatement().execute(createTableStmt.toString());

DatabaseMetaData dbmd = conn.getMetaData();
ResultSet rs = dbmd.getColumns("default", null, tableName, null);
ResultSet rs = dbmd.getColumns(ClickHouseServerForTest.getDatabase(), null, tableName, null);

int count = 0;
while (rs.next()) {
Expand All @@ -61,7 +63,7 @@ public void testGetColumns() throws Exception {
System.out.println("Column name: " + columnName + " colIndex: " + colIndex);
assertTrue(columnNames.contains(columnName));
assertEquals(rs.getString("TABLE_CAT"), "");
assertEquals(rs.getString("TABLE_SCHEM"), "default");
assertEquals(rs.getString("TABLE_SCHEM"), ClickHouseServerForTest.getDatabase());
assertEquals(rs.getString("TABLE_NAME"), tableName);
assertEquals(rs.getString("TYPE_NAME"), columnTypeNames.get(colIndex));
assertEquals(rs.getInt("DATA_TYPE"), columnJDBCDataTypes.get(colIndex));
Expand All @@ -86,7 +88,7 @@ public void testGetColumns() throws Exception {
}
count++;
}
Assert.assertEquals(count, columnNames.size());
Assert.assertEquals(count, columnNames.size(), "result set is empty");
}
}

Expand Down Expand Up @@ -239,6 +241,10 @@ public void testGetTypeInfo() throws Exception {

@Test(groups = { "integration" })
public void testGetFunctions() throws Exception {
if (ClickHouseVersion.of(getServerVersion()).check("(,23.8]")) {
return; // Illegal column Int8 of argument of function concat. (ILLEGAL_COLUMN) TODO: fix in JDBC
}

try (Connection conn = getJdbcConnection()) {
DatabaseMetaData dbmd = conn.getMetaData();
try (ResultSet rs = dbmd.getFunctions(null, null, "mapContains")) {
Expand Down

0 comments on commit 7d74e68

Please sign in to comment.