Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update SHOW and DESCRIBE queries. #85

Merged
merged 2 commits into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/main/java/org/opensearch/jdbc/DatabaseMetaDataImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -671,12 +671,12 @@ public ResultSet getProcedureColumns(String catalog, String schemaPattern, Strin

@Override
public ResultSet getTables(String catalog, String schemaPattern, String tableNamePattern, String[] types) throws SQLException {
// TODO - when server plugin supports PreparedStatement fully, implement this as a preparedStatment with params
// TODO - when server plugin supports PreparedStatement fully, implement this as a preparedStatement with params
log.debug(() -> logMessage("getTables(%s, %s, %s, %s)",
catalog, schemaPattern, tableNamePattern, Arrays.toString(types)));

PreparedStatement pst = connection.prepareStatement("SHOW TABLES LIKE " +
(tableNamePattern == null ? "%" : tableNamePattern));
PreparedStatement pst = connection.prepareStatement("SHOW TABLES LIKE '" +
(tableNamePattern == null ? "%" : tableNamePattern) + "'");

ResultSet resultSet = pst.executeQuery();

Expand Down Expand Up @@ -1207,8 +1207,8 @@ static class ColumnMetadataStatement extends PreparedStatementImpl {
ColumnMetadataStatement(ConnectionImpl connection, String tableNamePattern, String columnNamePattern, Logger log)
throws SQLException {
// TODO - once sql plugin supports PreparedStatement fully, do this through a preparedStatement with params
super(connection, "DESCRIBE TABLES LIKE " + tableNamePattern +
(columnNamePattern != null ? (" COLUMNS LIKE " + columnNamePattern) : ""),
super(connection, "DESCRIBE TABLES LIKE '" + tableNamePattern +
(columnNamePattern != null ? ("' COLUMNS LIKE '" + columnNamePattern + "'") : "'"),
log);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ void testGetColumnsWithoutColumnNamePattern() throws Exception {
Connection con = getMockConnection();

ColumnMetadataStatement stmt = new ColumnMetadataStatement((ConnectionImpl)con, "TABLE_%", null, NoOpLogger.INSTANCE);
assertEquals("DESCRIBE TABLES LIKE TABLE_%", stmt.sql);
assertEquals("DESCRIBE TABLES LIKE 'TABLE_%'", stmt.sql);
assertDoesNotThrow(stmt::close);
}

Expand All @@ -373,7 +373,7 @@ void testGetColumnsWithColumnNamePattern() throws Exception {
Connection con = getMockConnection();

ColumnMetadataStatement stmt = new ColumnMetadataStatement((ConnectionImpl)con, "TABLE_%", "COLUMN_%", NoOpLogger.INSTANCE);
assertEquals("DESCRIBE TABLES LIKE TABLE_% COLUMNS LIKE COLUMN_%", stmt.sql);
assertEquals("DESCRIBE TABLES LIKE 'TABLE_%' COLUMNS LIKE 'COLUMN_%'", stmt.sql);
assertDoesNotThrow(stmt::close);
}

Expand Down