@ -15,7 +15,7 @@ import org.postgresql.util.PSQLException;
/ *
/ *
* This class provides information about the database as a whole .
* 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
* < 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
* can use the normal ResultSet methods such as getString and getInt to
@ -2256,7 +2256,8 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
// This is taken direct from the psql source
// 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" ) ;
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 ( ) ) {
while ( r . next ( ) )
{
byte [ ] [ ] tuple = new byte [ 8 ] [ 0 ] ;
byte [ ] [ ] tuple = new byte [ 8 ] [ 0 ] ;
tuple [ 0 ] = tuple [ 1 ] = "" . getBytes ( ) ;
tuple [ 0 ] = tuple [ 1 ] = "" . getBytes ( ) ;
DriverManager . println ( "relname=\"" + r . getString ( 1 ) + "\" relacl=\"" + r . getString ( 2 ) + "\"" ) ;
DriverManager . println ( "relname=\"" + r . getString ( 1 ) + "\" relacl=\"" + r . getString ( 2 ) + "\"" ) ;
@ -2434,34 +2435,46 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
) ;
) ;
Vector tuples = new Vector ( ) ;
Vector tuples = new Vector ( ) ;
short seq = 0 ;
short seq = 0 ;
if ( rs . next ( ) ) {
if ( rs . next ( ) )
{
boolean hasMore ;
boolean hasMore ;
do {
do
{
byte tuple [ ] [ ] = new byte [ 14 ] [ 0 ] ;
byte tuple [ ] [ ] = new byte [ 14 ] [ 0 ] ;
for ( int k = 0 ; k < 14 ; k + + )
for ( int k = 0 ; k < 14 ; k + + )
tuple [ k ] = null ;
tuple [ k ] = null ;
String fKeyName = rs . getString ( 3 ) ;
String fKeyName = rs . getString ( 3 ) ;
boolean foundRule = false ;
boolean foundRule = false ;
do {
do
{
String proname = rs . getString ( 9 ) ;
String proname = rs . getString ( 9 ) ;
if ( proname ! = null & & proname . startsWith ( "RI_FKey_" ) ) {
if ( proname ! = null & & proname . startsWith ( "RI_FKey_" ) )
{
int col = - 1 ;
int col = - 1 ;
if ( proname . endsWith ( "_upd" ) ) col = 9 ; // UPDATE_RULE
if ( proname . endsWith ( "_upd" ) )
else if ( proname . endsWith ( "_del" ) ) col = 10 ; // DELETE_RULE
col = 9 ; // UPDATE_RULE
if ( col > - 1 ) {
else if ( proname . endsWith ( "_del" ) )
col = 10 ; // DELETE_RULE
if ( col > - 1 )
{
String rule = proname . substring ( 8 , proname . length ( ) - 4 ) ;
String rule = proname . substring ( 8 , proname . length ( ) - 4 ) ;
int action = importedKeyNoAction ;
int action = importedKeyNoAction ;
if ( "cascade" . equals ( rule ) ) action = importedKeyCascade ;
if ( "cascade" . equals ( rule ) )
else if ( "setnull" . equals ( rule ) ) action = importedKeySetNull ;
action = importedKeyCascade ;
else if ( "setdefault" . equals ( rule ) ) action = importedKeySetDefault ;
else if ( "setnull" . equals ( rule ) )
action = importedKeySetNull ;
else if ( "setdefault" . equals ( rule ) )
action = importedKeySetDefault ;
tuple [ col ] = Integer . toString ( action ) . getBytes ( ) ;
tuple [ col ] = Integer . toString ( action ) . getBytes ( ) ;
foundRule = true ;
foundRule = true ;
}
}
}
}
} while ( ( hasMore = rs . next ( ) ) & & fKeyName . equals ( rs . getString ( 3 ) ) ) ;
}
while ( ( hasMore = rs . next ( ) ) & & fKeyName . equals ( rs . getString ( 3 ) ) ) ;
if ( foundRule ) {
if ( foundRule )
{
tuple [ 2 ] = rs . getBytes ( 2 ) ; //PKTABLE_NAME
tuple [ 2 ] = rs . getBytes ( 2 ) ; //PKTABLE_NAME
tuple [ 6 ] = rs . getBytes ( 1 ) ; //FKTABLE_NAME
tuple [ 6 ] = rs . getBytes ( 1 ) ; //FKTABLE_NAME
@ -2471,15 +2484,21 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
int numColumns = ( rs . getInt ( 7 ) > > 1 ) - 2 ;
int numColumns = ( rs . getInt ( 7 ) > > 1 ) - 2 ;
String s = rs . getString ( 8 ) ;
String s = rs . getString ( 8 ) ;
int pos = s . lastIndexOf ( "\\000" ) ;
int pos = s . lastIndexOf ( "\\000" ) ;
for ( int c = 0 ; c < numColumns ; c + + ) {
for ( int c = 0 ; c < numColumns ; c + + )
if ( pos > - 1 ) {
{
if ( pos > - 1 )
{
int pos2 = s . lastIndexOf ( "\\000" , pos - 1 ) ;
int pos2 = s . lastIndexOf ( "\\000" , pos - 1 ) ;
if ( pos2 > - 1 ) {
if ( pos2 > - 1 )
if ( fkeyColumns . length ( ) > 0 ) fkeyColumns . insert ( 0 , ',' ) ;
{
if ( fkeyColumns . length ( ) > 0 )
fkeyColumns . insert ( 0 , ',' ) ;
fkeyColumns . insert ( 0 , s . substring ( pos2 + 4 , pos ) ) ; //FKCOLUMN_NAME
fkeyColumns . insert ( 0 , s . substring ( pos2 + 4 , pos ) ) ; //FKCOLUMN_NAME
pos = s . lastIndexOf ( "\\000" , pos2 - 1 ) ;
pos = s . lastIndexOf ( "\\000" , pos2 - 1 ) ;
if ( pos > - 1 ) {
if ( pos > - 1 )
if ( pkeyColumns . length ( ) > 0 ) pkeyColumns . insert ( 0 , ',' ) ;
{
if ( pkeyColumns . length ( ) > 0 )
pkeyColumns . insert ( 0 , ',' ) ;
pkeyColumns . insert ( 0 , s . substring ( pos + 4 , pos2 ) ) ; //PKCOLUMN_NAME
pkeyColumns . insert ( 0 , s . substring ( pos + 4 , pos2 ) ) ; //PKCOLUMN_NAME
}
}
}
}
@ -2496,7 +2515,8 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
int deferrability = importedKeyNotDeferrable ;
int deferrability = importedKeyNotDeferrable ;
boolean deferrable = rs . getBoolean ( 5 ) ;
boolean deferrable = rs . getBoolean ( 5 ) ;
boolean initiallyDeferred = rs . getBoolean ( 6 ) ;
boolean initiallyDeferred = rs . getBoolean ( 6 ) ;
if ( deferrable ) {
if ( deferrable )
{
if ( initiallyDeferred )
if ( initiallyDeferred )
deferrability = importedKeyInitiallyDeferred ;
deferrability = importedKeyInitiallyDeferred ;
else
else
@ -2506,7 +2526,8 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
tuples . addElement ( tuple ) ;
tuples . addElement ( tuple ) ;
}
}
} while ( hasMore ) ;
}
while ( hasMore ) ;
}
}
return new ResultSet ( connection , f , tuples , "OK" , 1 ) ;
return new ResultSet ( connection , f , tuples , "OK" , 1 ) ;