returnconnection.createStatement().executeQuery("SELECT '' as TABLE_CAT,'' AS TABLE_SCHEM,relname AS TABLE_NAME,'TABLE' AS TABLE_TYPE,'' AS REMARKS FROM pg_class WHERE relkind = 'r' and relname !~ '^pg_' and relname !~ '^Inv' and relname ~ '"+tableNamePattern+"' ORDER BY TABLE_NAME");
// the field descriptors for the new ResultSet
Fieldf[]=newField[5];
ResultSetr;// ResultSet for the SQL query that we need to do
Vectorv=newVector();// The new ResultSet tuple stuff
r=connection.ExecSQL("select a.oid,c.relname,a.attname,a.atttypid,a.attnum,a.attnotnull,a.attlen from pg_class c, pg_attribute a where a.attrelid=c.oid and c.relname like '"+tableNamePattern+"' and a.attname like '"+columnNamePattern+"' and a.attnum>0 order by c.relname,a.attnum");
while(r.next()){
byte[][]tuple=newbyte[18][0];
Stringname=r.getString(1);
Stringremarks=newString("no remarks");
// Fetch the description for the table (if any)
ResultSetdr=connection.ExecSQL("select description from pg_description where objoid="+r.getInt(1));
if(dr.getTupleCount()==1){
dr.next();
remarks=dr.getString(1);
}
dr.close();
tuple[0]="".getBytes();// Catalog name
tuple[1]="".getBytes();// Schema name
tuple[2]=r.getString(2).getBytes();// Table name
tuple[3]=r.getString(3).getBytes();// Column name
dr=connection.ExecSQL("select typname from pg_type where oid = "+r.getString(4));
dr.next();
Stringtypname=dr.getString(1);
dr.close();
tuple[4]=Integer.toString(Field.getSQLType(typname)).getBytes();// Data type
tuple[5]=typname.getBytes();// Type name
tuple[6]=r.getString(7).getBytes();// Column size
tuple[7]=null;// Buffer length
tuple[8]="0".getBytes();// Decimal Digits - how to get this?
tuple[9]="10".getBytes();// Num Prec Radix - assume decimal
// tuple[10] is below
tuple[11]=remarks.getBytes();// Remarks
tuple[12]=null;// column default
tuple[13]=null;// sql data type (unused)
tuple[14]=null;// sql datetime sub (unused)
tuple[15]=tuple[6];// char octet length
tuple[16]=r.getString(5).getBytes();// ordinal position
//f[0] = new Field(connection,new String("TABLE_CAT"),iVarcharOid,32);
//f[1] = new Field(connection,new String("TABLE_SCHEM"),iVarcharOid,32);
//f[2] = new Field(connection,new String("TABLE_NAME"),iVarcharOid,32);
//f[3] = new Field(connection,new String("COLUMN_NAME"),iVarcharOid,32);
//f[4] = new Field(connection,new String("GRANTOR"),iVarcharOid,32);
//f[5] = new Field(connection,new String("GRANTEE"),iVarcharOid,32);
//f[6] = new Field(connection,new String("PRIVILEGE"),iVarcharOid,32);
//f[7] = new Field(connection,new String("IS_GRANTABLE"),iVarcharOid,32);
//
//// This is taken direct from the psql source
//ResultSet r = 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 ORDER BY relname");
//while(r.next()) {
//byte[][] tuple = new byte[8][0];
//tuple[0] = tuple[1]= "default".getBytes();
//
//v.addElement(tuple);
//}
//
//return new ResultSet(connection,f,v,"OK",1);
}
/**
...
...
@@ -1722,10 +2020,24 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
* @param nullable include columns that are nullable?
* @return ResultSet each row is a column description
*/
// Implementation note: This is required for Borland's JBuilder to work