@ -15,7 +15,7 @@ import org.postgresql.util.PSQLException;
/ *
* This class provides information about the database as a whole .
*
* $Id : DatabaseMetaData . java , v 1 . 46 2001 / 11 / 19 22 : 33 : 39 momjian Exp $
* $Id : DatabaseMetaData . java , v 1 . 47 2001 / 11 / 19 23 : 16 : 46 momjian Exp $
*
* < p > Many of the methods here return lists of information in ResultSets . You
* can use the normal ResultSet methods such as getString and getInt to
@ -88,7 +88,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
public String getURL ( ) throws SQLException
{
String url = connection . getURL ( ) ;
Driver . debug ( "getURL " + url ) ;
Driver . debug ( "getURL " + url ) ;
return url ;
}
@ -101,7 +101,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
public String getUserName ( ) throws SQLException
{
String userName = connection . getUserName ( ) ;
Driver . debug ( "getUserName " + userName ) ;
Driver . debug ( "getUserName " + userName ) ;
return userName ;
}
@ -114,7 +114,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
public boolean isReadOnly ( ) throws SQLException
{
boolean isReadOnly = connection . isReadOnly ( ) ;
Driver . debug ( "isReadOnly " + isReadOnly ) ;
Driver . debug ( "isReadOnly " + isReadOnly ) ;
return isReadOnly ;
}
@ -164,7 +164,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
public boolean nullsAreSortedAtEnd ( ) throws SQLException
{
boolean nullsAreSortedAtEnd = ! connection . haveMinimumServerVersion ( "7.2" ) ;
Driver . debug ( "nullsAreSortedAtEnd " + nullsAreSortedAtEnd ) ;
Driver . debug ( "nullsAreSortedAtEnd " + nullsAreSortedAtEnd ) ;
return nullsAreSortedAtEnd ;
}
@ -218,7 +218,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
public String getDriverVersion ( ) throws SQLException
{
String driverVersion = connection . this_driver . getVersion ( ) ;
Driver . debug ( "getDriverVersion " + driverVersion ) ;
Driver . debug ( "getDriverVersion " + driverVersion ) ;
return driverVersion ;
}
@ -230,7 +230,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
public int getDriverMajorVersion ( )
{
int majorVersion = connection . this_driver . getMajorVersion ( ) ;
Driver . debug ( "getMajorVersion " + majorVersion ) ;
Driver . debug ( "getMajorVersion " + majorVersion ) ;
return majorVersion ;
}
@ -242,7 +242,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
public int getDriverMinorVersion ( )
{
int minorVersion = connection . this_driver . getMinorVersion ( ) ;
Driver . debug ( "getMinorVersion " + minorVersion ) ;
Driver . debug ( "getMinorVersion " + minorVersion ) ;
return minorVersion ;
}
@ -298,7 +298,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
* /
public boolean storesUpperCaseIdentifiers ( ) throws SQLException
{
Driver . debug ( "storesUpperCaseIdentifiers " + false ) ;
Driver . debug ( "storesUpperCaseIdentifiers " + false ) ;
return false ;
}
@ -622,7 +622,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
public boolean supportsGroupByUnrelated ( ) throws SQLException
{
boolean supportsGroupByUnrelated = connection . haveMinimumServerVersion ( "6.4" ) ;
Driver . debug ( "supportsGroupByUnrelated " + supportsGroupByUnrelated ) ;
Driver . debug ( "supportsGroupByUnrelated " + supportsGroupByUnrelated ) ;
return supportsGroupByUnrelated ;
}
@ -2245,27 +2245,28 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
if ( tableNamePattern = = null )
tableNamePattern = "%" ;
f [ 0 ] = new Field ( connection , "TABLE_CAT" , iVarcharOid , 32 ) ;
f [ 1 ] = new Field ( connection , "TABLE_SCHEM" , iVarcharOid , 32 ) ;
f [ 2 ] = new Field ( connection , "TABLE_NAME" , iVarcharOid , 32 ) ;
f [ 3 ] = new Field ( connection , "COLUMN_NAME" , iVarcharOid , 32 ) ;
f [ 4 ] = new Field ( connection , "GRANTOR" , iVarcharOid , 32 ) ;
f [ 5 ] = new Field ( connection , "GRANTEE" , iVarcharOid , 32 ) ;
f [ 6 ] = new Field ( connection , "PRIVILEGE" , iVarcharOid , 32 ) ;
f [ 7 ] = new Field ( connection , "IS_GRANTABLE" , iVarcharOid , 32 ) ;
f [ 0 ] = new Field ( connection , "TABLE_CAT" , iVarcharOid , 32 ) ;
f [ 1 ] = new Field ( connection , "TABLE_SCHEM" , iVarcharOid , 32 ) ;
f [ 2 ] = new Field ( connection , "TABLE_NAME" , iVarcharOid , 32 ) ;
f [ 3 ] = new Field ( connection , "COLUMN_NAME" , iVarcharOid , 32 ) ;
f [ 4 ] = new Field ( connection , "GRANTOR" , iVarcharOid , 32 ) ;
f [ 5 ] = new Field ( connection , "GRANTEE" , iVarcharOid , 32 ) ;
f [ 6 ] = new Field ( connection , "PRIVILEGE" , iVarcharOid , 32 ) ;
f [ 7 ] = new Field ( connection , "IS_GRANTABLE" , iVarcharOid , 32 ) ;
// This is taken direct from the psql source
java . sql . 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 and relname like '" + tableNamePattern . toLowerCase ( ) + "' ORDER BY relname" ) ;
while ( r . next ( ) ) {
java . sql . 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 and relname like '" + tableNamePattern . toLowerCase ( ) + "' ORDER BY relname" ) ;
while ( r . next ( ) )
{
byte [ ] [ ] tuple = new byte [ 8 ] [ 0 ] ;
tuple [ 0 ] = tuple [ 1 ] = "" . getBytes ( ) ;
DriverManager . println ( "relname=\"" + r . getString ( 1 ) + "\" relacl=\"" + r . getString ( 2 ) + "\"" ) ;
tuple [ 0 ] = tuple [ 1 ] = "" . getBytes ( ) ;
DriverManager . println ( "relname=\"" + r . getString ( 1 ) + "\" relacl=\"" + r . getString ( 2 ) + "\"" ) ;
// For now, don't add to the result as relacl needs to be processed.
//v.addElement(tuple);
}
return new ResultSet ( connection , f , v , "OK" , 1 ) ;
return new ResultSet ( connection , f , v , "OK" , 1 ) ;
}
/ *
@ -2401,22 +2402,22 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
private java . sql . ResultSet getImportedExportedKeys ( String catalog , String schema , String primaryTable , String foreignTable ) throws SQLException
{
Field f [ ] = new Field [ 14 ] ;
f [ 0 ] = new Field ( connection , "PKTABLE_CAT" , iVarcharOid , 32 ) ;
f [ 1 ] = new Field ( connection , "PKTABLE_SCHEM" , iVarcharOid , 32 ) ;
f [ 2 ] = new Field ( connection , "PKTABLE_NAME" , iVarcharOid , 32 ) ;
f [ 3 ] = new Field ( connection , "PKCOLUMN_NAME" , iVarcharOid , 32 ) ;
f [ 4 ] = new Field ( connection , "FKTABLE_CAT" , iVarcharOid , 32 ) ;
f [ 5 ] = new Field ( connection , "FKTABLE_SCHEM" , iVarcharOid , 32 ) ;
f [ 6 ] = new Field ( connection , "FKTABLE_NAME" , iVarcharOid , 32 ) ;
f [ 7 ] = new Field ( connection , "FKCOLUMN_NAME" , iVarcharOid , 32 ) ;
f [ 8 ] = new Field ( connection , "KEY_SEQ" , iInt2Oid , 2 ) ;
f [ 9 ] = new Field ( connection , "UPDATE_RULE" , iInt2Oid , 2 ) ;
f [ 10 ] = new Field ( connection , "DELETE_RULE" , iInt2Oid , 2 ) ;
f [ 11 ] = new Field ( connection , "FK_NAME" , iVarcharOid , 32 ) ;
f [ 12 ] = new Field ( connection , "PK_NAME" , iVarcharOid , 32 ) ;
f [ 13 ] = new Field ( connection , "DEFERRABILITY" , iInt2Oid , 2 ) ;
Field f [ ] = new Field [ 14 ] ;
f [ 0 ] = new Field ( connection , "PKTABLE_CAT" , iVarcharOid , 32 ) ;
f [ 1 ] = new Field ( connection , "PKTABLE_SCHEM" , iVarcharOid , 32 ) ;
f [ 2 ] = new Field ( connection , "PKTABLE_NAME" , iVarcharOid , 32 ) ;
f [ 3 ] = new Field ( connection , "PKCOLUMN_NAME" , iVarcharOid , 32 ) ;
f [ 4 ] = new Field ( connection , "FKTABLE_CAT" , iVarcharOid , 32 ) ;
f [ 5 ] = new Field ( connection , "FKTABLE_SCHEM" , iVarcharOid , 32 ) ;
f [ 6 ] = new Field ( connection , "FKTABLE_NAME" , iVarcharOid , 32 ) ;
f [ 7 ] = new Field ( connection , "FKCOLUMN_NAME" , iVarcharOid , 32 ) ;
f [ 8 ] = new Field ( connection , "KEY_SEQ" , iInt2Oid , 2 ) ;
f [ 9 ] = new Field ( connection , "UPDATE_RULE" , iInt2Oid , 2 ) ;
f [ 10 ] = new Field ( connection , "DELETE_RULE" , iInt2Oid , 2 ) ;
f [ 11 ] = new Field ( connection , "FK_NAME" , iVarcharOid , 32 ) ;
f [ 12 ] = new Field ( connection , "PK_NAME" , iVarcharOid , 32 ) ;
f [ 13 ] = new Field ( connection , "DEFERRABILITY" , iInt2Oid , 2 ) ;
java . sql . ResultSet rs = connection . ExecSQL ( "SELECT c.relname,c2.relname,"
+ "t.tgconstrname,ic.relname,"
@ -2426,87 +2427,107 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
+ "pg_class ic,pg_proc p, pg_index i "
+ "WHERE t.tgrelid=c.oid AND t.tgconstrrelid=c2.oid "
+ "AND t.tgfoid=p.oid AND tgisconstraint "
+ ( ( primaryTable ! = null ) ? "AND c2.relname='" + primaryTable + "' " : "" )
+ ( ( foreignTable ! = null ) ? "AND c.relname='" + foreignTable + "' " : "" )
+ ( ( primaryTable ! = null ) ? "AND c2.relname='" + primaryTable + "' " : "" )
+ ( ( foreignTable ! = null ) ? "AND c.relname='" + foreignTable + "' " : "" )
+ "AND i.indrelid=c.oid "
+ "AND i.indexrelid=ic.oid AND i.indisprimary "
+ "ORDER BY c.relname,c2.relname"
) ;
Vector tuples = new Vector ( ) ;
short seq = 0 ;
if ( rs . next ( ) ) {
short seq = 0 ;
if ( rs . next ( ) )
{
boolean hasMore ;
do {
byte tuple [ ] [ ] = new byte [ 14 ] [ 0 ] ;
do
{
byte tuple [ ] [ ] = new byte [ 14 ] [ 0 ] ;
for ( int k = 0 ; k < 14 ; k + + )
tuple [ k ] = null ;
String fKeyName = rs . getString ( 3 ) ;
boolean foundRule = false ;
do {
String proname = rs . getString ( 9 ) ;
if ( proname ! = null & & proname . startsWith ( "RI_FKey_" ) ) {
int col = - 1 ;
if ( proname . endsWith ( "_upd" ) ) col = 9 ; // UPDATE_RULE
else if ( proname . endsWith ( "_del" ) ) col = 10 ; // DELETE_RULE
if ( col > - 1 ) {
String rule = proname . substring ( 8 , proname . length ( ) - 4 ) ;
int action = importedKeyNoAction ;
if ( "cascade" . equals ( rule ) ) action = importedKeyCascade ;
else if ( "setnull" . equals ( rule ) ) action = importedKeySetNull ;
else if ( "setdefault" . equals ( rule ) ) action = importedKeySetDefault ;
tuple [ col ] = Integer . toString ( action ) . getBytes ( ) ;
foundRule = true ;
}
}
} while ( ( hasMore = rs . next ( ) ) & & fKeyName . equals ( rs . getString ( 3 ) ) ) ;
if ( foundRule ) {
tuple [ 2 ] = rs . getBytes ( 2 ) ; //PKTABLE_NAME
tuple [ 6 ] = rs . getBytes ( 1 ) ; //FKTABLE_NAME
String fKeyName = rs . getString ( 3 ) ;
boolean foundRule = false ;
do
{
String proname = rs . getString ( 9 ) ;
if ( proname ! = null & & proname . startsWith ( "RI_FKey_" ) )
{
int col = - 1 ;
if ( proname . endsWith ( "_upd" ) )
col = 9 ; // UPDATE_RULE
else if ( proname . endsWith ( "_del" ) )
col = 10 ; // DELETE_RULE
if ( col > - 1 )
{
String rule = proname . substring ( 8 , proname . length ( ) - 4 ) ;
int action = importedKeyNoAction ;
if ( "cascade" . equals ( rule ) )
action = importedKeyCascade ;
else if ( "setnull" . equals ( rule ) )
action = importedKeySetNull ;
else if ( "setdefault" . equals ( rule ) )
action = importedKeySetDefault ;
tuple [ col ] = Integer . toString ( action ) . getBytes ( ) ;
foundRule = true ;
}
}
}
while ( ( hasMore = rs . next ( ) ) & & fKeyName . equals ( rs . getString ( 3 ) ) ) ;
if ( foundRule )
{
tuple [ 2 ] = rs . getBytes ( 2 ) ; //PKTABLE_NAME
tuple [ 6 ] = rs . getBytes ( 1 ) ; //FKTABLE_NAME
// Parse the tgargs data
StringBuffer fkeyColumns = new StringBuffer ( ) ;
StringBuffer pkeyColumns = new StringBuffer ( ) ;
int numColumns = ( rs . getInt ( 7 ) > > 1 ) - 2 ;
String s = rs . getString ( 8 ) ;
int pos = s . lastIndexOf ( "\\000" ) ;
for ( int c = 0 ; c < numColumns ; c + + ) {
if ( pos > - 1 ) {
int pos2 = s . lastIndexOf ( "\\000" , pos - 1 ) ;
if ( pos2 > - 1 ) {
if ( fkeyColumns . length ( ) > 0 ) fkeyColumns . insert ( 0 , ',' ) ;
fkeyColumns . insert ( 0 , s . substring ( pos2 + 4 , pos ) ) ; //FKCOLUMN_NAME
pos = s . lastIndexOf ( "\\000" , pos2 - 1 ) ;
if ( pos > - 1 ) {
if ( pkeyColumns . length ( ) > 0 ) pkeyColumns . insert ( 0 , ',' ) ;
pkeyColumns . insert ( 0 , s . substring ( pos + 4 , pos2 ) ) ; //PKCOLUMN_NAME
StringBuffer fkeyColumns = new StringBuffer ( ) ;
StringBuffer pkeyColumns = new StringBuffer ( ) ;
int numColumns = ( rs . getInt ( 7 ) > > 1 ) - 2 ;
String s = rs . getString ( 8 ) ;
int pos = s . lastIndexOf ( "\\000" ) ;
for ( int c = 0 ; c < numColumns ; c + + )
{
if ( pos > - 1 )
{
int pos2 = s . lastIndexOf ( "\\000" , pos - 1 ) ;
if ( pos2 > - 1 )
{
if ( fkeyColumns . length ( ) > 0 )
fkeyColumns . insert ( 0 , ',' ) ;
fkeyColumns . insert ( 0 , s . substring ( pos2 + 4 , pos ) ) ; //FKCOLUMN_NAME
pos = s . lastIndexOf ( "\\000" , pos2 - 1 ) ;
if ( pos > - 1 )
{
if ( pkeyColumns . length ( ) > 0 )
pkeyColumns . insert ( 0 , ',' ) ;
pkeyColumns . insert ( 0 , s . substring ( pos + 4 , pos2 ) ) ; //PKCOLUMN_NAME
}
}
}
}
tuple [ 7 ] = fkeyColumns . toString ( ) . getBytes ( ) ; //FKCOLUMN_NAME
tuple [ 3 ] = pkeyColumns . toString ( ) . getBytes ( ) ; //PKCOLUMN_NAME
tuple [ 7 ] = fkeyColumns . toString ( ) . getBytes ( ) ; //FKCOLUMN_NAME
tuple [ 3 ] = pkeyColumns . toString ( ) . getBytes ( ) ; //PKCOLUMN_NAME
tuple [ 8 ] = Integer . toString ( seq + + ) . getBytes ( ) ; //KEY_SEQ
tuple [ 11 ] = fKeyName . getBytes ( ) ; //FK_NAME
tuple [ 12 ] = rs . getBytes ( 4 ) ; //PK_NAME
tuple [ 8 ] = Integer . toString ( seq + + ) . getBytes ( ) ; //KEY_SEQ
tuple [ 11 ] = fKeyName . getBytes ( ) ; //FK_NAME
tuple [ 12 ] = rs . getBytes ( 4 ) ; //PK_NAME
// DEFERRABILITY
int deferrability = importedKeyNotDeferrable ;
boolean deferrable = rs . getBoolean ( 5 ) ;
boolean initiallyDeferred = rs . getBoolean ( 6 ) ;
if ( deferrable ) {
int deferrability = importedKeyNotDeferrable ;
boolean deferrable = rs . getBoolean ( 5 ) ;
boolean initiallyDeferred = rs . getBoolean ( 6 ) ;
if ( deferrable )
{
if ( initiallyDeferred )
deferrability = importedKeyInitiallyDeferred ;
deferrability = importedKeyInitiallyDeferred ;
else
deferrability = importedKeyInitiallyImmediate ;
deferrability = importedKeyInitiallyImmediate ;
}
tuple [ 13 ] = Integer . toString ( deferrability ) . getBytes ( ) ;
tuple [ 13 ] = Integer . toString ( deferrability ) . getBytes ( ) ;
tuples . addElement ( tuple ) ;
}
} while ( hasMore ) ;
}
while ( hasMore ) ;
}
return new ResultSet ( connection , f , tuples , "OK" , 1 ) ;