sql="SELECT NULL AS PROCEDURE_CAT, n.nspname AS PROCEDURE_SCHEM, p.proname AS PROCEDURE_NAME, NULL, NULL, NULL, d.description AS REMARKS, "+java.sql.DatabaseMetaData.procedureReturnsResult+" AS PROCEDURE_TYPE "+
" FROM pg_catalog.pg_namespace n, pg_catalog.pg_proc p "+
" LEFT JOIN pg_catalog.pg_description d ON (p.oid=d.objoid) "+
" LEFT JOIN pg_catalog.pg_class c ON (d.classoid=c.oid AND c.relname='pg_proc') "+
" LEFT JOIN pg_catalog.pg_namespace pn ON (c.relnamespace=pn.oid AND pn.nspname='pg_catalog') "+
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 "+
" 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(procedureNamePattern!=null){
sql+=" WHERE p.proname LIKE '"+escapeQuotes(procedureNamePattern.toLowerCase())+"' ";
}
sql+=" ORDER BY PROCEDURE_NAME ";
}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 "+
" FROM pg_proc p ";
if(procedureNamePattern!=null){
sql+=" WHERE p.proname LIKE '"+escapeQuotes(procedureNamePattern.toLowerCase())+"' ";
ht.put("SCHEMAS","c.relkind = 'r' AND n.nspname NOT LIKE 'pg\\\\_%'");
ht.put("NOSCHEMAS","c.relkind = 'r' AND c.relname NOT LIKE 'pg\\\\_%'");
ht=newHashtable();
tableTypeClauses.put("VIEW",ht);
ht.put("SCHEMAS","c.relkind = 'v' AND n.nspname <> 'pg_catalog'");
ht.put("NOSCHEMAS","c.relkind = 'v' AND c.relname NOT LIKE 'pg\\\\_%'");
ht=newHashtable();
tableTypeClauses.put("INDEX",ht);
ht.put("SCHEMAS","c.relkind = 'i' AND n.nspname NOT LIKE 'pg\\\\_%'");
ht.put("NOSCHEMAS","c.relkind = 'i' AND c.relname NOT LIKE 'pg\\\\_%'");
ht=newHashtable();
tableTypeClauses.put("SEQUENCE",ht);
ht.put("SCHEMAS","c.relkind = 'S'");
ht.put("NOSCHEMAS","c.relkind = 'S'");
ht=newHashtable();
tableTypeClauses.put("SYSTEM TABLE",ht);
ht.put("SCHEMAS","c.relkind = 'r' AND n.nspname = 'pg_catalog'");
ht.put("NOSCHEMAS","c.relkind = r' AND c.relname LIKE 'pg\\\\_%' AND c.relname NOT LIKE 'pg\\\\_toast\\\\_%' AND c.relname NOT LIKE 'pg\\\\_temp\\\\_%'");
ht=newHashtable();
tableTypeClauses.put("SYSTEM TOAST TABLE",ht);
ht.put("SCHEMAS","c.relkind = 'r' AND n.nspname = 'pg_toast'");
ht.put("NOSCHEMAS","c.relkind = r' AND c.relname LIKE 'pg\\\\_toast\\\\_%'");
ht=newHashtable();
tableTypeClauses.put("SYSTEM TOAST INDEX",ht);
ht.put("SCHEMAS","c.relkind = 'i' AND n.nspname = 'pg_toast'");
ht.put("NOSCHEMAS","c.relkind = 'i' AND c.relname LIKE 'pg\\\\_toast\\\\_%'");
ht=newHashtable();
tableTypeClauses.put("SYSTEM VIEW",ht);
ht.put("SCHEMAS","c.relkind = 'v' AND n.nspname = 'pg_catalog' ");
ht.put("NOSCHEMAS","c.relkind = 'v' AND c.relname LIKE 'pg\\\\_%'");
ht=newHashtable();
tableTypeClauses.put("SYSTEM INDEX",ht);
ht.put("SCHEMAS","c.relkind = 'i' AND n.nspname = 'pg_catalog'");
ht.put("NOSCHEMAS","c.relkind = 'v' AND c.relname LIKE 'pg\\\\_%' AND c.relname NOT LIKE 'pg\\\\_toast\\\\_%' AND c.relname NOT LIKE 'pg\\\\_temp\\\\_%'");
ht=newHashtable();
tableTypeClauses.put("TEMPORARY TABLE",ht);
ht.put("SCHEMAS","c.relkind = 'r' AND n.nspname LIKE 'pg\\\\_temp\\\\_%' ");
ht.put("NOSCHEMAS","c.relkind = 'r' AND c.relname LIKE 'pg\\\\_temp\\\\_%' ");
ht=newHashtable();
tableTypeClauses.put("TEMPORARY INDEX",ht);
ht.put("SCHEMAS","c.relkind = 'i' AND n.nspname LIKE 'pg\\\\_temp\\\\_%' ");
ht.put("NOSCHEMAS","c.relkind = 'i' AND c.relname LIKE 'pg\\\\_temp\\\\_%' ");
}
// This array contains the valid values for the types argument
// in getTables().
//
// Each supported type consists of it's name, and the sql where
// clause to retrieve that value.
//
// IMPORTANT: the query must be enclosed in ( )
privatestaticfinalStringgetTableTypes[][]={
{"TABLE","(relkind='r' and relhasrules='f' and relname !~ '^pg_' and relname !~ '^xinv')"},
{"VIEW","(relkind='v' and relname !~ '^pg_')"},
{"INDEX","(relkind='i' and relname !~ '^pg_')"},
{"SEQUENCE","(relkind='S' and relname !~ '^pg_')"},
{"SYSTEM TABLE","(relkind='r' and relname ~ '^pg_')"},
{"SYSTEM INDEX","(relkind='i' and relname ~ '^pg_')"}
};
// These are the default tables, used when NULL is passed to getTables
// The choice of these provide the same behaviour as psql's \d
sql="SELECT nspname AS TABLE_SCHEM FROM pg_catalog.pg_namespace WHERE nspname <> 'pg_toast' AND nspname NOT LIKE 'pg\\\\_temp\\\\_%' ORDER BY TABLE_SCHEM";
}else{
sql="SELECT ''::text AS TABLE_SCHEM ORDER BY TABLE_SCHEM";
java.sql.ResultSetr=connection.ExecSQL("SELECT relname, relacl FROM pg_class, pg_user WHERE ( relkind = 'r' OR relkind = 'i') and relname !~ '^pg_' and relname !~ '^xin[vx][0-9]+' and usesysid = relowner and relname like '"+table.toLowerCase()+"' ORDER BY relname");
java.sql.ResultSetr=connection.ExecSQL("SELECT relname, relacl FROM pg_class, pg_user WHERE ( relkind = 'r' OR relkind = 'i') and relname !~ '^pg_' and relname !~ '^xin[vx][0-9]+' and usesysid = relowner and relname like '"+tableNamePattern.toLowerCase()+"' ORDER BY relname");
select="SELECT NULL AS TABLE_CAT, n.nspname AS TABLE_SCHEM, ";
from=" FROM pg_catalog.pg_namespace n, pg_catalog.pg_class ct, pg_catalog.pg_class ci, pg_catalog.pg_index i, pg_catalog.pg_attribute a, pg_catalog.pg_am am ";
where=" AND n.oid = ct.relnamespace ";
if(schema!=null&&!"".equals(schema)){
where+=" AND n.nspname = '"+escapeQuotes(schema.toLowerCase())+"' ";
}
}else{
select="SELECT NULL AS TABLE_CAT, NULL AS TABLE_SCHEM, ";
from=" FROM pg_class ct, pg_class ci, pg_index i, pg_attribute a, pg_am am ";
}
returnconnection.getResultSet(null,f,v,"OK",1);
Stringsql=select+
" ct.relname AS TABLE_NAME, NOT i.indisunique AS NON_UNIQUE, NULL AS INDEX_QUALIFIER, ci.relname AS INDEX_NAME, "+
" CASE i.indisclustered "+
" WHEN true THEN "+java.sql.DatabaseMetaData.tableIndexClustered+
" ELSE CASE am.amname "+
" WHEN 'hash' THEN "+java.sql.DatabaseMetaData.tableIndexHashed+
Driver.debug("Serialize: initializing instance for type: "+type);
tableName=toPostgreSQL(type);
tableName=toPostgreSQL(conn,type);
className=type;
ourClass=Class.forName(className);
}
...
...
@@ -144,7 +144,14 @@ public class Serialize
// Second check, the type must be a table
booleanstatus=false;
ResultSetrs=((org.postgresql.jdbc1.AbstractJdbc1Connection)conn).ExecSQL("select typname from pg_type,pg_class where typname=relname and typname='"+tableName+"'");
sql="SELECT 1 FROM pg_catalog.pg_type t, pg_catalog.pg_class c WHERE t.typrelid=c.oid AND c.relkind='r' AND t.typname='"+tableName+"' AND pg_table_is_visible(c.oid) ";
}else{
sql="SELECT 1 FROM pg_type t, pg_class c WHERE t.typrelid=c.oid AND c.relkind='r' AND t.typname='"+tableName+"'";