@@ -674,7 +674,7 @@ public ResultSet getTables(String catalog, String schemaPattern, String tableNam
674674 // TODO: when switch between catalog and schema is implemented, then TABLE_SCHEMA and TABLE_CAT should be populated accordingly
675675// String commentColumn = connection.getServerVersion().check("[21.6,)") ? "t.comment" : "''";
676676 // TODO: handle useCatalogs == true and return schema catalog name
677- String catalogPlaceholder = useCatalogs ? "'local' " : "" ;
677+ String catalogPlaceholder = useCatalogs ? "'local' " : "'' " ;
678678
679679 String sql = "SELECT " +
680680 catalogPlaceholder + " AS TABLE_CAT, " +
@@ -712,7 +712,7 @@ public ResultSet getTables(String catalog, String schemaPattern, String tableNam
712712 @ Override
713713 public ResultSet getSchemas () throws SQLException {
714714 // TODO: handle useCatalogs == true and return schema catalog name
715- String catalogPlaceholder = useCatalogs ? "'local' " : "" ;
715+ String catalogPlaceholder = useCatalogs ? "'local' " : "'' " ;
716716 return connection .createStatement ().executeQuery ("SELECT name AS TABLE_SCHEM, " + catalogPlaceholder + " AS TABLE_CATALOG FROM system.databases ORDER BY name" );
717717 }
718718
@@ -741,28 +741,27 @@ public ResultSet getTableTypes() throws SQLException {
741741 public ResultSet getColumns (String catalog , String schemaPattern , String tableNamePattern , String columnNamePattern ) throws SQLException {
742742 //TODO: Best way to convert type to JDBC data type
743743 // TODO: handle useCatalogs == true and return schema catalog name
744- String catalogPlaceholder = useCatalogs ? "'local' " : "" ;
744+ String catalogPlaceholder = useCatalogs ? "'local' " : "'' " ;
745745
746746 String sql = "SELECT " +
747747 catalogPlaceholder + " AS TABLE_CAT, " +
748748 "database AS TABLE_SCHEM, " +
749749 "table AS TABLE_NAME, " +
750750 "name AS COLUMN_NAME, " +
751751 JdbcUtils .generateSqlTypeEnum ("system.columns.type" ) + " AS DATA_TYPE, " +
752- "type AS TYPE_NAME, " +
753- JdbcUtils .generateSqlTypeSizes ("system.columns.type" ) + " AS COLUMN_SIZE, " +
754-
752+ "replaceRegexpOne(type, '^Nullable\\ (([\\ \\ w ,\\ \\ )\\ \\ (]+)\\ )$', '\\ \\ 1') AS TYPE_NAME, " +
753+ JdbcUtils .generateSqlTypeSizes ("system.columns.type" ) + " AS COLUMN_SIZE, " +
755754 "toInt32(0) AS BUFFER_LENGTH, " +
756- "if (numeric_scale IS NOT NULL, numeric_scale, 0 ) as DECIMAL_DIGITS, " +
757- "toInt32(system.columns. numeric_precision_radix) AS NUM_PREC_RADIX, " +
755+ "IF (numeric_scale == 0, NULL, numeric_scale) as DECIMAL_DIGITS, " +
756+ "toInt32(numeric_precision_radix) AS NUM_PREC_RADIX, " +
758757 "toInt32(position(type, 'Nullable(') >= 1 ?" + java .sql .DatabaseMetaData .typeNullable + " : " + java .sql .DatabaseMetaData .typeNoNulls + ") as NULLABLE, " +
759758 "system.columns.comment AS REMARKS, " +
760759 "system.columns.default_expression AS COLUMN_DEF, " +
761760 "toInt32(0) AS SQL_DATA_TYPE, " +
762761 "toInt32(0) AS SQL_DATETIME_SUB, " +
763762 "character_octet_length AS CHAR_OCTET_LENGTH, " +
764763 "toInt32(system.columns.position) AS ORDINAL_POSITION, " +
765- "position(type, 'Nullable( ') >= 1 ? 'YES' : 'NO' AS IS_NULLABLE," +
764+ "position(upper( type) , 'NULLABLE ') >= 1 ? 'YES' : 'NO' AS IS_NULLABLE," +
766765 "NULL AS SCOPE_CATALOG, " +
767766 "NULL AS SCOPE_SCHEMA, " +
768767 "NULL AS SCOPE_TABLE, " +
@@ -773,7 +772,8 @@ public ResultSet getColumns(String catalog, String schemaPattern, String tableNa
773772 " WHERE database LIKE '" + (schemaPattern == null ? "%" : schemaPattern ) + "'" +
774773 " AND database LIKE '" + (catalog == null ? "%" : catalog ) + "'" +
775774 " AND table LIKE '" + (tableNamePattern == null ? "%" : tableNamePattern ) + "'" +
776- " AND name LIKE '" + (columnNamePattern == null ? "%" : columnNamePattern ) + "'" ;
775+ " AND name LIKE '" + (columnNamePattern == null ? "%" : columnNamePattern ) + "'" +
776+ " ORDER BY TABLE_SCHEM, TABLE_NAME, ORDINAL_POSITION" ;
777777 log .info ("getColumns: {}" , sql );
778778
779779 return connection .createStatement ().executeQuery (sql );
@@ -1035,7 +1035,7 @@ public RowIdLifetime getRowIdLifetime() throws SQLException {
10351035 @ Override
10361036 public ResultSet getSchemas (String catalog , String schemaPattern ) throws SQLException {
10371037 // TODO: handle useCatalogs == true and return schema catalog name
1038- String catalogPlaceholder = useCatalogs ? "'local' " : "" ;
1038+ String catalogPlaceholder = useCatalogs ? "'local' " : "'' " ;
10391039 return connection .createStatement ().executeQuery ("SELECT name AS TABLE_SCHEM, " + catalogPlaceholder + " AS TABLE_CATALOG FROM system.databases " +
10401040 "WHERE name LIKE '" + (schemaPattern == null ? "%" : schemaPattern ) + "'" );
10411041 }
0 commit comments