summaryrefslogtreecommitdiff
path: root/src/interfaces/jdbc/org/postgresql/jdbc2/DatabaseMetaData.java
diff options
context:
space:
mode:
authorPeter Eisentraut <peter_e@gmx.net>2001-07-08 08:31:08 +0000
committerPeter Eisentraut <peter_e@gmx.net>2001-07-08 08:31:08 +0000
commit2d9ee0fc551629d57b40c071d5ff8fc28e9e32bf (patch)
tree0b4a578a7f53a5f2b1d672049164090dbe601705 /src/interfaces/jdbc/org/postgresql/jdbc2/DatabaseMetaData.java
parentea88062c29aca410535c75c3b7aef1937bd74a47 (diff)
downloadpostgresql-2d9ee0fc551629d57b40c071d5ff8fc28e9e32bf.tar.gz
Bring DatabaseMetaData feature tests up to date:
* NULLs are sorted differently in 7.2 * table correlation names are supported * GROUP BY, ORDER BY unrelated is supported since 6.4 * ESCAPE/LIKE only supported since 7.1 * outer joins only since 7.1 * preferred term for procedure is "function" * preferred term for catalog is "database" * supports SELECT for UPDATE since 6.5 * supports subqueries * supports UNION; supports UNION ALL since 7.1 * update some of the max lengths to match reality * rearrange some functions to match the order in the spec for easier maintenance
Diffstat (limited to 'src/interfaces/jdbc/org/postgresql/jdbc2/DatabaseMetaData.java')
-rw-r--r--src/interfaces/jdbc/org/postgresql/jdbc2/DatabaseMetaData.java342
1 files changed, 200 insertions, 142 deletions
diff --git a/src/interfaces/jdbc/org/postgresql/jdbc2/DatabaseMetaData.java b/src/interfaces/jdbc/org/postgresql/jdbc2/DatabaseMetaData.java
index 98ef712d28..b048ca6127 100644
--- a/src/interfaces/jdbc/org/postgresql/jdbc2/DatabaseMetaData.java
+++ b/src/interfaces/jdbc/org/postgresql/jdbc2/DatabaseMetaData.java
@@ -46,6 +46,16 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
// This is a default value for remarks
private static final byte defaultRemarks[]="no remarks".getBytes();
+
+ private boolean haveMinimumServerVersion(String ver) throws SQLException
+ {
+ if (getDatabaseProductVersion().compareTo(ver)>=0)
+ return true;
+ else
+ return false;
+ }
+
+
public DatabaseMetaData(Connection conn)
{
this.connection = conn;
@@ -116,7 +126,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
*/
public boolean nullsAreSortedHigh() throws SQLException
{
- return false;
+ return haveMinimumServerVersion("7.2");
}
/**
@@ -149,7 +159,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
*/
public boolean nullsAreSortedAtEnd() throws SQLException
{
- return true;
+ return ! haveMinimumServerVersion("7.2");
}
/**
@@ -305,10 +315,6 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
* case sensitive and as a result store them in mixed case? A
* 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
- * given below are correct - otherwise I don't know.
- *
* @return true if so
* @exception SQLException if a database access error occurs
*/
@@ -355,9 +361,6 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
* a space if identifier quoting isn't supported. A JDBC Compliant
* driver will always use a double quote character.
*
- * <p>If an SQL identifier is a table name, column name, etc. then
- * we do not support it.
- *
* @return the quoting string
* @exception SQLException if a database access error occurs
*/
@@ -510,15 +513,27 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
return false;
}
+ /**
+ * Are table correlation names supported? A JDBC Compliant
+ * driver always returns true.
+ *
+ * @return true if so; false otherwise
+ * @exception SQLException - if a database access error occurs
+ */
public boolean supportsTableCorrelationNames() throws SQLException
{
- // XXX-Not Implemented
- return false;
+ return true;
}
+ /**
+ * If table correlation names are supported, are they restricted to
+ * be different from the names of the tables?
+ *
+ * @return true if so; false otherwise
+ * @exception SQLException - if a database access error occurs
+ */
public boolean supportsDifferentTableCorrelationNames() throws SQLException
{
- // XXX-Not Implemented
return false;
}
@@ -537,14 +552,13 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
/**
* Can an "ORDER BY" clause use columns not in the SELECT?
- * I checked it, and you can't.
*
* @return true if so
* @exception SQLException if a database access error occurs
*/
public boolean supportsOrderByUnrelated() throws SQLException
{
- return false;
+ return haveMinimumServerVersion("6.4");
}
/**
@@ -561,14 +575,13 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
/**
* Can a "GROUP BY" clause use columns not in the SELECT?
- * I checked it - it seems to allow it
*
* @return true if so
* @exception SQLException if a database access error occurs
*/
public boolean supportsGroupByUnrelated() throws SQLException
{
- return true;
+ return haveMinimumServerVersion("6.4");
}
/**
@@ -576,12 +589,14 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
* it specifies all the columns in the SELECT? Does anyone actually
* understand what they mean here?
*
+ * (I think this is a subset of the previous function. -- petere)
+ *
* @return true if so
* @exception SQLException if a database access error occurs
*/
public boolean supportsGroupByBeyondSelect() throws SQLException
{
- return true; // For now...
+ return supportsGroupByUnrelated();
}
/**
@@ -593,7 +608,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
*/
public boolean supportsLikeEscapeClause() throws SQLException
{
- return true;
+ return haveMinimumServerVersion("7.1");
}
/**
@@ -681,8 +696,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
/**
* Does this driver support the ANSI-92 entry level SQL grammar?
- * All JDBC Compliant drivers must return true. I think we have
- * to support outer joins for this to be true.
+ * All JDBC Compliant drivers must return true.
*
* @return true if so
* @exception SQLException if a database access error occurs
@@ -694,8 +708,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
/**
* Does this driver support the ANSI-92 intermediate level SQL
- * grammar? Anyone who does not support Entry level cannot support
- * Intermediate level.
+ * grammar?
*
* @return true if so
* @exception SQLException if a database access error occurs
@@ -736,7 +749,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
*/
public boolean supportsOuterJoins() throws SQLException
{
- return true; // yes 7.1 does
+ return haveMinimumServerVersion("7.1");
}
/**
@@ -748,7 +761,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
*/
public boolean supportsFullOuterJoins() throws SQLException
{
- return true; // yes in 7.1
+ return haveMinimumServerVersion("7.1");
}
/**
@@ -760,44 +773,43 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
*/
public boolean supportsLimitedOuterJoins() throws SQLException
{
- return true; // yes in 7.1
+ return supportsFullOuterJoins();
}
/**
- * What is the database vendor's preferred term for "schema" - well,
- * we do not provide support for schemas, so lets just use that
- * term.
+ * What is the database vendor's preferred term for "schema"?
+ * PostgreSQL doesn't have schemas, but when it does, we'll use the
+ * term "schema".
*
* @return the vendor term
* @exception SQLException if a database access error occurs
*/
public String getSchemaTerm() throws SQLException
{
- return "Schema";
+ return "schema";
}
/**
- * What is the database vendor's preferred term for "procedure" -
- * I kind of like "Procedure" myself.
+ * What is the database vendor's preferred term for "procedure"?
+ * Traditionally, "function" has been used.
*
* @return the vendor term
* @exception SQLException if a database access error occurs
*/
public String getProcedureTerm() throws SQLException
{
- return "Procedure";
+ return "function";
}
/**
- * What is the database vendor's preferred term for "catalog"? -
- * we dont have a preferred term, so just use Catalog
+ * What is the database vendor's preferred term for "catalog"?
*
* @return the vendor term
* @exception SQLException if a database access error occurs
*/
public String getCatalogTerm() throws SQLException
{
- return "Catalog";
+ return "database";
}
/**
@@ -809,21 +821,18 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
*/
public boolean isCatalogAtStart() throws SQLException
{
- return false;
+ throw org.postgresql.Driver.notImplemented();
}
/**
- * What is the Catalog separator. Hmmm....well, I kind of like
- * a period (so we get catalog.table definitions). - I don't think
- * PostgreSQL supports catalogs anyhow, so it makes no difference.
+ * What is the Catalog separator.
*
* @return the catalog separator string
* @exception SQLException if a database access error occurs
*/
public String getCatalogSeparator() throws SQLException
{
- // PM Sep 29 97 - changed from "." as we don't support catalogs.
- return "";
+ throw org.postgresql.Driver.notImplemented();
}
/**
@@ -959,68 +968,114 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
return false; // For now...
}
+ /**
+ * Is SELECT for UPDATE supported?
+ *
+ * @return true if so; false otherwise
+ * @exception SQLException - if a database access error occurs
+ */
public boolean supportsSelectForUpdate() throws SQLException
{
- // XXX-Not Implemented
- return false;
+ return haveMinimumServerVersion("6.5");
}
+ /**
+ * Are stored procedure calls using the stored procedure escape
+ * syntax supported?
+ *
+ * @return true if so; false otherwise
+ * @exception SQLException - if a database access error occurs
+ */
public boolean supportsStoredProcedures() throws SQLException
{
- // XXX-Not Implemented
return false;
}
+ /**
+ * Are subqueries in comparison expressions supported? A JDBC
+ * Compliant driver always returns true.
+ *
+ * @return true if so; false otherwise
+ * @exception SQLException - if a database access error occurs
+ */
public boolean supportsSubqueriesInComparisons() throws SQLException
{
- // XXX-Not Implemented
- return false;
+ return true;
}
+ /**
+ * Are subqueries in 'exists' expressions supported? A JDBC
+ * Compliant driver always returns true.
+ *
+ * @return true if so; false otherwise
+ * @exception SQLException - if a database access error occurs
+ */
public boolean supportsSubqueriesInExists() throws SQLException
{
- // XXX-Not Implemented
- return false;
+ return true;
}
+ /**
+ * Are subqueries in 'in' statements supported? A JDBC
+ * Compliant driver always returns true.
+ *
+ * @return true if so; false otherwise
+ * @exception SQLException - if a database access error occurs
+ */
public boolean supportsSubqueriesInIns() throws SQLException
{
- // XXX-Not Implemented
- return false;
+ return true;
}
+ /**
+ * Are subqueries in quantified expressions supported? A JDBC
+ * Compliant driver always returns true.
+ *
+ * (No idea what this is, but we support a good deal of
+ * subquerying.)
+ *
+ * @return true if so; false otherwise
+ * @exception SQLException - if a database access error occurs
+ */
public boolean supportsSubqueriesInQuantifieds() throws SQLException
{
- // XXX-Not Implemented
- return false;
+ return true;
}
+ /**
+ * Are correlated subqueries supported? A JDBC Compliant driver
+ * always returns true.
+ *
+ * (a.k.a. subselect in from?)
+ *
+ * @return true if so; false otherwise
+ * @exception SQLException - if a database access error occurs
+ */
public boolean supportsCorrelatedSubqueries() throws SQLException
{
- // XXX-Not Implemented
- return false;
+ return haveMinimumServerVersion("7.1");
}
/**
- * Is SQL UNION supported? Nope.
+ * Is SQL UNION supported?
*
* @return true if so
* @exception SQLException if a database access error occurs
*/
public boolean supportsUnion() throws SQLException
{
- return true; // 7.0?
+ return true; // since 6.3
}
/**
- * Is SQL UNION ALL supported? Nope.
+ * Is SQL UNION ALL supported?
*
* @return true if so
* @exception SQLException if a database access error occurs
*/
public boolean supportsUnionAll() throws SQLException
{
- return false;
+ return haveMinimumServerVersion("7.1");
}
/**
@@ -1081,7 +1136,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
*/
public int getMaxBinaryLiteralLength() throws SQLException
{
- return 0; // For now...
+ return 0; // no limit
}
/**
@@ -1093,7 +1148,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
*/
public int getMaxCharLiteralLength() throws SQLException
{
- return 65535;
+ return 0; // no limit
}
/**
@@ -1117,7 +1172,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
*/
public int getMaxColumnsInGroupBy() throws SQLException
{
- return getMaxColumnsInTable();
+ return 0; // no limit
}
/**
@@ -1135,26 +1190,24 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
/**
* What's the maximum number of columns in an "ORDER BY clause?
- * Theoretically, all of them!
*
* @return the max columns
* @exception SQLException if a database access error occurs
*/
public int getMaxColumnsInOrderBy() throws SQLException
{
- return getMaxColumnsInTable();
+ return 0; // no limit
}
/**
* What is the maximum number of columns in a "SELECT" list?
- * Theoretically, all of them!
*
* @return the max columns
* @exception SQLException if a database access error occurs
*/
public int getMaxColumnsInSelect() throws SQLException
{
- return getMaxColumnsInTable();
+ return 0; // no limit
}
/**
@@ -1204,20 +1257,17 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
}
/**
- * 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
- * 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 -
- * a 4 byte OID number)? I think its the length of an index
- * element, personally, so Im setting it to 8192.
+ * Retrieves the maximum number of bytes for an index, including all
+ * of the parts of the index.
*
- * @return max index length in bytes
+ * @return max index length in bytes, which includes the composite
+ * of all the constituent parts of the index; a result of zero means
+ * that there is no limit or the limit is not known
* @exception SQLException if a database access error occurs
*/
public int getMaxIndexLength() throws SQLException
{
- return 65535;
+ return 0; // no limit (larger than an int anyway)
}
public int getMaxSchemaNameLength() throws SQLException
@@ -1246,15 +1296,17 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
}
/**
- * What is the maximum length of a single row? (not including
- * blobs). 65535 is defined in PostgreSQL.
+ * What is the maximum length of a single row?
*
* @return max row size in bytes
* @exception SQLException if a database access error occurs
*/
public int getMaxRowSize() throws SQLException
{
- return 65535;
+ if (haveMinimumServerVersion("7.1"))
+ return 1073741824; // 1 GB
+ else
+ return 8192; // XXX could be altered
}
/**
@@ -1277,7 +1329,10 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
*/
public int getMaxStatementLength() throws SQLException
{
- return 65535;
+ if (haveMinimumServerVersion("7.0"))
+ return 0; // actually whatever fits in size_t
+ else
+ return 16384;
}
/**
@@ -1310,19 +1365,14 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
/**
* What is the maximum number of tables that can be specified
- * in a SELECT? Theoretically, this is the same number as the
- * number of tables allowable. In practice tho, it is much smaller
- * since the number of tables is limited by the statement, we
- * return 1024 here - this is just a number I came up with (being
- * the number of tables roughly of three characters each that you
- * can fit inside a 8192 character buffer with comma separators).
+ * in a SELECT?
*
* @return the maximum
* @exception SQLException if a database access error occurs
*/
public int getMaxTablesInSelect() throws SQLException
{
- return 1024;
+ return 0; // no limit
}
/**
@@ -1386,15 +1436,14 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
/**
* 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
+ * supported?
*
* @return true if so
* @exception SQLException if a database access error occurs
*/
public boolean supportsDataDefinitionAndDataManipulationTransactions() throws SQLException
{
- return false;
+ return true;
}
/**
@@ -1406,7 +1455,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
*/
public boolean supportsDataManipulationTransactionsOnly() throws SQLException
{
- return true;
+ return false;
}
/**
@@ -2699,91 +2748,89 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
return new ResultSet(connection, f, v, "OK", 1);
}
+
// ** JDBC 2 Extensions **
/**
- * New in 7.1 - we don't support deletes so this must be false!
+ * Does the database support the given result set type?
+ *
+ * @param type - defined in java.sql.ResultSet
+ * @return true if so; false otherwise
+ * @exception SQLException - if a database access error occurs
*/
- public boolean deletesAreDetected(int i) throws SQLException
+ public boolean supportsResultSetType(int type) throws SQLException
{
- return false;
+ // The only type we don't support
+ return type != java.sql.ResultSet.TYPE_SCROLL_SENSITIVE;
}
+
/**
- * New in 7.1 - we don't support deletes so this must be false!
- */
- public boolean othersDeletesAreVisible(int i) throws SQLException
+ * Does the database support the concurrency type in combination
+ * with the given result set type?
+ *
+ * @param type - defined in java.sql.ResultSet
+ * @param concurrency - type defined in java.sql.ResultSet
+ * @return true if so; false otherwise
+ * @exception SQLException - if a database access error occurs
+ */
+ public boolean supportsResultSetConcurrency(int type,int concurrency) throws SQLException
{
- return false;
- }
+ // These combinations are not supported!
+ if(type == java.sql.ResultSet.TYPE_SCROLL_SENSITIVE)
+ return false;
- public java.sql.Connection getConnection() throws SQLException
- {
- return (java.sql.Connection)connection;
- }
+ // We don't yet support Updateable ResultSets
+ if(concurrency == java.sql.ResultSet.CONCUR_UPDATABLE)
+ return false;
- /**
- * Return user defined types in a schema
- */
- public java.sql.ResultSet getUDTs(String catalog,
- String schemaPattern,
- String typeNamePattern,
- int[] types
- ) throws SQLException
- {
- throw org.postgresql.Driver.notImplemented();
+ // Everything else we do
+ return true;
}
- /**
- * New in 7.1 - we don't support visible inserts so this must be false!
- */
- public boolean othersInsertsAreVisible(int type) throws SQLException
+
+ /* lots of unsupported stuff... */
+ public boolean ownUpdatesAreVisible(int type) throws SQLException
{
return false;
}
- /**
- * New in 7.1 - we don't support visible updates so this must be false!
- */
- public boolean updatesAreDetected(int type) throws SQLException
+ public boolean ownDeletesAreVisible(int type) throws SQLException
{
return false;
}
- /**
- * New in 7.1 - we don't support visible updates so this must be false!
- */
- public boolean othersUpdatesAreVisible(int type) throws SQLException
+ public boolean ownInsertsAreVisible(int type) throws SQLException
{
return false;
}
- public boolean ownUpdatesAreVisible(int type) throws SQLException
+ public boolean othersUpdatesAreVisible(int type) throws SQLException
{
return false;
}
- public boolean ownInsertsAreVisible(int type) throws SQLException
+ public boolean othersDeletesAreVisible(int i) throws SQLException
{
return false;
}
- public boolean insertsAreDetected(int type) throws SQLException
+ public boolean othersInsertsAreVisible(int type) throws SQLException
{
return false;
}
- public boolean ownDeletesAreVisible(int type) throws SQLException
+ public boolean updatesAreDetected(int type) throws SQLException
{
return false;
}
- public boolean rowChangesAreDetected(int type) throws SQLException
+ public boolean deletesAreDetected(int i) throws SQLException
{
return false;
}
- public boolean rowChangesAreVisible(int type) throws SQLException
+ public boolean insertsAreDetected(int type) throws SQLException
{
return false;
}
@@ -2797,26 +2844,37 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
}
/**
- * New in 7.1
+ * Return user defined types in a schema
*/
- public boolean supportsResultSetConcurrency(int type,int concurrency) throws SQLException
+ public java.sql.ResultSet getUDTs(String catalog,
+ String schemaPattern,
+ String typeNamePattern,
+ int[] types
+ ) throws SQLException
{
- // These combinations are not supported!
- if(type==java.sql.ResultSet.TYPE_SCROLL_SENSITIVE)
- return false;
+ throw org.postgresql.Driver.notImplemented();
+ }
- // We don't yet support Updateable ResultSets
- if(concurrency==java.sql.ResultSet.CONCUR_UPDATABLE)
- return false;
- // Everything else we do
- return true;
+ /**
+ * Retrieves the connection that produced this metadata object.
+ *
+ * @return the connection that produced this metadata object
+ */
+ public java.sql.Connection getConnection() throws SQLException
+ {
+ return (java.sql.Connection)connection;
}
- public boolean supportsResultSetType(int type) throws SQLException
+ /* I don't find these in the spec!?! */
+
+ public boolean rowChangesAreDetected(int type) throws SQLException
{
- // The only type we don't support
- return type!=java.sql.ResultSet.TYPE_SCROLL_SENSITIVE;
+ return false;
}
+ public boolean rowChangesAreVisible(int type) throws SQLException
+ {
+ return false;
+ }
}