java.sql.ResultSetr;// ResultSet for the SQL query that we need to do
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 "+
Vectorv=newVector();// The new ResultSet tuple stuff
" FROM pg_catalog.pg_namespace n, pg_catalog.pg_proc p "+
" LEFT JOIN pg_catalog.pg_description d ON (p.oid=d.objoid) "+
r=connection.ExecSQL("select proname, proretset from pg_proc where proname like '"+procedureNamePattern.toLowerCase()+"' order by proname");
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 "+
while(r.next())
" 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') ";
byte[][]tuple=newbyte[8][0];
if(procedureNamePattern!=null){
sql+=" WHERE p.proname LIKE '"+escapeQuotes(procedureNamePattern.toLowerCase())+"' ";
tuple[0]=null;// Catalog name
}
tuple[1]=null;// Schema name
sql+=" ORDER BY PROCEDURE_NAME ";
tuple[2]=r.getBytes(1);// Procedure name
}else{
tuple[3]=tuple[4]=tuple[5]=null;// Reserved
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 "+
tuple[6]=null;// Remarks
" FROM pg_proc p ";
if(procedureNamePattern!=null){
if(r.getBoolean(2))
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
// These are the default tables, used when NULL is passed to getTables
// The choice of these provide the same behaviour as psql's \d
// The choice of these provide the same behaviour as psql's \d
// We don't use schemas, so we simply return a single schema name "".
Stringsql;
//
if(connection.haveMinimumServerVersion("7.3")){
Fieldf[]=newField[1];
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";
Vectorv=newVector();
}else{
byte[][]tuple=newbyte[1][0];
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");
" FROM pg_catalog.pg_namespace n, pg_catalog.pg_class c, pg_catalog.pg_user u "+
// This is taken direct from the psql source
" WHERE c.relnamespace = n.oid "+
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");
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 ";
Driver.debug("Serialize: initializing instance for type: "+type);
Driver.debug("Serialize: initializing instance for type: "+type);
tableName=toPostgreSQL(type);
tableName=toPostgreSQL(conn,type);
className=type;
className=type;
ourClass=Class.forName(className);
ourClass=Class.forName(className);
}
}
...
@@ -144,7 +144,14 @@ public class Serialize
...
@@ -144,7 +144,14 @@ public class Serialize
// Second check, the type must be a table
// Second check, the type must be a table
booleanstatus=false;
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+"'";