Index: org/postgresql/jdbc2/AbstractJdbc2DatabaseMetaData.java
===================================================================
RCS file: /cvsroot/jdbc/pgjdbc/org/postgresql/jdbc2/AbstractJdbc2DatabaseMetaData.java,v
retrieving revision 1.42
diff -c -r1.42 AbstractJdbc2DatabaseMetaData.java
*** org/postgresql/jdbc2/AbstractJdbc2DatabaseMetaData.java 2 Dec 2007 06:48:43 -0000 1.42
--- org/postgresql/jdbc2/AbstractJdbc2DatabaseMetaData.java 23 Dec 2007 23:12:41 -0000
***************
*** 2202,2280 ****
return (ResultSet) ((BaseStatement)createMetaDataStatement()).createDriverResultSet(f, v);
}
!
! /*
! * Get a description of table columns available in a catalog.
! *
! *
Only column descriptions matching the catalog, schema, table
! * and column name criteria are returned. They are ordered by
! * TABLE_SCHEM, TABLE_NAME and ORDINAL_POSITION.
! *
! *
Each column description has the following columns:
! *
! * - TABLE_CAT String => table catalog (may be null)
! *
- TABLE_SCHEM String => table schema (may be null)
! *
- TABLE_NAME String => table name
! *
- COLUMN_NAME String => column name
! *
- DATA_TYPE short => SQL type from java.sql.Types
! *
- TYPE_NAME String => Data source dependent type name
! *
- COLUMN_SIZE int => column size. For char or date
! * types this is the maximum number of characters, for numeric or
! * decimal types this is precision.
! *
- BUFFER_LENGTH is not used.
! *
- DECIMAL_DIGITS int => the number of fractional digits
! *
- NUM_PREC_RADIX int => Radix (typically either 10 or 2)
! *
- NULLABLE int => is NULL allowed?
! *
! * - columnNoNulls - might not allow NULL values
! *
- columnNullable - definitely allows NULL values
! *
- columnNullableUnknown - nullability unknown
! *
! * - REMARKS String => comment describing column (may be null)
! *
- COLUMN_DEF String => default value (may be null)
! *
- SQL_DATA_TYPE int => unused
! *
- SQL_DATETIME_SUB int => unused
! *
- CHAR_OCTET_LENGTH int => for char types the
! * maximum number of bytes in the column
! *
- ORDINAL_POSITION int => index of column in table
! * (starting at 1)
! *
- IS_NULLABLE String => "NO" means column definitely
! * does not allow NULL values; "YES" means the column might
! * allow NULL values. An empty string means nobody knows.
! *
! *
! * @param catalog a catalog name; "" retrieves those without a catalog
! * @param schemaPattern a schema name pattern; "" retrieves those
! * without a schema
! * @param tableNamePattern a table name pattern
! * @param columnNamePattern a column name pattern
! * @return ResultSet each row is a column description
! * @see #getSearchStringEscape
! */
! public java.sql.ResultSet getColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) throws SQLException
! {
! Vector v = new Vector(); // The new ResultSet tuple stuff
! Field f[] = new Field[18]; // The field descriptors for the new ResultSet
!
! f[0] = new Field("TABLE_CAT", Oid.VARCHAR);
! f[1] = new Field("TABLE_SCHEM", Oid.VARCHAR);
! f[2] = new Field("TABLE_NAME", Oid.VARCHAR);
! f[3] = new Field("COLUMN_NAME", Oid.VARCHAR);
! f[4] = new Field("DATA_TYPE", Oid.INT2);
! f[5] = new Field("TYPE_NAME", Oid.VARCHAR);
! f[6] = new Field("COLUMN_SIZE", Oid.INT4);
! f[7] = new Field("BUFFER_LENGTH", Oid.VARCHAR);
! f[8] = new Field("DECIMAL_DIGITS", Oid.INT4);
! f[9] = new Field("NUM_PREC_RADIX", Oid.INT4);
! f[10] = new Field("NULLABLE", Oid.INT4);
! f[11] = new Field("REMARKS", Oid.VARCHAR);
! f[12] = new Field("COLUMN_DEF", Oid.VARCHAR);
! f[13] = new Field("SQL_DATA_TYPE", Oid.INT4);
! f[14] = new Field("SQL_DATETIME_SUB", Oid.INT4);
! f[15] = new Field("CHAR_OCTET_LENGTH", Oid.VARCHAR);
! f[16] = new Field("ORDINAL_POSITION", Oid.INT4);
! f[17] = new Field("IS_NULLABLE", Oid.VARCHAR);
!
String sql;
if (connection.haveMinimumServerVersion("7.3"))
{
--- 2202,2233 ----
return (ResultSet) ((BaseStatement)createMetaDataStatement()).createDriverResultSet(f, v);
}
!
! protected Vector getColumnsFieldDef() {
! Vector f = new Vector();
! f.addElement(new Field("TABLE_CAT", Oid.VARCHAR));
! f.addElement(new Field("TABLE_SCHEM", Oid.VARCHAR));
! f.addElement(new Field("TABLE_NAME", Oid.VARCHAR));
! f.addElement(new Field("COLUMN_NAME", Oid.VARCHAR));
! f.addElement(new Field("DATA_TYPE", Oid.INT2));
! f.addElement(new Field("TYPE_NAME", Oid.VARCHAR));
! f.addElement(new Field("COLUMN_SIZE", Oid.INT4));
! f.addElement(new Field("BUFFER_LENGTH", Oid.VARCHAR));
! f.addElement(new Field("DECIMAL_DIGITS", Oid.INT4));
! f.addElement(new Field("NUM_PREC_RADIX", Oid.INT4));
! f.addElement(new Field("NULLABLE", Oid.INT4));
! f.addElement(new Field("REMARKS", Oid.VARCHAR));
! f.addElement(new Field("COLUMN_DEF", Oid.VARCHAR));
! f.addElement(new Field("SQL_DATA_TYPE", Oid.INT4));
! f.addElement(new Field("SQL_DATETIME_SUB", Oid.INT4));
! f.addElement(new Field("CHAR_OCTET_LENGTH", Oid.VARCHAR));
! f.addElement(new Field("ORDINAL_POSITION", Oid.INT4));
! f.addElement(new Field("IS_NULLABLE", Oid.VARCHAR));
! return f;
! }
!
! protected Vector getColumnsValues(Field[] f, String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) throws SQLException {
! Vector v = new Vector();
String sql;
if (connection.haveMinimumServerVersion("7.3"))
{
***************
*** 2332,2338 ****
ResultSet rs = connection.createStatement().executeQuery(sql);
while (rs.next())
{
! byte[][] tuple = new byte[18][];
int typeOid = (int)rs.getLong("atttypid");
int typeMod = rs.getInt("atttypmod");
--- 2285,2291 ----
ResultSet rs = connection.createStatement().executeQuery(sql);
while (rs.next())
{
! byte[][] tuple = new byte[f.length][];
int typeOid = (int)rs.getLong("atttypid");
int typeMod = rs.getInt("atttypmod");
***************
*** 2392,2397 ****
--- 2345,2406 ----
}
rs.close();
+ return v;
+ }
+
+ /*
+ * Get a description of table columns available in a catalog.
+ *
+ * Only column descriptions matching the catalog, schema, table
+ * and column name criteria are returned. They are ordered by
+ * TABLE_SCHEM, TABLE_NAME and ORDINAL_POSITION.
+ *
+ *
Each column description has the following columns:
+ *
+ * - TABLE_CAT String => table catalog (may be null)
+ *
- TABLE_SCHEM String => table schema (may be null)
+ *
- TABLE_NAME String => table name
+ *
- COLUMN_NAME String => column name
+ *
- DATA_TYPE short => SQL type from java.sql.Types
+ *
- TYPE_NAME String => Data source dependent type name
+ *
- COLUMN_SIZE int => column size. For char or date
+ * types this is the maximum number of characters, for numeric or
+ * decimal types this is precision.
+ *
- BUFFER_LENGTH is not used.
+ *
- DECIMAL_DIGITS int => the number of fractional digits
+ *
- NUM_PREC_RADIX int => Radix (typically either 10 or 2)
+ *
- NULLABLE int => is NULL allowed?
+ *
+ * - columnNoNulls - might not allow NULL values
+ *
- columnNullable - definitely allows NULL values
+ *
- columnNullableUnknown - nullability unknown
+ *
+ * - REMARKS String => comment describing column (may be null)
+ *
- COLUMN_DEF String => default value (may be null)
+ *
- SQL_DATA_TYPE int => unused
+ *
- SQL_DATETIME_SUB int => unused
+ *
- CHAR_OCTET_LENGTH int => for char types the
+ * maximum number of bytes in the column
+ *
- ORDINAL_POSITION int => index of column in table
+ * (starting at 1)
+ *
- IS_NULLABLE String => "NO" means column definitely
+ * does not allow NULL values; "YES" means the column might
+ * allow NULL values. An empty string means nobody knows.
+ *
+ *
+ * @param catalog a catalog name; "" retrieves those without a catalog
+ * @param schemaPattern a schema name pattern; "" retrieves those
+ * without a schema
+ * @param tableNamePattern a table name pattern
+ * @param columnNamePattern a column name pattern
+ * @return ResultSet each row is a column description
+ * @see #getSearchStringEscape
+ */
+ public java.sql.ResultSet getColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) throws SQLException
+ {
+ Field[] f = (Field[]) getColumnsFieldDef().toArray(new Field[0]); // The field descriptors for the new ResultSet
+ Vector v = getColumnsValues(f, catalog, schemaPattern, tableNamePattern, columnNamePattern); // The new ResultSet tuple stuff
+
return (ResultSet) ((BaseStatement)createMetaDataStatement()).createDriverResultSet(f, v);
}
Index: org/postgresql/jdbc3/AbstractJdbc3DatabaseMetaData.java
===================================================================
RCS file: /cvsroot/jdbc/pgjdbc/org/postgresql/jdbc3/AbstractJdbc3DatabaseMetaData.java,v
retrieving revision 1.11
diff -c -r1.11 AbstractJdbc3DatabaseMetaData.java
*** org/postgresql/jdbc3/AbstractJdbc3DatabaseMetaData.java 15 Feb 2005 08:56:26 -0000 1.11
--- org/postgresql/jdbc3/AbstractJdbc3DatabaseMetaData.java 23 Dec 2007 23:12:41 -0000
***************
*** 3,9 ****
* Copyright (c) 2004-2005, PostgreSQL Global Development Group
*
* IDENTIFICATION
! * $PostgreSQL: pgjdbc/org/postgresql/jdbc3/AbstractJdbc3DatabaseMetaData.java,v 1.11 2005/02/15 08:56:26 jurka Exp $
*
*-------------------------------------------------------------------------
*/
--- 3,9 ----
* Copyright (c) 2004-2005, PostgreSQL Global Development Group
*
* IDENTIFICATION
! * $PostgreSQL: pgjdbc/org/postgresql/jdbc3/AbstractJdbc3DatabaseMetaData.java,v 1.10 2005/01/11 08:25:46 jurka Exp $
*
*-------------------------------------------------------------------------
*/
***************
*** 11,16 ****
--- 11,19 ----
import java.sql.*;
+ import java.util.Vector;
+ import org.postgresql.core.Field;
+ import org.postgresql.core.Oid;
public abstract class AbstractJdbc3DatabaseMetaData extends org.postgresql.jdbc2.AbstractJdbc2DatabaseMetaData
{
***************
*** 366,370 ****
{
return false;
}
!
}
--- 369,432 ----
{
return false;
}
!
! protected Vector getColumnsFieldDef() {
! Vector f = super.getColumnsFieldDef();
! f.add(new Field("SCOPE_CATLOG", Oid.VARCHAR));
! f.add(new Field("SCOPE_SCHEMA", Oid.VARCHAR));
! f.add(new Field("SCOPE_TABLE", Oid.VARCHAR));
! f.add(new Field("SOURCE_DATA_TYPE", Oid.INT2));
! return f;
! }
!
! protected Vector getColumnsValues(Field[] f, String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) throws SQLException {
! Vector v = super.getColumnsValues(f, catalog, schemaPattern, tableNamePattern, columnNamePattern);
! String sql;
! if (connection.haveMinimumServerVersion("7.3")) {
! sql = "SELECT t.typbasetype" +
! " FROM pg_catalog.pg_namespace n " +
! " JOIN pg_catalog.pg_class c ON (c.relnamespace = n.oid) " +
! " JOIN pg_catalog.pg_attribute a ON (a.attrelid = c.oid) " +
! " JOIN pg_catalog.pg_type t ON (a.atttypid = t.oid) " +
! " WHERE a.attnum > 0 AND NOT a.attisdropped ";
! if (schemaPattern != null && !"".equals(schemaPattern)) {
! sql += " AND n.nspname LIKE '" + escapeQuotes(schemaPattern) + "' ";
! }
! if (tableNamePattern != null && !"".equals(tableNamePattern))
! {
! sql += " AND c.relname LIKE '" + escapeQuotes(tableNamePattern) + "' ";
! }
! if (columnNamePattern != null && !"".equals(columnNamePattern))
! {
! sql += " AND a.attname LIKE '" + escapeQuotes(columnNamePattern) + "' ";
! }
! sql += " ORDER BY nspname,relname,attnum ";
! ResultSet rs = connection.createStatement().executeQuery(sql);
! int i = 0;
! while (rs.next()) {
! int baseTypeOid = (int) rs.getLong("typbasetype");
!
! byte[][] tuple = (byte[][]) v.get(i++);
! tuple[18] = null; // SCOPE_CATLOG
! tuple[19] = null; // SCOPE_SCHEMA
! tuple[20] = null; // SCOPE_TABLE
! tuple[21] = baseTypeOid == 0 ? null : connection.encodeString(Integer.toString(connection.getSQLType(baseTypeOid)));
! // SOURCE_DATA_TYPE
! }
! rs.close();
! }
! else {
! // Domains have been added in PostgreSQL 7.3 so we can simply leave the
! // additional fields null if we have an older server.
! for (int i = 0; i < v.size(); i++) {
! byte[][] tuple = (byte[][]) v.get(i);
! tuple[18] = null; // SCOPE_CATLOG
! tuple[19] = null; // SCOPE_SCHEMA
! tuple[20] = null; // SCOPE_TABLE
! tuple[21] = null; // SOURCE_DATA_TYPE
! }
! }
! return v;
! }
!
}