columnmetadata.java

来自「derby database source code.good for you.」· Java 代码 · 共 926 行 · 第 1/3 页

JAVA
926
字号
        switch (jdbcType) {        case java.sql.Types.NUMERIC:        case Types.DECIMAL:            return sqlPrecision_[column - 1];        case Types.SMALLINT:            return 5;        case Types.INTEGER:            return 10;        case Types.BIGINT:            return 19;        case java.sql.Types.FLOAT:            return 15;        case Types.REAL:            return 7;  // This is the number of signed digits for IEEE float with mantissa 24, ie. 2^24        case Types.DOUBLE:            return 15; // This is the number of signed digits for IEEE float with mantissa 24, ie. 2^24        case Types.CHAR:        case Types.VARCHAR:        case Types.LONGVARCHAR:        case Types.BINARY:        case Types.VARBINARY:        case Types.LONGVARBINARY:        case Types.CLOB:        case Types.BLOB:            return (int) sqlLength_[column - 1];        case Types.DATE:            return 10;        case Types.TIME:            return 8;        case Types.TIMESTAMP:            return 26;        default:            throw new SqlException(logWriter_, "Unregistered column type");        }    }    public int getScale(int column) throws SqlException {        checkForClosedStatement();        checkForValidColumnIndex(column);        // We get the scale from the SQLDA as returned by DERBY, but DERBY does not return the ANSI-defined        // value of scale 6 for TIMESTAMP.        //        //   The JDBC drivers should hardcode this info as a short/near term solution.        //        if (types_[column - 1] == Types.TIMESTAMP) {            return 6;        }        return sqlScale_[column - 1];    }    public String getTableName(int column) throws SqlException {        checkForClosedStatement();        checkForValidColumnIndex(column);        if (sqlxBasename_ == null || sqlxBasename_[column - 1] == null) {            return ""; // Per jdbc spec        }        return sqlxBasename_[column - 1];    }    /**     * What's a column's table's catalog name?     *     * @param column the first column is 1, the second is 2, ...     *     * @return column name or "" if not applicable.     *     * @throws SQLException thrown on failure     */    public String getCatalogName(int column) throws SqlException {        checkForClosedStatement();        checkForValidColumnIndex(column);        return "";    }    public int getColumnType(int column) throws SqlException {        checkForClosedStatement();        checkForValidColumnIndex(column);        return types_[column - 1];    }    public String getColumnTypeName(int column) throws SqlException {        checkForClosedStatement();        checkForValidColumnIndex(column);        int jdbcType = types_[column - 1];        // So these all come back zero for downlevel servers in PROTOCOL.        // John is going to write some code to construct the sqlType_ array        // based on the protocol types from the query descriptor.        int sqlType = sqlType_[column - 1];        switch (sqlType) {        case Types.DERBY_SQLTYPE_DATE:        case Types.DERBY_SQLTYPE_NDATE:            return "DATE";        case Types.DERBY_SQLTYPE_TIME:        case Types.DERBY_SQLTYPE_NTIME:            return "TIME";        case Types.DERBY_SQLTYPE_TIMESTAMP:        case Types.DERBY_SQLTYPE_NTIMESTAMP:            return "TIMESTAMP";        case Types.DERBY_SQLTYPE_BLOB:        case Types.DERBY_SQLTYPE_NBLOB:            return "BLOB";        case Types.DERBY_SQLTYPE_CLOB:        case Types.DERBY_SQLTYPE_NCLOB:            return "CLOB";        case Types.DERBY_SQLTYPE_VARCHAR:        case Types.DERBY_SQLTYPE_NVARCHAR:            if (jdbcType == Types.VARBINARY) {                return "VARCHAR FOR BIT DATA";            } else {                return "VARCHAR";            }        case Types.DERBY_SQLTYPE_CHAR:        case Types.DERBY_SQLTYPE_NCHAR:            if (jdbcType == Types.BINARY) {                return "CHAR FOR BIT DATA";            } else {                return "CHAR";            }        case Types.DERBY_SQLTYPE_LONG:        case Types.DERBY_SQLTYPE_NLONG:            if (jdbcType == Types.LONGVARBINARY) {                return "LONG VARCHAR FOR BIT DATA";            } else {                return "LONG VARCHAR";            }        case Types.DERBY_SQLTYPE_CSTR:        case Types.DERBY_SQLTYPE_NCSTR:            return "SBCS";        case Types.DERBY_SQLTYPE_FLOAT:        case Types.DERBY_SQLTYPE_NFLOAT:            if (jdbcType == Types.DOUBLE) {                return "DOUBLE";            }            if (jdbcType == Types.REAL) {                return "REAL";            }        case Types.DERBY_SQLTYPE_DECIMAL:        case Types.DERBY_SQLTYPE_NDECIMAL:            return "DECIMAL";        case Types.DERBY_SQLTYPE_BIGINT:        case Types.DERBY_SQLTYPE_NBIGINT:            return "BIGINT";        case Types.DERBY_SQLTYPE_INTEGER:        case Types.DERBY_SQLTYPE_NINTEGER:            return "INTEGER";        case Types.DERBY_SQLTYPE_SMALL:        case Types.DERBY_SQLTYPE_NSMALL:            return "SMALLINT";        case Types.DERBY_SQLTYPE_NUMERIC:        case Types.DERBY_SQLTYPE_NNUMERIC:            return "NUMERIC";        default:            throw new SqlException(logWriter_, "Not supported");        }    }    public boolean isReadOnly(int column) throws SqlException {        checkForClosedStatement();        checkForValidColumnIndex(column);        if (sqlxUpdatable_ == null) {            return (resultSetConcurrency_ == java.sql.ResultSet.CONCUR_READ_ONLY); // If no extended describe, return resultSet's concurrecnty        }        return sqlxUpdatable_[column - 1] == 0; // PROTOCOL 0 means not updatable, 1 means updatable    }    public boolean isWritable(int column) throws SqlException {        checkForClosedStatement();        checkForValidColumnIndex(column);        if (sqlxUpdatable_ == null) {            return (resultSetConcurrency_ == java.sql.ResultSet.CONCUR_UPDATABLE); // If no extended describe, return resultSet's concurrency        }        return sqlxUpdatable_[column - 1] == 1; // PROTOCOL 0 means not updatable, 1 means updatable    }    public boolean isDefinitelyWritable(int column) throws SqlException {        checkForClosedStatement();        checkForValidColumnIndex(column);        if (sqlxUpdatable_ == null) {            return false;        }        return sqlxUpdatable_[column - 1] == 1; // PROTOCOL 0 means not updatable, 1 means updatable    }    //--------------------------jdbc 2.0-----------------------------------    public String getColumnClassName(int column) throws SqlException {        checkForClosedStatement();        checkForValidColumnIndex(column);        int jdbcType = types_[column - 1];        switch (jdbcType) {        case java.sql.Types.BIT:            return "java.lang.Boolean";        case java.sql.Types.TINYINT:            return "java.lang.Integer";        case Types.SMALLINT:            return "java.lang.Integer";        case Types.INTEGER:            return "java.lang.Integer";        case Types.BIGINT:            return "java.lang.Long";        case java.sql.Types.FLOAT:            return "java.lang.Double";        case Types.REAL:            return "java.lang.Float";        case Types.DOUBLE:            return "java.lang.Double";        case java.sql.Types.NUMERIC:        case Types.DECIMAL:            return "java.math.BigDecimal";        case Types.CHAR:        case Types.VARCHAR:        case Types.LONGVARCHAR:            return "java.lang.String";        case Types.DATE:            return "java.sql.Date";        case Types.TIME:            return "java.sql.Time";        case Types.TIMESTAMP:            return "java.sql.Timestamp";        case Types.BINARY:        case Types.VARBINARY:        case Types.LONGVARBINARY:            return "byte[]";        case java.sql.Types.STRUCT:            return "java.sql.Struct";        case java.sql.Types.ARRAY:            return "java.sql.Array";        case Types.BLOB:            return "java.sql.Blob";        case Types.CLOB:            return "java.sql.Clob";        case java.sql.Types.REF:            return "java.sql.Ref";        default:            throw new SqlException(logWriter_, "Not supported");        }    }    //----------------------------helper methods----------------------------------    void checkForValidColumnIndex(int column) throws SqlException {        if (column < 1 || column > columns_) {            throw new SqlException(logWriter_, "Invalid argument: column index " +                    column + " is out of range.");        }    }    // If the input parameter has been set, return true, else return false.    private boolean isParameterModeGuessedAsAnInput(int parameterIndex) {        if (sqlxParmmode_[parameterIndex - 1] == java.sql.ParameterMetaData.parameterModeIn ||                sqlxParmmode_[parameterIndex - 1] == java.sql.ParameterMetaData.parameterModeInOut) {            return true;        }        return false;    }    // Does OUT parm registration rely on extended describe?    // If the output parameter has been registered, return true, else return false.    public boolean isParameterModeGuessedAsOutput(int parameterIndex) {        return sqlxParmmode_[parameterIndex - 1] >= java.sql.ParameterMetaData.parameterModeInOut;    }    // Only called when column meta data is not described. Called by setXXX methods.    public void guessInputParameterMetaData(int parameterIndex,                                            int jdbcType) throws SqlException {        guessInputParameterMetaData(parameterIndex, jdbcType, 0);    }    private void setParmModeForInputParameter(int parameterIndex) {        if (sqlxParmmode_[parameterIndex - 1] == java.sql.ParameterMetaData.parameterModeOut) {            sqlxParmmode_[parameterIndex - 1] = java.sql.ParameterMetaData.parameterModeInOut;        } else if (sqlxParmmode_[parameterIndex - 1] == java.sql.ParameterMetaData.parameterModeUnknown) {            sqlxParmmode_[parameterIndex - 1] = java.sql.ParameterMetaData.parameterModeIn;        }    }    // Only called when column meta data is not described. Called by setXXX methods.    // Scale is only applied for Decimal or Numeric JDBC type.    public void guessInputParameterMetaData(int parameterIndex,                                            int jdbcType,                                            int scale) throws SqlException {        setParmModeForInputParameter(parameterIndex);        int driverType = getInternalTypeForGuessedOrRegisteredJdbcType(jdbcType);        // if output parameter has been registered already        if (isParameterModeGuessedAsOutput(parameterIndex)) {            if (!isCompatibleDriverTypes(types_[parameterIndex - 1], driverType)) {                throw new SqlException(logWriter_, "The jdbcType " + jdbcType + " does not match between the setter method and " +                        "the registerOutParameter method.");            } else {                return; // don't bother guessing if the parameter was already registered            }        }        guessParameterMetaDataBasedOnSupportedDriverType(parameterIndex, jdbcType == java.sql.Types.BIGINT, driverType, scale);    }    private void setParmModeForOutputParameter(int parameterIndex) {        if (sqlxParmmode_[parameterIndex - 1] == java.sql.ParameterMetaData.parameterModeIn) {            sqlxParmmode_[parameterIndex - 1] = java.sql.ParameterMetaData.parameterModeInOut;        } else if (sqlxParmmode_[parameterIndex - 1] == java.sql.ParameterMetaData.parameterModeUnknown) {            sqlxParmmode_[parameterIndex - 1] = java.sql.ParameterMetaData.parameterModeOut;        }

⌨️ 快捷键说明

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