Skip to content

Commit

Permalink
fix: query replacement for JDBC getColumns() (#2855)
Browse files Browse the repository at this point in the history
* fix: query replacement for JDBC getColumns()

* fix: also replace query parameters
  • Loading branch information
olavloite authored Feb 8, 2025
1 parent 5984399 commit b1c4338
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,8 @@ private static String replaceGetColumnsQuery(String sql) {
return sql;
}
replacedSql += " WHERE TRUE " + sql.substring(startIndex).replace(") c WHERE true", "");
replacedSql =
replacedSql.replaceFirst("AND current_database\\(\\) = (:?'.*?'|\\?)", "AND TRUE");
return replacedSql
.replace(" AND n.nspname LIKE ", " AND TABLE_SCHEMA LIKE ")
.replace(" AND c.relname LIKE ", " AND TABLE_NAME LIKE ")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public class PgJdbcCatalog {
"SELECT n.nspname,c.relname,a.attname,a.atttypid,a.attnotnull OR (t.typtype = 'd' AND t.typnotnull) AS attnotnull,a.atttypmod,a.attlen,a.attnum,pg_catalog.pg_get_expr(def.adbin, def.adrelid) AS adsrc,dsc.description,t.typbasetype,t.typtype FROM pg_catalog.pg_namespace n JOIN pg_catalog.pg_class c ON (c.relnamespace = n.oid) JOIN pg_catalog.pg_attribute a ON (a.attrelid=c.oid) JOIN pg_catalog.pg_type t ON (a.atttypid = t.oid) LEFT JOIN pg_catalog.pg_attrdef def ON (a.attrelid=def.adrelid AND a.attnum = def.adnum) LEFT JOIN pg_catalog.pg_description dsc ON (c.oid=dsc.objoid AND a.attnum = dsc.objsubid) LEFT JOIN pg_catalog.pg_class dc ON (dc.oid=dsc.classoid AND dc.relname='pg_class') LEFT JOIN pg_catalog.pg_namespace dn ON (dc.relnamespace=dn.oid AND dn.nspname='pg_catalog')";

public static final String PG_JDBC_GET_COLUMNS_REPLACEMENT =
"SELECT TABLE_CATALOG as current_database, TABLE_CATALOG AS \"TABLE_CAT\", TABLE_SCHEMA AS nspname, TABLE_NAME AS relname, COLUMN_NAME AS attname, '' as typtype,\n"
"SELECT TABLE_CATALOG as current_database, TABLE_SCHEMA AS nspname, TABLE_NAME AS relname, COLUMN_NAME AS attname, '' as typtype,\n"
+ " CASE\n"
+ " WHEN SPANNER_TYPE = 'boolean' THEN 16\n"
+ " WHEN SPANNER_TYPE = 'boolean[]' THEN 1000\n"
Expand Down

0 comments on commit b1c4338

Please sign in to comment.