⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 databasemetadata.java

📁 Java写的TDS协议(JDBC/ODBC)实现
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
     *      <LI> importedKeyInitiallyDeferred - see SQL92 for definition
     *      <LI> importedKeyInitiallyImmediate - see SQL92 for definition
     *      <LI> importedKeyNotDeferrable - see SQL92 for definition
     *    </UL>
     *
     *  </OL>
     *
     *
     *@param  catalog           a catalog name; "" retrieves those without a
     *      catalog; null means drop catalog name from the selection criteria
     *@param  schema            a schema name pattern; "" retrieves those
     *      without a schema
     *@param  table             a table name
     *@return                   ResultSet - each row is a foreign key column
     *      description
     *@exception  SQLException  if a database-access error occurs.
     *@see                      #getImportedKeys
     */
    public java.sql.ResultSet getExportedKeys(
        String catalog,
        String schema,
        String table)
        throws SQLException
    {
        return getCrossReference(catalog, schema, table, null, null, null);
    }

    /**
     *  Get all the "extra" characters that can be used in unquoted identifier
     *  names (those beyond a-z, A-Z, 0-9 and _).
     *
     *@return                   the string containing the extra characters
     *@exception  SQLException  if a database-access error occurs.
     */
    public String getExtraNameCharacters() throws SQLException
    {
        // @todo Maybe add the extended set characters, too, to this list
        return "#$";
    }

    /**
     *  What's the string used to quote SQL identifiers? This returns a space "
     *  " if identifier quoting isn't supported. A JDBC-Compliant driver always
     *  uses a double quote character.
     *
     *@return                   the quoting string
     *@exception  SQLException  if a database-access error occurs.
     */
    public String getIdentifierQuoteString() throws SQLException
    {
        return "\"";
    }

    /**
     *  Get a description of the primary key columns that are referenced by a
     *  table's foreign key columns (the primary keys imported by a table). They
     *  are ordered by PKTABLE_CAT, PKTABLE_SCHEM, PKTABLE_NAME, and KEY_SEQ.
     *  <P>
     *
     *  Each primary key column description has the following columns:
     *  <OL>
     *    <LI> <B>PKTABLE_CAT</B> String =>primary key table catalog being
     *    imported (may be null)
     *    <LI> <B>PKTABLE_SCHEM</B> String =>primary key table schema being
     *    imported (may be null)
     *    <LI> <B>PKTABLE_NAME</B> String =>primary key table name being
     *    imported
     *    <LI> <B>PKCOLUMN_NAME</B> String =>primary key column name being
     *    imported
     *    <LI> <B>FKTABLE_CAT</B> String =>foreign key table catalog (may be
     *    null)
     *    <LI> <B>FKTABLE_SCHEM</B> String =>foreign key table schema (may be
     *    null)
     *    <LI> <B>FKTABLE_NAME</B> String =>foreign key table name
     *    <LI> <B>FKCOLUMN_NAME</B> String =>foreign key column name
     *    <LI> <B>KEY_SEQ</B> short =>sequence number within foreign key
     *    <LI> <B>UPDATE_RULE</B> short =>What happens to foreign key when
     *    primary is updated:
     *    <UL>
     *      <LI> importedNoAction - do not allow update of primary key if it has
     *      been imported
     *      <LI> importedKeyCascade - change imported key to agree with primary
     *      key update
     *      <LI> importedKeySetNull - change imported key to NULL if its primary
     *      key has been updated
     *      <LI> importedKeySetDefault - change imported key to default values
     *      if its primary key has been updated
     *      <LI> importedKeyRestrict - same as importedKeyNoAction (for ODBC 2.x
     *      compatibility)
     *    </UL>
     *
     *    <LI> <B>DELETE_RULE</B> short =>What happens to the foreign key when
     *    primary is deleted.
     *    <UL>
     *      <LI> importedKeyNoAction - do not allow delete of primary key if it
     *      has been imported
     *      <LI> importedKeyCascade - delete rows that import a deleted key
     *      <LI> importedKeySetNull - change imported key to NULL if its primary
     *      key has been deleted
     *      <LI> importedKeyRestrict - same as importedKeyNoAction (for ODBC 2.x
     *      compatibility)
     *      <LI> importedKeySetDefault - change imported key to default if its
     *      primary key has been deleted
     *    </UL>
     *
     *    <LI> <B>FK_NAME</B> String =>foreign key name (may be null)
     *    <LI> <B>PK_NAME</B> String =>primary key name (may be null)
     *    <LI> <B>DEFERRABILITY</B> short =>can the evaluation of foreign key
     *    constraints be deferred until commit
     *    <UL>
     *      <LI> importedKeyInitiallyDeferred - see SQL92 for definition
     *      <LI> importedKeyInitiallyImmediate - see SQL92 for definition
     *      <LI> importedKeyNotDeferrable - see SQL92 for definition
     *    </UL>
     *
     *  </OL>
     *
     *
     *@param  catalog           a catalog name; "" retrieves those without a
     *      catalog; null means drop catalog name from the selection criteria
     *@param  schema            a schema name pattern; "" retrieves those
     *      without a schema
     *@param  table             a table name
     *@return                   ResultSet - each row is a primary key column
     *      description
     *@exception  SQLException  if a database-access error occurs.
     *@see                      #getExportedKeys
     */
    public java.sql.ResultSet getImportedKeys(
        String catalog,
        String schema,
        String table)
        throws SQLException
    {
        return getCrossReference(null, null, null, catalog, schema, table);
    }

    /**
     *  Get a description of a table's indices and statistics. They are ordered
     *  by NON_UNIQUE, TYPE, INDEX_NAME, and ORDINAL_POSITION. <P>
     *
     *  Each index column 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_NAME</B> String =>table name
     *    <LI> <B>NON_UNIQUE</B> boolean =>Can index values be non-unique? false
     *    when TYPE is tableIndexStatistic
     *    <LI> <B>INDEX_QUALIFIER</B> String =>index catalog (may be null); null
     *    when TYPE is tableIndexStatistic
     *    <LI> <B>INDEX_NAME</B> String =>index name; null when TYPE is
     *    tableIndexStatistic
     *    <LI> <B>TYPE</B> short =>index type:
     *    <UL>
     *      <LI> tableIndexStatistic - this identifies table statistics that are
     *      returned in conjuction with a table's index descriptions
     *      <LI> tableIndexClustered - this is a clustered index
     *      <LI> tableIndexHashed - this is a hashed index
     *      <LI> tableIndexOther - this is some other style of index
     *    </UL>
     *
     *    <LI> <B>ORDINAL_POSITION</B> short =>column sequence number within
     *    index; zero when TYPE is tableIndexStatistic
     *    <LI> <B>COLUMN_NAME</B> String =>column name; null when TYPE is
     *    tableIndexStatistic
     *    <LI> <B>ASC_OR_DESC</B> String =>column sort sequence, "A" =>
     *    ascending, "D" =>descending, may be null if sort sequence is not
     *    supported; null when TYPE is tableIndexStatistic
     *    <LI> <B>CARDINALITY</B> int =>When TYPE is tableIndexStatistic, then
     *    this is the number of rows in the table; otherwise, it is the number
     *    of unique values in the index.
     *    <LI> <B>PAGES</B> int =>When TYPE is tableIndexStatisic then this is
     *    the number of pages used for the table, otherwise it is the number of
     *    pages used for the current index.
     *    <LI> <B>FILTER_CONDITION</B> String =>Filter condition, if any. (may
     *    be null)
     *  </OL>
     *
     *
     *@param  catalog           a catalog name; "" retrieves those without a
     *      catalog; null means drop catalog name from the selection criteria
     *@param  schema            a schema name pattern; "" retrieves those
     *      without a schema
     *@param  table             a table name
     *@param  unique            when true, return only indices for unique
     *      values; when false, return indices regardless of whether unique or
     *      not
     *@param  approximate       when true, result is allowed to reflect
     *      approximate or out of data values; when false, results are requested
     *      to be accurate
     *@return                   ResultSet - each row is an index column
     *      description
     *@exception  SQLException  if a database-access error occurs.
     */
    public java.sql.ResultSet getIndexInfo(
        String catalog,
        String schema,
        String table,
        boolean unique,
        boolean approximate)
        throws SQLException
    {
        String query = "exec sp_statistics ?, ?, ?, ?, ?";
        if( catalog != null )
            query = "exec "+catalog+"..sp_statistics ?, ?, ?, ?, ?";

        CallableStatement s = connection.prepareCall(query);
        s.setString(1, table);
        s.setString(2, schema);
        s.setString(3, catalog);
        s.setString(4, unique ? "Y" : "N");
        s.setString(5, approximate ? "Q" : "E");

        TdsResultSet rs = (TdsResultSet)s.executeQuery();
        Columns col = rs.getContext().getColumnInfo();

        col.setName(1, "TABLE_CAT");
        col.setLabel(1, "TABLE_CAT");
        col.setName(2, "TABLE_SCHEM");
        col.setLabel(2, "TABLE_SCHEM");
        col.setName(8, "ORDINAL_POSITION");
        col.setLabel(8, "ORDINAL_POSITION");
        col.setName(10, "ASC_OR_DESC");
        col.setLabel(10, "ASC_OR_DESC");

        return rs;
    }

    //----------------------------------------------------------------------
    // The following group of methods exposes various limitations
    // based on the target database with the current driver.
    // Unless otherwise specified, a result of zero means there is no
    // limit, or the limit is not known.

    /**
     *  How many hex characters can you have in an inline binary literal?
     *
     *@return                   max literal length
     *@exception  SQLException  if a database-access error occurs.
     */
    public int getMaxBinaryLiteralLength() throws SQLException
    {
        // XXX Need to check for Sybase and SQLServer 7.0

        return 131072;
        // per "Programming ODBC for SQLServer" Appendix A
    }

    /**
     *  What's the maximum length of a catalog name?
     *
     *@return                   max name length in bytes
     *@exception  SQLException  if a database-access error occurs.
     */
    public int getMaxCatalogNameLength() throws SQLException
    {
        return sysnameLength;
    }

    /**
     *  What's the max length for a character literal?
     *
     *@return                   max literal length
     *@exception  SQLException  if a database-access error occurs.
     */
    public int getMaxCharLiteralLength() throws SQLException
    {
        // XXX Need to check for Sybase

        return 131072;
        // per "Programming ODBC for SQLServer" Appendix A
    }

    /**
     *  What's the limit on column name length?
     *
     *@return                   max literal length
     *@exception  SQLException  if a database-access error occurs.
     */
    public int getMaxColumnNameLength() throws SQLException
    {
        // XXX Need to check for Sybase

        return sysnameLength; // per "Programming ODBC for SQLServer" Appendix A
        // per "Programming ODBC for SQLServer" Appendix A
    }

    /**
     *  What's the maximum number of columns in a "GROUP BY" clause?
     *
     *@return                   max number of columns
     *@exception  SQLException  if a database-access error occurs.
     */
    public int getMaxColumnsInGroupBy() throws SQLException
    {
        // XXX Need to check for Sybase

        return 16;
        // per "Programming ODBC for SQLServer" Appendix A
    }

    /**
     *  What's the maximum number of columns allowed in an index?
     *
     *@return                   max columns
     *@exception  SQLException  if a database-access error occurs.
     */
    public int getMaxColumnsInIndex() throws SQLException
    {
        // XXX need to find out if this is still true for SYBASE

        // per SQL Server Books Online "Administrator's Companion",
        // Part 1, Chapter 1.
        return 16;
    }

    /**
     *  What's the maximum number of columns in an "ORDER BY" clause?
     *
     *@return                   max columns
     *@exception  SQLException  if a database-access error occurs.
     */
    public int getMaxColumnsInOrderBy() throws SQLException
    {
        // XXX Need to check for Sybase

        return 16;
        // per "Programming ODBC for SQLServer" Appendix A
    }

    /**
     *  What's the maximum number of columns in a "SELECT" list?
     *
     *@return                   max columns
     *@exception  SQLException  if a database-access error occurs.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -