* This class provides information about the database as a whole.
*
* <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
* retrieve the data from these ResultSets. If a given form of metadata is
* not available, these methods should throw a SQLException.
*
*
* @see java.sql.DatabaseMetaData
*/
-public class DatabaseMetaData implements java.sql.DatabaseMetaData
+public class DatabaseMetaData implements java.sql.DatabaseMetaData
{
Connection connection; // The connection association
-
+
// These define various OID's. Hopefully they will stay constant.
static final int iVarcharOid = 1043; // OID for varchar
static final int iBoolOid = 16; // OID for bool
static final int iInt2Oid = 21; // OID for int2
static final int iInt4Oid = 23; // OID for int4
static final int VARHDRSZ = 4; // length for int4
-
+
// This is a default value for remarks
private static final byte defaultRemarks[]="no remarks".getBytes();
-
+
public DatabaseMetaData(Connection conn)
{
this.connection = conn;
}
-
+
/**
* Can all the procedures returned by getProcedures be called
* by the current user?
{
return true; // For now...
}
-
+
/**
* Can all the tables returned by getTable be SELECTed by
* the current user?
{
return true; // For now...
}
-
+
/**
* What is the URL for this database?
*
{
return connection.getURL();
}
-
+
/**
* What is our user name as known to the database?
*
{
return connection.getUserName();
}
-
+
/**
* Is the database in read-only mode?
*
{
return connection.isReadOnly();
}
-
+
/**
* Are NULL values sorted high?
*
{
return false;
}
-
+
/**
* Are NULL values sorted low?
*
{
return false;
}
-
+
/**
* Are NULL values sorted at the start regardless of sort order?
*
{
return false;
}
-
+
/**
* Are NULL values sorted at the end regardless of sort order?
*
{
return true;
}
-
+
/**
* What is the name of this database product - we hope that it is
* PostgreSQL, so we return that explicitly.
{
return "PostgreSQL";
}
-
+
/**
* What is the version of this database product.
*
return versionNumber;
}
-
+
/**
* What is the name of this JDBC driver? If we don't know this
* we are doing something wrong!
{
return "PostgreSQL Native Driver";
}
-
+
/**
* What is the version string of this JDBC driver? Again, this is
* static.
{
return connection.this_driver.getVersion();
}
-
+
/**
* What is this JDBC driver's major version number?
*
{
return connection.this_driver.getMajorVersion();
}
-
+
/**
* What is this JDBC driver's minor version number?
*
{
return connection.this_driver.getMinorVersion();
}
-
+
/**
* Does the database store tables in a local file? No - it
* stores them in a file on the server.
- *
+ *
* @return true if so
* @exception SQLException if a database access error occurs
*/
{
return false;
}
-
+
/**
* Does the database use a file for each table? Well, not really,
- * since it doesnt use local files.
+ * since it doesnt use local files.
*
* @return true if so
* @exception SQLException if a database access error occurs
{
return false;
}
-
+
/**
* Does the database treat mixed case unquoted SQL identifiers
* as case sensitive and as a result store them in mixed case?
{
return false;
}
-
+
/**
* Does the database treat mixed case unquoted SQL identifiers as
* case insensitive and store them in upper case?
{
return false;
}
-
+
/**
* Does the database treat mixed case unquoted SQL identifiers as
* case insensitive and store them in lower case?
{
return true;
}
-
+
/**
* Does the database treat mixed case unquoted SQL identifiers as
* case insensitive and store them in mixed case?
{
return false;
}
-
+
/**
* Does the database treat mixed case quoted SQL identifiers as
* case sensitive and as a result store them in mixed case? A
- * JDBC compliant driver will always return true.
+ * JDBC compliant driver will always return true.
*
* <p>Predicament - what do they mean by "SQL identifiers" - if it
* means the names of the tables and columns, then the answers
{
return true;
}
-
+
/**
* Does the database treat mixed case quoted SQL identifiers as
* case insensitive and store them in upper case?
{
return false;
}
-
+
/**
* Does the database treat mixed case quoted SQL identifiers as case
* insensitive and store them in lower case?
{
return false;
}
-
+
/**
* Does the database treat mixed case quoted SQL identifiers as case
* insensitive and store them in mixed case?
{
return false;
}
-
+
/**
* What is the string used to quote SQL identifiers? This returns
* a space if identifier quoting isn't supported. A JDBC Compliant
{
return "\"";
}
-
+
/**
* Get a comma separated list of all a database's SQL keywords that
* are NOT also SQL92 keywords.
{
return "abort,acl,add,aggregate,append,archive,arch_store,backward,binary,change,cluster,copy,database,delimiters,do,extend,explain,forward,heavy,index,inherits,isnull,light,listen,load,merge,nothing,notify,notnull,oids,purge,rename,replace,retrieve,returns,rule,recipe,setof,stdin,stdout,store,vacuum,verbose,version";
}
-
+
public String getNumericFunctions() throws SQLException
{
// XXX-Not Implemented
return "";
}
-
+
public String getStringFunctions() throws SQLException
{
// XXX-Not Implemented
return "";
}
-
+
public String getSystemFunctions() throws SQLException
{
// XXX-Not Implemented
return "";
}
-
+
public String getTimeDateFunctions() throws SQLException
{
// XXX-Not Implemented
return "";
}
-
+
/**
* This is the string that can be used to escape '_' and '%' in
* a search string pattern style catalog search parameters
{
return "\\";
}
-
+
/**
- * Get all the "extra" characters that can bew used in unquoted
+ * Get all the "extra" characters that can be used in unquoted
* identifier names (those beyond a-zA-Z0-9 and _)
*
* <p>From the file src/backend/parser/scan.l, an identifier is
{
return "";
}
-
+
/**
* Is "ALTER TABLE" with an add column supported?
* Yes for PostgreSQL 6.1
{
return true;
}
-
+
/**
* Is "ALTER TABLE" with a drop column supported?
* Peter 10/10/2000 This was set to true, but 7.1devel doesn't support it!
{
return false;
}
-
+
/**
* Is column aliasing supported?
*
{
return true;
}
-
+
/**
* Are concatenations between NULL and non-NULL values NULL? A
* JDBC Compliant driver always returns true
{
return true;
}
-
+
public boolean supportsConvert() throws SQLException
{
// XXX-Not Implemented
return false;
}
-
+
public boolean supportsConvert(int fromType, int toType) throws SQLException
{
// XXX-Not Implemented
return false;
}
-
+
public boolean supportsTableCorrelationNames() throws SQLException
{
// XXX-Not Implemented
return false;
}
-
+
public boolean supportsDifferentTableCorrelationNames() throws SQLException
{
// XXX-Not Implemented
return false;
}
-
+
/**
- * Are expressions in "ORCER BY" lists supported?
- *
+ * Are expressions in "ORDER BY" lists supported?
+ *
* <br>e.g. select * from t order by a + b;
*
* @return true if so
{
return true;
}
-
+
/**
* Can an "ORDER BY" clause use columns not in the SELECT?
* I checked it, and you can't.
{
return false;
}
-
+
/**
* Is some form of "GROUP BY" clause supported?
* I checked it, and yes it is.
{
return true;
}
-
+
/**
* Can a "GROUP BY" clause use columns not in the SELECT?
* I checked it - it seems to allow it
{
return true;
}
-
+
/**
* Can a "GROUP BY" clause add columns not in the SELECT provided
* it specifies all the columns in the SELECT? Does anyone actually
{
return true; // For now...
}
-
+
/**
* Is the escape character in "LIKE" clauses supported? A
* JDBC compliant driver always returns true.
{
return true;
}
-
+
/**
* Are multiple ResultSets from a single execute supported?
* Well, I implemented it, but I dont think this is possible from
* the back ends point of view.
- *
+ *
* @return true if so
* @exception SQLException if a database access error occurs
*/
{
return false;
}
-
+
/**
* Can we have multiple transactions open at once (on different
* connections?)
{
return true;
}
-
+
/**
* Can columns be defined as non-nullable. A JDBC Compliant driver
* always returns true.
{
return true;
}
-
+
/**
* Does this driver support the minimum ODBC SQL grammar. This
* grammar is defined at:
{
return true;
}
-
+
/**
* Does this driver support the Core ODBC SQL grammar. We need
* SQL-92 conformance for this.
{
return false;
}
-
+
/**
* Does this driver support the Extended (Level 2) ODBC SQL
* grammar. We don't conform to the Core (Level 1), so we can't
{
return false;
}
-
+
/**
* Does this driver support the ANSI-92 entry level SQL grammar?
* All JDBC Compliant drivers must return true. I think we have
{
return false;
}
-
+
/**
* Does this driver support the ANSI-92 intermediate level SQL
* grammar? Anyone who does not support Entry level cannot support
{
return false;
}
-
+
/**
* Does this driver support the ANSI-92 full SQL grammar?
*
{
return false;
}
-
+
/**
* Is the SQL Integrity Enhancement Facility supported?
* I haven't seen this mentioned anywhere, so I guess not
- *
+ *
* @return true if so
* @exception SQLException if a database access error occurs
*/
{
return false;
}
-
+
/**
* Is some form of outer join supported? From my knowledge, nope.
*
*/
public boolean supportsOuterJoins() throws SQLException
{
- return false;
+ return true; // yes 7.1 does
}
-
+
/**
* Are full nexted outer joins supported? Well, we dont support any
* form of outer join, so this is no as well
*/
public boolean supportsFullOuterJoins() throws SQLException
{
- return false;
+ return true; // yes in 7.1
}
-
+
/**
* Is there limited support for outer joins? (This will be true if
* supportFullOuterJoins is true)
*/
public boolean supportsLimitedOuterJoins() throws SQLException
{
- return false;
+ return true; // yes in 7.1
}
-
+
/**
* What is the database vendor's preferred term for "schema" - well,
* we do not provide support for schemas, so lets just use that
{
return "Schema";
}
-
+
/**
- * What is the database vendor's preferred term for "procedure" -
+ * What is the database vendor's preferred term for "procedure" -
* I kind of like "Procedure" myself.
*
* @return the vendor term
{
return "Procedure";
}
-
+
/**
* What is the database vendor's preferred term for "catalog"? -
* we dont have a preferred term, so just use Catalog
{
return "Catalog";
}
-
+
/**
* Does a catalog appear at the start of a qualified table name?
* (Otherwise it appears at the end).
{
return false;
}
-
+
/**
* What is the Catalog separator. Hmmm....well, I kind of like
* a period (so we get catalog.table definitions). - I don't think
// PM Sep 29 97 - changed from "." as we don't support catalogs.
return "";
}
-
+
/**
* Can a schema name be used in a data manipulation statement? Nope.
*
{
return false;
}
-
+
/**
* Can a schema name be used in a procedure call statement? Nope.
*
{
return false;
}
-
+
/**
* Can a schema be used in a table definition statement? Nope.
*
{
return false;
}
-
+
/**
* Can a schema name be used in an index definition statement?
*
{
return false;
}
-
+
/**
* Can a schema name be used in a privilege definition statement?
*
{
return false;
}
-
+
/**
* Can a catalog name be used in a data manipulation statement?
*
{
return false;
}
-
+
/**
* Can a catalog name be used in a procedure call statement?
*
{
return false;
}
-
+
/**
* Can a catalog name be used in a table definition statement?
*
{
return false;
}
-
+
/**
* Can a catalog name be used in an index definition?
*
{
return false;
}
-
+
/**
* Can a catalog name be used in a privilege definition statement?
*
{
return false;
}
-
+
/**
* We support cursors for gets only it seems. I dont see a method
* to get a positioned delete.
{
return false; // For now...
}
-
+
/**
* Is positioned UPDATE supported?
- *
+ *
* @return true if so
* @exception SQLException if a database access error occurs
*/
{
return false; // For now...
}
-
+
public boolean supportsSelectForUpdate() throws SQLException
{
// XXX-Not Implemented
return false;
}
-
+
public boolean supportsStoredProcedures() throws SQLException
{
// XXX-Not Implemented
return false;
}
-
+
public boolean supportsSubqueriesInComparisons() throws SQLException
{
// XXX-Not Implemented
return false;
}
-
+
public boolean supportsSubqueriesInExists() throws SQLException
{
// XXX-Not Implemented
return false;
}
-
+
public boolean supportsSubqueriesInIns() throws SQLException
{
// XXX-Not Implemented
return false;
}
-
+
public boolean supportsSubqueriesInQuantifieds() throws SQLException
{
// XXX-Not Implemented
return false;
}
-
+
public boolean supportsCorrelatedSubqueries() throws SQLException
{
// XXX-Not Implemented
return false;
}
-
+
/**
* Is SQL UNION supported? Nope.
*
*/
public boolean supportsUnion() throws SQLException
{
- return false;
+ return true; // 7.0?
}
-
+
/**
* Is SQL UNION ALL supported? Nope.
*
{
return false;
}
-
+
/**
* In PostgreSQL, Cursors are only open within transactions.
*
{
return false;
}
-
+
/**
* Do we support open cursors across multiple transactions?
*
{
return false;
}
-
+
/**
* Can statements remain open across commits? They may, but
* this driver cannot guarentee that. In further reflection.
{
return true;
}
-
+
/**
* Can statements remain open across rollbacks? They may, but
* this driver cannot guarentee that. In further contemplation,
{
return true;
}
-
+
/**
* How many hex characters can you have in an inline binary literal
*
{
return 0; // For now...
}
-
+
/**
* What is the maximum length for a character literal
* I suppose it is 8190 (8192 - 2 for the quotes)
{
return 65535;
}
-
+
/**
* Whats the limit on column name length. The description of
* pg_class would say '32' (length of pg_class.relname) - we
{
return 32;
}
-
+
/**
* What is the maximum number of columns in a "GROUP BY" clause?
*
* @return the max number of columns
- * @exception SQLException if a database access error occurs
+ * @exception SQLException if a database access error occurs
*/
public int getMaxColumnsInGroupBy() throws SQLException
{
return getMaxColumnsInTable();
}
-
+
/**
* What's the maximum number of columns allowed in an index?
* 6.0 only allowed one column, but 6.1 introduced multi-column
{
return getMaxColumnsInTable();
}
-
+
/**
* What's the maximum number of columns in an "ORDER BY clause?
* Theoretically, all of them!
{
return getMaxColumnsInTable();
}
-
+
/**
* What is the maximum number of columns in a "SELECT" list?
* Theoretically, all of them!
{
return getMaxColumnsInTable();
}
-
+
/**
* What is the maximum number of columns in a table? From the
* create_table(l) manual page...
{
return 1600;
}
-
+
/**
* How many active connection can we have at a time to this
* database? Well, since it depends on postmaster, which just
{
return 8192;
}
-
+
/**
* What is the maximum cursor name length (the same as all
* the other F***** identifiers!)
{
return 32;
}
-
+
/**
* What is the maximum length of an index (in bytes)? Now, does
- * the spec. mean name of an index (in which case its 32, the
+ * the spec. mean name of an index (in which case its 32, the
* same as a table) or does it mean length of an index element
* (in which case its 8192, the size of a row) or does it mean
- * the number of rows it can access (in which case it 2^32 -
+ * the number of rows it can access (in which case it 2^32 -
* a 4 byte OID number)? I think its the length of an index
* element, personally, so Im setting it to 65535.
*
{
return 65535;
}
-
+
public int getMaxSchemaNameLength() throws SQLException
{
// XXX-Not Implemented
return 0;
}
-
+
/**
* What is the maximum length of a procedure name?
* (length of pg_proc.proname used) - again, I really
{
return 32;
}
-
+
public int getMaxCatalogNameLength() throws SQLException
{
// XXX-Not Implemented
return 0;
}
-
+
/**
* What is the maximum length of a single row? (not including
* blobs). 65535 is defined in PostgreSQL.
{
return 65535;
}
-
+
/**
* Did getMaxRowSize() include LONGVARCHAR and LONGVARBINARY
* blobs? We don't handle blobs yet
{
return false;
}
-
+
/**
* What is the maximum length of a SQL statement?
*
{
return 65535;
}
-
+
/**
* How many active statements can we have open at one time to
* this database? Basically, since each Statement downloads
{
return 1;
}
-
+
/**
* What is the maximum length of a table name? This was found
* from pg_class.relname length
{
return 32;
}
-
+
/**
* What is the maximum number of tables that can be specified
* in a SELECT? Theoretically, this is the same number as the
{
return 1024;
}
-
+
/**
* What is the maximum length of a user name? Well, we generally
* use UNIX like user names in PostgreSQL, so I think this would
{
return 32;
}
-
-
+
+
/**
* What is the database's default transaction isolation level? We
* do not support this, so all transactions are SERIALIZABLE.
*/
public int getDefaultTransactionIsolation() throws SQLException
{
- return Connection.TRANSACTION_READ_COMMITTED;
+ return Connection.TRANSACTION_READ_COMMITTED;
}
-
+
/**
* Are transactions supported? If not, commit and rollback are noops
* and the isolation level is TRANSACTION_NONE. We do support
- * transactions.
+ * transactions.
*
* @return true if transactions are supported
* @exception SQLException if a database access error occurs
{
return true;
}
-
+
/**
* Does the database support the given transaction isolation level?
* We only support TRANSACTION_SERIALIZABLE and TRANSACTION_READ_COMMITTED
- *
+ *
* @param level the values are defined in java.sql.Connection
* @return true if so
* @exception SQLException if a database access error occurs
*/
public boolean supportsTransactionIsolationLevel(int level) throws SQLException
{
- if (level == Connection.TRANSACTION_SERIALIZABLE ||
- level == Connection.TRANSACTION_READ_COMMITTED)
- return true;
- else
- return false;
+ if (level == Connection.TRANSACTION_SERIALIZABLE ||
+ level == Connection.TRANSACTION_READ_COMMITTED)
+ return true;
+ else
+ return false;
}
-
+
/**
- * Are both data definition and data manipulation transactions
+ * Are both data definition and data manipulation transactions
* supported? I checked it, and could not do a CREATE TABLE
* within a transaction, so I am assuming that we don't
*
{
return false;
}
-
+
/**
* Are only data manipulation statements withing a transaction
* supported?
{
return true;
}
-
+
/**
* Does a data definition statement within a transaction force
* the transaction to commit? I think this means something like:
* COMMIT;
* </pre><p>
*
- * does the CREATE TABLE call cause a commit? The answer is no.
+ * does the CREATE TABLE call cause a commit? The answer is no.
*
* @return true if so
* @exception SQLException if a database access error occurs
{
return false;
}
-
+
/**
* Is a data definition statement within a transaction ignored?
* It seems to be (from experiment in previous method)
{
return true;
}
-
+
/**
* Get a description of stored procedures available in a catalog
- *
+ *
* <p>Only procedure descriptions matching the schema and procedure
* name criteria are returned. They are ordered by PROCEDURE_SCHEM
* and PROCEDURE_NAME
Field f[] = new Field[8];
java.sql.ResultSet r; // ResultSet for the SQL query that we need to do
Vector v = new Vector(); // The new ResultSet tuple stuff
-
+
byte remarks[] = defaultRemarks;
-
+
f[0] = new Field(connection, "PROCEDURE_CAT", iVarcharOid, 32);
f[1] = new Field(connection, "PROCEDURE_SCHEM", iVarcharOid, 32);
f[2] = new Field(connection, "PROCEDURE_NAME", iVarcharOid, 32);
f[3] = f[4] = f[5] = new Field(connection,"reserved",iVarcharOid,32); // null; // reserved, must be null for now
f[6] = new Field(connection, "REMARKS", iVarcharOid, 8192);
f[7] = new Field(connection, "PROCEDURE_TYPE", iInt2Oid, 2);
-
+
// If the pattern is null, then set it to the default
if(procedureNamePattern==null)
procedureNamePattern="%";
-
+
r = connection.ExecSQL("select proname, proretset from pg_proc where proname like '"+procedureNamePattern.toLowerCase()+"' order by proname");
-
+
while (r.next())
{
byte[][] tuple = new byte[8][0];
-
+
tuple[0] = null; // Catalog name
tuple[1] = null; // Schema name
tuple[2] = r.getBytes(1); // Procedure name
tuple[3] = tuple[4] = tuple[5] = null; // Reserved
tuple[6] = remarks; // Remarks
-
+
if (r.getBoolean(2))
tuple[7] = Integer.toString(java.sql.DatabaseMetaData.procedureReturnsResult).getBytes();
else
tuple[7] = Integer.toString(java.sql.DatabaseMetaData.procedureNoResult).getBytes();
-
+
v.addElement(tuple);
}
return new ResultSet(connection, f, v, "OK", 1);
}
-
+
/**
* Get a description of a catalog's stored procedure parameters
* and result columns.
* first. Next are the parameter descriptions in call order. The
* column descriptions follow in column number order.
*
- * <p>Each row in the ResultSet is a parameter description or column
+ * <p>Each row in the ResultSet is a parameter description or column
* description with the following fields:
* <ol>
* <li><b>PROCEDURE_CAT</b> String => procedure catalog (may be null)
{
if(procedureNamePattern==null)
procedureNamePattern="%";
-
+
if(columnNamePattern==null)
columnNamePattern="%";
-
+
// for now, this returns an empty result set.
Field f[] = new Field[13];
ResultSet r; // ResultSet for the SQL query that we need to do
Vector v = new Vector(); // The new ResultSet tuple stuff
-
+
f[0] = new Field(connection, "PROCEDURE_CAT", iVarcharOid, 32);
f[1] = new Field(connection, "PROCEDURE_SCHEM", iVarcharOid, 32);
f[2] = new Field(connection, "PROCEDURE_NAME", iVarcharOid, 32);
f[10] = new Field(connection, "RADIX", iInt2Oid, 2);
f[11] = new Field(connection, "NULLABLE", iInt2Oid, 2);
f[12] = new Field(connection, "REMARKS", iVarcharOid, 32);
-
+
// add query loop here
-
+
return new ResultSet(connection, f, v, "OK", 1);
}
-
+
/**
- * Get a description of tables available in a catalog.
+ * Get a description of tables available in a catalog.
*
* <p>Only table descriptions matching the catalog, schema, table
* name and type criteria are returned. They are ordered by
- * TABLE_TYPE, TABLE_SCHEM and TABLE_NAME.
- *
- * <p>Each table description has the following columns:
+ * TABLE_TYPE, TABLE_SCHEM and TABLE_NAME.
+ *
+ * <p>Each table description has the following columns:
*
* <ol>
- * <li><b>TABLE_CAT</b> String => table catalog (may be null)
- * <li><b>TABLE_SCHEM</b> String => table schema (may be null)
+ * <li><b>TABLE_CAT</b> String => table catalog (may be null)
+ * <li><b>TABLE_SCHEM</b> String => table schema (may be null)
* <li><b>TABLE_NAME</b> String => table name
* <li><b>TABLE_TYPE</b> String => table type. Typical types are "TABLE",
* "VIEW", "SYSTEM TABLE", "GLOBAL TEMPORARY", "LOCAL
- * TEMPORARY", "ALIAS", "SYNONYM".
+ * TEMPORARY", "ALIAS", "SYNONYM".
* <li><b>REMARKS</b> String => explanatory comment on the table
* </ol>
*
* @param tableNamePattern a table name pattern. For all tables this should be "%"
* @param types a list of table types to include; null returns
* all types
- * @return each row is a table description
+ * @return each row is a table description
* @exception SQLException if a database-access error occurs.
*/
public java.sql.ResultSet getTables(String catalog, String schemaPattern, String tableNamePattern, String types[]) throws SQLException
// Handle default value for types
if(types==null)
types = defaultTableTypes;
-
+
if(tableNamePattern==null)
tableNamePattern="%";
-
+
// the field descriptors for the new ResultSet
Field f[] = new Field[5];
java.sql.ResultSet r; // ResultSet for the SQL query that we need to do
Vector v = new Vector(); // The new ResultSet tuple stuff
-
+
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, "TABLE_TYPE", iVarcharOid, 32);
f[4] = new Field(connection, "REMARKS", iVarcharOid, 32);
-
+
// Now form the query
StringBuffer sql = new StringBuffer("select relname,oid,relkind from pg_class where (");
boolean notFirst=false;
for(int i=0;i<types.length;i++) {
for(int j=0;j<getTableTypes.length;j++)
if(getTableTypes[j][0].equals(types[i])) {
- if(notFirst)
- sql.append(" or ");
+ if(notFirst)
+ sql.append(" or ");
sql.append(getTableTypes[j][1]);
notFirst=true;
}
}
-
+
// Added by Stefan Andreasen <stefan@linux.kapow.dk>
// Now take the pattern into account
sql.append(") and relname like '");
sql.append(tableNamePattern.toLowerCase());
sql.append("' order by relkind, relname");
-
+
// Now run the query
r = connection.ExecSQL(sql.toString());
-
+
byte remarks[];
-
+
while (r.next())
{
byte[][] tuple = new byte[5][0];
-
+
// Fetch the description for the table (if any)
java.sql.ResultSet dr = connection.ExecSQL("select description from pg_description where objoid="+r.getInt(2));
if(((org.postgresql.ResultSet)dr).getTupleCount()==1) {
} else
remarks = defaultRemarks;
dr.close();
-
+
String relKind;
switch (r.getBytes(3)[0]) {
case (byte) 'r':
tuple[0] = null; // Catalog name
tuple[1] = null; // Schema name
- tuple[2] = r.getBytes(1); // Table name
+ tuple[2] = r.getBytes(1); // Table name
tuple[3] = (relKind==null) ? null : relKind.getBytes(); // Table type
tuple[4] = remarks; // Remarks
v.addElement(tuple);
r.close();
return new ResultSet(connection, f, v, "OK", 1);
}
-
+
// This array contains the valid values for the types argument
// in getTables().
//
//
// IMPORTANT: the query must be enclosed in ( )
private static final String getTableTypes[][] = {
- {"TABLE", "(relkind='r' and relhasrules='f' and relname !~ '^pg_')"},
+ {"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
private static final String defaultTableTypes[] = {
"TABLE","VIEW","INDEX","SEQUENCE"
};
-
+
/**
* Get the schema names available in this database. The results
* are ordered by schema name.
v.addElement(tuple);
return new ResultSet(connection,f,v,"OK",1);
}
-
+
/**
* Get the catalog names available in this database. The results
* are ordered by catalog name.
v.addElement(tuple);
return new ResultSet(connection,f,v,"OK",1);
}
-
+
/**
* Get the table types available in this database. The results
* are ordered by table type.
}
return new ResultSet(connection,f,v,"OK",1);
}
-
+
/**
* Get a description of table columns available in a catalog.
*
Field f[] = new Field[18];
java.sql.ResultSet r; // ResultSet for the SQL query that we need to do
Vector v = new Vector(); // The new ResultSet tuple stuff
-
+
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[15] = new Field(connection, "CHAR_OCTET_LENGTH", iVarcharOid, 32);
f[16] = new Field(connection, "ORDINAL_POSITION", iInt4Oid,4);
f[17] = new Field(connection, "IS_NULLABLE", iVarcharOid, 32);
-
+
// Added by Stefan Andreasen <stefan@linux.kapow.dk>
// If the pattern are null then set them to %
if (tableNamePattern == null) tableNamePattern="%";
if (columnNamePattern == null) columnNamePattern="%";
-
+
// Now form the query
// Modified by Stefan Andreasen <stefan@linux.kapow.dk>
r = connection.ExecSQL("select a.oid,c.relname,a.attname,a.atttypid,a.attnum,a.attnotnull,a.attlen,a.atttypmod from pg_class c, pg_attribute a where a.attrelid=c.oid and c.relname like '"+tableNamePattern.toLowerCase()+"' and a.attname like '"+columnNamePattern.toLowerCase()+"' and a.attnum>0 order by c.relname,a.attnum");
-
+
byte remarks[];
-
+
while(r.next()) {
byte[][] tuple = new byte[18][0];
-
+
// Fetch the description for the table (if any)
java.sql.ResultSet dr = connection.ExecSQL("select description from pg_description where objoid="+r.getInt(1));
if(((org.postgresql.ResultSet)dr).getTupleCount()==1) {
tuple[11] = dr.getBytes(1);
} else
tuple[11] = defaultRemarks;
-
+
dr.close();
-
+
tuple[0] = "".getBytes(); // Catalog name
tuple[1] = "".getBytes(); // Schema name
tuple[2] = r.getBytes(2); // Table name
tuple[3] = r.getBytes(3); // Column name
-
+
dr = connection.ExecSQL("select typname from pg_type where oid = "+r.getString(4));
dr.next();
String typname=dr.getString(1);
dr.close();
tuple[4] = Integer.toString(Field.getSQLType(typname)).getBytes(); // Data type
tuple[5] = typname.getBytes(); // Type name
-
+
// Column size
// Looking at the psql source,
// I think the length of a varchar as specified when the table was created
tuple[6] = Integer.toString(atttypmod != -1 ? atttypmod - VARHDRSZ : 0).getBytes();
} else
tuple[6] = r.getBytes(7);
-
+
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] is above
-
+
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.getBytes(5); // ordinal position
-
+
String nullFlag = r.getString(6);
tuple[10] = Integer.toString(nullFlag.equals("f")?java.sql.DatabaseMetaData.columnNullable:java.sql.DatabaseMetaData.columnNoNulls).getBytes(); // Nullable
tuple[17] = (nullFlag.equals("f")?"YES":"NO").getBytes(); // is nullable
-
+
v.addElement(tuple);
}
r.close();
return new ResultSet(connection, f, v, "OK", 1);
}
-
+
/**
* Get a description of the access rights for a table's columns.
*
{
Field f[] = new Field[8];
Vector v = new Vector();
-
+
if(table==null)
table="%";
-
+
if(columnNamePattern==null)
columnNamePattern="%";
else
columnNamePattern=columnNamePattern.toLowerCase();
-
+
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[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 '"+table.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)+"\"");
-
+
// 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);
}
-
+
/**
* Get a description of the access rights for each table available
* in a catalog.
// XXX-Not Implemented
return null;
}
-
+
/**
* Get a description of a table's optimal set of columns that
* uniquely identifies a row. They are ordered by SCOPE.
Field f[] = new Field[8];
ResultSet r; // ResultSet for the SQL query that we need to do
Vector v = new Vector(); // The new ResultSet tuple stuff
-
+
f[0] = new Field(connection, "SCOPE", iInt2Oid, 2);
f[1] = new Field(connection, "COLUMN_NAME", iVarcharOid, 32);
f[2] = new Field(connection, "DATA_TYPE", iInt2Oid, 2);
f[5] = new Field(connection, "BUFFER_LENGTH", iInt4Oid, 4);
f[6] = new Field(connection, "DECIMAL_DIGITS", iInt2Oid, 2);
f[7] = new Field(connection, "PSEUDO_COLUMN", iInt2Oid, 2);
-
+
return new ResultSet(connection, f, v, "OK", 1);
}
-
+
/**
* Get a description of a table's columns that are automatically
* updated when any value in a row is updated. They are
// XXX-Not Implemented
return null;
}
-
+
/**
* Get a description of a table's primary key columns. They
* are ordered by COLUMN_NAME.
" ORDER BY table_name, pk_name, key_seq"
);
}
-
- private void importLoop(Vector tuples, java.sql.ResultSet keyRelation) throws SQLException
- {
+
+ private void importLoop(Vector tuples, java.sql.ResultSet keyRelation) throws SQLException {
String s,s2;
String origTable=null, primTable=new String(""), schema;
int i;
s=keyRelation.getString(1);
s2=s;
//System.out.println(s);
-
+
for (i=0;;i++) {
s=s.substring(s.indexOf("\\000")+4);
if (s.compareTo("")==0) {
//return tuples;
}
-
/**
* Get a description of the primary key columns that are
* referenced by a table's foreign key columns (the primary keys
return rsret;
}
-
+
/**
* Get a description of a foreign key columns that reference a
* table's primary key columns (the foreign keys exported by a
// XXX-Not Implemented
return null;
}
-
+
/**
* Get a description of the foreign key columns in the foreign key
* table that reference the primary key columns of the primary key
// XXX-Not Implemented
return null;
}
-
+
/**
* Get a description of all the standard SQL types supported by
* this database. They are ordered by DATA_TYPE and then by how
Field f[] = new Field[18];
ResultSet r; // ResultSet for the SQL query that we need to do
Vector v = new Vector(); // The new ResultSet tuple stuff
-
+
f[0] = new Field(connection, "TYPE_NAME", iVarcharOid, 32);
f[1] = new Field(connection, "DATA_TYPE", iInt2Oid, 2);
f[2] = new Field(connection, "PRECISION", iInt4Oid, 4);
f[15] = new Field(connection, "SQL_DATA_TYPE", iInt4Oid, 4);
f[16] = new Field(connection, "SQL_DATETIME_SUB", iInt4Oid, 4);
f[17] = new Field(connection, "NUM_PREC_RADIX", iInt4Oid, 4);
-
+
// cache some results, this will keep memory useage down, and speed
// things up a little.
byte b9[] = "9".getBytes();
byte bf[] = "f".getBytes();
byte bnn[] = Integer.toString(typeNoNulls).getBytes();
byte bts[] = Integer.toString(typeSearchable).getBytes();
-
+
while(rs.next()) {
byte[][] tuple = new byte[18][];
String typname=rs.getString(1);
rs.close();
return new ResultSet(connection, f, v, "OK", 1);
}
-
+
return null;
}
-
+
/**
* Get a description of a table's indices and statistics. They are
* ordered by NON_UNIQUE, TYPE, INDEX_NAME, and ORDINAL_POSITION.
Field f[] = new Field[13];
java.sql.ResultSet r; // ResultSet for the SQL query that we need to do
Vector v = new Vector(); // The new ResultSet tuple stuff
-
+
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[10] = new Field(connection, "CARDINALITY", iInt4Oid, 4);
f[11] = new Field(connection, "PAGES", iInt4Oid, 4);
f[12] = new Field(connection, "FILTER_CONDITION", iVarcharOid, 32);
-
r = connection.ExecSQL("select " +
"c.relname, " +
return new ResultSet(connection, f, v, "OK", 1);
}
-}
+}