Commit d9d59ca6 authored by Dave Cramer's avatar Dave Cramer

patch for getTables to fix problems with backends before 7.3 by Kris Jurka

parent 58eeb82c
...@@ -1730,12 +1730,14 @@ public abstract class AbstractJdbc1DatabaseMetaData ...@@ -1730,12 +1730,14 @@ public abstract class AbstractJdbc1DatabaseMetaData
} else if (connection.haveMinimumServerVersion("7.1")) { } else if (connection.haveMinimumServerVersion("7.1")) {
sql = "SELECT NULL AS PROCEDURE_CAT, NULL AS PROCEDURE_SCHEM, p.proname AS PROCEDURE_NAME, NULL, NULL, NULL, d.description AS REMARKS, "+java.sql.DatabaseMetaData.procedureReturnsResult+" AS PROCEDURE_TYPE "+ sql = "SELECT NULL AS PROCEDURE_CAT, NULL AS PROCEDURE_SCHEM, p.proname AS PROCEDURE_NAME, NULL, NULL, NULL, d.description AS REMARKS, "+java.sql.DatabaseMetaData.procedureReturnsResult+" AS PROCEDURE_TYPE "+
" FROM pg_proc p "+ " FROM pg_proc p "+
" LEFT JOIN pg_description d ON (p.oid=d.objoid) "+ " LEFT JOIN pg_description d ON (p.oid=d.objoid) ";
" LEFT JOIN pg_class c ON (d.classoid=c.oid AND c.relname='pg_proc') "; if (connection.haveMinimumServerVersion("7.2")) {
if (procedureNamePattern != null) { sql += " LEFT JOIN pg_class c ON (d.classoid=c.oid AND c.relname='pg_proc') ";
sql += " WHERE p.proname LIKE '"+escapeQuotes(procedureNamePattern)+"' "; }
} if (procedureNamePattern != null) {
sql += " ORDER BY PROCEDURE_NAME "; sql += " WHERE p.proname LIKE '"+escapeQuotes(procedureNamePattern)+"' ";
}
sql += " ORDER BY PROCEDURE_NAME ";
} else { } else {
sql = "SELECT NULL AS PROCEDURE_CAT, NULL AS PROCEDURE_SCHEM, p.proname AS PROCEDURE_NAME, NULL, NULL, NULL, NULL AS REMARKS, "+java.sql.DatabaseMetaData.procedureReturnsResult+" AS PROCEDURE_TYPE "+ sql = "SELECT NULL AS PROCEDURE_CAT, NULL AS PROCEDURE_SCHEM, p.proname AS PROCEDURE_NAME, NULL, NULL, NULL, NULL AS REMARKS, "+java.sql.DatabaseMetaData.procedureReturnsResult+" AS PROCEDURE_TYPE "+
" FROM pg_proc p "; " FROM pg_proc p ";
...@@ -1995,9 +1997,6 @@ public abstract class AbstractJdbc1DatabaseMetaData ...@@ -1995,9 +1997,6 @@ public abstract class AbstractJdbc1DatabaseMetaData
if (schemaPattern != null && !"".equals(schemaPattern)) { if (schemaPattern != null && !"".equals(schemaPattern)) {
select += " AND n.nspname LIKE '"+escapeQuotes(schemaPattern)+"' "; select += " AND n.nspname LIKE '"+escapeQuotes(schemaPattern)+"' ";
} }
if (tableNamePattern != null) {
select += " AND c.relname LIKE '"+escapeQuotes(tableNamePattern)+"' ";
}
orderby = " ORDER BY TABLE_TYPE,TABLE_SCHEM,TABLE_NAME "; orderby = " ORDER BY TABLE_TYPE,TABLE_SCHEM,TABLE_NAME ";
} else { } else {
useSchemas = "NOSCHEMAS"; useSchemas = "NOSCHEMAS";
...@@ -2035,12 +2034,17 @@ public abstract class AbstractJdbc1DatabaseMetaData ...@@ -2035,12 +2034,17 @@ public abstract class AbstractJdbc1DatabaseMetaData
" ELSE NULL "+ " ELSE NULL "+
" END "; " END ";
orderby = " ORDER BY TABLE_TYPE,TABLE_NAME "; orderby = " ORDER BY TABLE_TYPE,TABLE_NAME ";
if (connection.haveMinimumServerVersion("7.1")) { if (connection.haveMinimumServerVersion("7.2")) {
select = "SELECT NULL AS TABLE_CAT, NULL AS TABLE_SCHEM, c.relname AS TABLE_NAME, "+tableType+" AS TABLE_TYPE, d.description AS REMARKS "+ select = "SELECT NULL AS TABLE_CAT, NULL AS TABLE_SCHEM, c.relname AS TABLE_NAME, "+tableType+" AS TABLE_TYPE, d.description AS REMARKS "+
" FROM pg_class c "+ " FROM pg_class c "+
" LEFT JOIN pg_description d ON (c.oid=d.objoid AND d.objsubid = 0) "+ " LEFT JOIN pg_description d ON (c.oid=d.objoid AND d.objsubid = 0) "+
" LEFT JOIN pg_class dc ON (d.classoid = dc.oid AND dc.relname='pg_class') "+ " LEFT JOIN pg_class dc ON (d.classoid = dc.oid AND dc.relname='pg_class') "+
" WHERE true "; " WHERE true ";
} else if (connection.haveMinimumServerVersion("7.1")) {
select = "SELECT NULL AS TABLE_CAT, NULL AS TABLE_SCHEM, c.relname AS TABLE_NAME, "+tableType+" AS TABLE_TYPE, d.description AS REMARKS "+
" FROM pg_class c "+
" LEFT JOIN pg_description d ON (c.oid=d.objoid) "+
" WHERE true ";
} else { } else {
select = "SELECT NULL AS TABLE_CAT, NULL AS TABLE_SCHEM, c.relname AS TABLE_NAME, "+tableType+" AS TABLE_TYPE, NULL AS REMARKS "+ select = "SELECT NULL AS TABLE_CAT, NULL AS TABLE_SCHEM, c.relname AS TABLE_NAME, "+tableType+" AS TABLE_TYPE, NULL AS REMARKS "+
" FROM pg_class c "+ " FROM pg_class c "+
...@@ -2051,6 +2055,9 @@ public abstract class AbstractJdbc1DatabaseMetaData ...@@ -2051,6 +2055,9 @@ public abstract class AbstractJdbc1DatabaseMetaData
if (types == null) { if (types == null) {
types = defaultTableTypes; types = defaultTableTypes;
} }
if (tableNamePattern != null) {
select += " AND c.relname LIKE '"+escapeQuotes(tableNamePattern)+"' ";
}
String sql = select; String sql = select;
sql += " AND (false "; sql += " AND (false ";
for (int i=0; i<types.length; i++) { for (int i=0; i<types.length; i++) {
...@@ -2288,7 +2295,7 @@ public abstract class AbstractJdbc1DatabaseMetaData ...@@ -2288,7 +2295,7 @@ public abstract class AbstractJdbc1DatabaseMetaData
if (schemaPattern != null && !"".equals(schemaPattern)) { if (schemaPattern != null && !"".equals(schemaPattern)) {
sql += " AND n.nspname LIKE '"+escapeQuotes(schemaPattern)+"' "; sql += " AND n.nspname LIKE '"+escapeQuotes(schemaPattern)+"' ";
} }
} else if (connection.haveMinimumServerVersion("7.1")) { } else if (connection.haveMinimumServerVersion("7.2")) {
sql = "SELECT NULL::text AS nspname,c.relname,a.attname,a.atttypid,a.attnotnull,a.atttypmod,a.attlen,a.attnum,def.adsrc,dsc.description "+ sql = "SELECT NULL::text AS nspname,c.relname,a.attname,a.atttypid,a.attnotnull,a.atttypmod,a.attlen,a.attnum,def.adsrc,dsc.description "+
" FROM pg_class c "+ " FROM pg_class c "+
" JOIN pg_attribute a ON (a.attrelid=c.oid) "+ " JOIN pg_attribute a ON (a.attrelid=c.oid) "+
...@@ -2296,6 +2303,13 @@ public abstract class AbstractJdbc1DatabaseMetaData ...@@ -2296,6 +2303,13 @@ public abstract class AbstractJdbc1DatabaseMetaData
" LEFT JOIN pg_description dsc ON (c.oid=dsc.objoid AND a.attnum = dsc.objsubid) "+ " LEFT JOIN pg_description dsc ON (c.oid=dsc.objoid AND a.attnum = dsc.objsubid) "+
" LEFT JOIN pg_class dc ON (dc.oid=dsc.classoid AND dc.relname='pg_class') "+ " LEFT JOIN pg_class dc ON (dc.oid=dsc.classoid AND dc.relname='pg_class') "+
" WHERE a.attnum > 0 "; " WHERE a.attnum > 0 ";
} else if (connection.haveMinimumServerVersion("7.1")) {
sql = "SELECT NULL::text AS nspname,c.relname,a.attname,a.atttypid,a.attnotnull,a.atttypmod,a.attlen,a.attnum,def.adsrc,dsc.description "+
" FROM pg_class c "+
" JOIN pg_attribute a ON (a.attrelid=c.oid) "+
" LEFT JOIN pg_attrdef def ON (a.attrelid=def.adrelid AND a.attnum = def.adnum) "+
" LEFT JOIN pg_description dsc ON (a.oid=dsc.objoid) "+
" WHERE a.attnum > 0 ";
} else { } else {
// if < 7.1 then don't get defaults or descriptions. // if < 7.1 then don't get defaults or descriptions.
sql = "SELECT NULL::text AS nspname,c.relname,a.attname,a.atttypid,a.attnotnull,a.atttypmod,a.attlen,a.attnum,NULL AS adsrc,NULL AS description "+ sql = "SELECT NULL::text AS nspname,c.relname,a.attname,a.atttypid,a.attnotnull,a.atttypmod,a.attlen,a.attnum,NULL AS adsrc,NULL AS description "+
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment