Class PgResultSetMetaData

  • All Implemented Interfaces:
    java.sql.ResultSetMetaData, java.sql.Wrapper, PGResultSetMetaData

    public class PgResultSetMetaData
    extends java.lang.Object
    implements java.sql.ResultSetMetaData, PGResultSetMetaData
    • Constructor Detail

      • PgResultSetMetaData

        public PgResultSetMetaData​(BaseConnection connection,
                                   Field[] fields)
        Initialise for a result with a tuple set and a field descriptor set
        Parameters:
        connection - the connection to retrieve metadata
        fields - the array of field descriptors
    • Method Detail

      • getColumnCount

        public int getColumnCount()
                           throws java.sql.SQLException
        Specified by:
        getColumnCount in interface java.sql.ResultSetMetaData
        Throws:
        java.sql.SQLException
      • isAutoIncrement

        public boolean isAutoIncrement​(int column)
                                throws java.sql.SQLException

        It is believed that PostgreSQL does not support this feature.

        Specified by:
        isAutoIncrement in interface java.sql.ResultSetMetaData
        Parameters:
        column - the first column is 1, the second is 2...
        Returns:
        true if so
        Throws:
        java.sql.SQLException - if a database access error occurs
      • isCaseSensitive

        public boolean isCaseSensitive​(int column)
                                throws java.sql.SQLException

        Does a column's case matter? ASSUMPTION: Any field that is not obviously case insensitive is assumed to be case sensitive

        Specified by:
        isCaseSensitive in interface java.sql.ResultSetMetaData
        Parameters:
        column - the first column is 1, the second is 2...
        Returns:
        true if so
        Throws:
        java.sql.SQLException - if a database access error occurs
      • isSearchable

        public boolean isSearchable​(int column)
                             throws java.sql.SQLException

        Can the column be used in a WHERE clause? Basically for this, I split the functions into two types: recognised types (which are always useable), and OTHER types (which may or may not be useable). The OTHER types, for now, I will assume they are useable. We should really query the catalog to see if they are useable.

        Specified by:
        isSearchable in interface java.sql.ResultSetMetaData
        Parameters:
        column - the first column is 1, the second is 2...
        Returns:
        true if they can be used in a WHERE clause
        Throws:
        java.sql.SQLException - if a database access error occurs
      • isCurrency

        public boolean isCurrency​(int column)
                           throws java.sql.SQLException

        Is the column a cash value? 6.1 introduced the cash/money type, which haven't been incorporated as of 970414, so I just check the type name for both 'cash' and 'money'

        Specified by:
        isCurrency in interface java.sql.ResultSetMetaData
        Parameters:
        column - the first column is 1, the second is 2...
        Returns:
        true if its a cash column
        Throws:
        java.sql.SQLException - if a database access error occurs
      • isNullable

        public int isNullable​(int column)
                       throws java.sql.SQLException
        Specified by:
        isNullable in interface java.sql.ResultSetMetaData
        Throws:
        java.sql.SQLException
      • isSigned

        public boolean isSigned​(int column)
                         throws java.sql.SQLException

        Is the column a signed number? In PostgreSQL, all numbers are signed, so this is trivial. However, strings are not signed (duh!)

        Specified by:
        isSigned in interface java.sql.ResultSetMetaData
        Parameters:
        column - the first column is 1, the second is 2...
        Returns:
        true if so
        Throws:
        java.sql.SQLException - if a database access error occurs
      • getColumnDisplaySize

        public int getColumnDisplaySize​(int column)
                                 throws java.sql.SQLException
        Specified by:
        getColumnDisplaySize in interface java.sql.ResultSetMetaData
        Throws:
        java.sql.SQLException
      • getColumnLabel

        public java.lang.String getColumnLabel​(int column)
                                        throws java.sql.SQLException
        Specified by:
        getColumnLabel in interface java.sql.ResultSetMetaData
        Throws:
        java.sql.SQLException
      • getColumnName

        public java.lang.String getColumnName​(int column)
                                       throws java.sql.SQLException
        Specified by:
        getColumnName in interface java.sql.ResultSetMetaData
        Throws:
        java.sql.SQLException
      • getBaseColumnName

        public java.lang.String getBaseColumnName​(int column)
                                           throws java.sql.SQLException
        Description copied from interface: PGResultSetMetaData
        Returns the underlying column name of a query result, or "" if it is unable to be determined.
        Specified by:
        getBaseColumnName in interface PGResultSetMetaData
        Parameters:
        column - column position (1-based)
        Returns:
        underlying column name of a query result
        Throws:
        java.sql.SQLException - if something wrong happens
      • getSchemaName

        public java.lang.String getSchemaName​(int column)
                                       throws java.sql.SQLException
        Specified by:
        getSchemaName in interface java.sql.ResultSetMetaData
        Throws:
        java.sql.SQLException
      • getBaseSchemaName

        public java.lang.String getBaseSchemaName​(int column)
                                           throws java.sql.SQLException
        Description copied from interface: PGResultSetMetaData
        Returns the underlying schema name of query result, or "" if it is unable to be determined.
        Specified by:
        getBaseSchemaName in interface PGResultSetMetaData
        Parameters:
        column - column position (1-based)
        Returns:
        underlying schema name of query result
        Throws:
        java.sql.SQLException - if something wrong happens
      • getPrecision

        public int getPrecision​(int column)
                         throws java.sql.SQLException
        Specified by:
        getPrecision in interface java.sql.ResultSetMetaData
        Throws:
        java.sql.SQLException
      • getScale

        public int getScale​(int column)
                     throws java.sql.SQLException
        Specified by:
        getScale in interface java.sql.ResultSetMetaData
        Throws:
        java.sql.SQLException
      • getTableName

        public java.lang.String getTableName​(int column)
                                      throws java.sql.SQLException
        Specified by:
        getTableName in interface java.sql.ResultSetMetaData
        Throws:
        java.sql.SQLException
      • getBaseTableName

        public java.lang.String getBaseTableName​(int column)
                                          throws java.sql.SQLException
        Description copied from interface: PGResultSetMetaData
        Returns the underlying table name of query result, or "" if it is unable to be determined.
        Specified by:
        getBaseTableName in interface PGResultSetMetaData
        Parameters:
        column - column position (1-based)
        Returns:
        underlying table name of query result
        Throws:
        java.sql.SQLException - if something wrong happens
      • getCatalogName

        public java.lang.String getCatalogName​(int column)
                                        throws java.sql.SQLException

        As with getSchemaName(), we can say that if getTableName() returns n/a, then we can too - otherwise, we need to work on it.

        Specified by:
        getCatalogName in interface java.sql.ResultSetMetaData
        Parameters:
        column - the first column is 1, the second is 2...
        Returns:
        catalog name, or "" if not applicable
        Throws:
        java.sql.SQLException - if a database access error occurs
      • getColumnType

        public int getColumnType​(int column)
                          throws java.sql.SQLException
        Specified by:
        getColumnType in interface java.sql.ResultSetMetaData
        Throws:
        java.sql.SQLException
      • getFormat

        public int getFormat​(int column)
                      throws java.sql.SQLException
        Description copied from interface: PGResultSetMetaData
        Is a column Text or Binary?
        Specified by:
        getFormat in interface PGResultSetMetaData
        Parameters:
        column - column position (1-based)
        Returns:
        0 if column data foramt is TEXT, or 1 if BINARY
        Throws:
        java.sql.SQLException - if something wrong happens
        See Also:
        Field.BINARY_FORMAT, Field.TEXT_FORMAT
      • getColumnTypeName

        public java.lang.String getColumnTypeName​(int column)
                                           throws java.sql.SQLException
        Specified by:
        getColumnTypeName in interface java.sql.ResultSetMetaData
        Throws:
        java.sql.SQLException
      • isReadOnly

        public boolean isReadOnly​(int column)
                           throws java.sql.SQLException

        In reality, we would have to check the GRANT/REVOKE stuff for this to be effective, and I haven't really looked into that yet, so this will get re-visited.

        Specified by:
        isReadOnly in interface java.sql.ResultSetMetaData
        Parameters:
        column - the first column is 1, the second is 2, etc.*
        Returns:
        true if so*
        Throws:
        java.sql.SQLException - if a database access error occurs
      • isWritable

        public boolean isWritable​(int column)
                           throws java.sql.SQLException

        In reality have to check the GRANT/REVOKE stuff, which I haven't worked with as yet. However, if it isn't ReadOnly, then it is obviously writable.

        Specified by:
        isWritable in interface java.sql.ResultSetMetaData
        Parameters:
        column - the first column is 1, the second is 2, etc.
        Returns:
        true if so
        Throws:
        java.sql.SQLException - if a database access error occurs
      • isDefinitelyWritable

        public boolean isDefinitelyWritable​(int column)
                                     throws java.sql.SQLException

        Hmmm...this is a bad one, since the two preceding functions have not been really defined. I cannot tell is the short answer. I thus return isWritable() just to give us an idea.

        Specified by:
        isDefinitelyWritable in interface java.sql.ResultSetMetaData
        Parameters:
        column - the first column is 1, the second is 2, etc..
        Returns:
        true if so
        Throws:
        java.sql.SQLException - if a database access error occurs
      • getField

        protected Field getField​(int columnIndex)
                          throws java.sql.SQLException
        For several routines in this package, we need to convert a columnIndex into a Field[] descriptor. Rather than do the same code several times, here it is.
        Parameters:
        columnIndex - the first column is 1, the second is 2...
        Returns:
        the Field description
        Throws:
        java.sql.SQLException - if a database access error occurs
      • getPGType

        protected java.lang.String getPGType​(int columnIndex)
                                      throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • getSQLType

        protected int getSQLType​(int columnIndex)
                          throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • getColumnClassName

        public java.lang.String getColumnClassName​(int column)
                                            throws java.sql.SQLException
        Specified by:
        getColumnClassName in interface java.sql.ResultSetMetaData
        Throws:
        java.sql.SQLException
      • isWrapperFor

        public boolean isWrapperFor​(java.lang.Class<?> iface)
                             throws java.sql.SQLException
        Specified by:
        isWrapperFor in interface java.sql.Wrapper
        Throws:
        java.sql.SQLException
      • unwrap

        public <T> T unwrap​(java.lang.Class<T> iface)
                     throws java.sql.SQLException
        Specified by:
        unwrap in interface java.sql.Wrapper
        Throws:
        java.sql.SQLException