Search in sources :

Example 11 with RowDescriptorBuilder

use of org.firebirdsql.gds.ng.fields.RowDescriptorBuilder in project jaybird by FirebirdSQL.

the class FBDatabaseMetaData method getColumnPrivileges.

/**
 * Gets a description of the access rights for a table's columns.
 *
 * <P>Only privileges matching the column name criteria are
 * returned.  They are ordered by COLUMN_NAME and PRIVILEGE.
 *
 * <P>Each privilige 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>COLUMN_NAME</B> String => column name
 *  <LI><B>GRANTOR</B> => grantor of access (may be null)
 *  <LI><B>GRANTEE</B> String => grantee of access
 *  <LI><B>PRIVILEGE</B> String => name of access (SELECT,
 *      INSERT, UPDATE, REFRENCES, ...)
 *  <LI><B>IS_GRANTABLE</B> String => "YES" if grantee is permitted
 *      to grant to others; "NO" if not; null if unknown
 *  </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; "" retrieves those without a schema
 * @param table a table name
 * @param columnNamePattern a column name pattern
 * @return <code>ResultSet</code> - each row is a column privilege description
 * @exception SQLException if a database access error occurs
 * @see #getSearchStringEscape
 */
public ResultSet getColumnPrivileges(String catalog, String schema, String table, String columnNamePattern) throws SQLException {
    final RowDescriptor rowDescriptor = new RowDescriptorBuilder(8, datatypeCoder).at(0).simple(SQL_VARYING, OBJECT_NAME_LENGTH, "TABLE_CAT", "COLUMNPRIV").addField().at(1).simple(SQL_VARYING, OBJECT_NAME_LENGTH, "TABLE_SCHEM", "COLUMNPRIV").addField().at(2).simple(SQL_VARYING, OBJECT_NAME_LENGTH, "TABLE_NAME", "COLUMNPRIV").addField().at(3).simple(SQL_VARYING, OBJECT_NAME_LENGTH, "COLUMN_NAME", "COLUMNPRIV").addField().at(4).simple(SQL_VARYING, OBJECT_NAME_LENGTH, "GRANTOR", "COLUMNPRIV").addField().at(5).simple(SQL_VARYING, OBJECT_NAME_LENGTH, "GRANTEE", "COLUMNPRIV").addField().at(6).simple(SQL_VARYING, 31, "PRIVILEGE", "COLUMNPRIV").addField().at(7).simple(SQL_VARYING, 31, "IS_GRANTABLE", "COLUMNPRIV").addField().toRowDescriptor();
    Clause columnClause = new Clause("RF.RDB$FIELD_NAME", columnNamePattern);
    String sql = GET_COLUMN_PRIVILEGES_START;
    sql += columnClause.getCondition();
    sql += GET_COLUMN_PRIVILEGES_END;
    List<String> params = new ArrayList<>(2);
    params.add(table);
    if (columnClause.hasCondition()) {
        params.add(columnClause.getValue());
    }
    try (ResultSet rs = doQuery(sql, params)) {
        // return empty result set
        if (!rs.next()) {
            return new FBResultSet(rowDescriptor, Collections.<RowValue>emptyList());
        }
        final List<RowValue> rows = new ArrayList<>();
        final RowValueBuilder valueBuilder = new RowValueBuilder(rowDescriptor);
        do {
            rows.add(valueBuilder.at(2).set(getBytes(rs.getString("TABLE_NAME"))).at(3).set(getBytes(rs.getString("COLUMN_NAME"))).at(4).set(getBytes(rs.getString("GRANTOR"))).at(5).set(getBytes(rs.getString("GRANTEE"))).at(6).set(mapPrivilege(rs.getString("PRIVILEGE"))).at(7).set(rs.getShort("IS_GRANTABLE") == 0 ? NO_BYTES : YES_BYTES).toRowValue(true));
        } while (rs.next());
        return new FBResultSet(rowDescriptor, rows);
    }
}
Also used : RowDescriptorBuilder(org.firebirdsql.gds.ng.fields.RowDescriptorBuilder) RowValueBuilder(org.firebirdsql.gds.ng.fields.RowValueBuilder) RowValue(org.firebirdsql.gds.ng.fields.RowValue) RowDescriptor(org.firebirdsql.gds.ng.fields.RowDescriptor)

Example 12 with RowDescriptorBuilder

use of org.firebirdsql.gds.ng.fields.RowDescriptorBuilder in project jaybird by FirebirdSQL.

the class FBDatabaseMetaData method getProcedures.

/**
 * Gets a description of the stored procedures available in a
 * catalog.
 *
 * <P>Only procedure descriptions matching the schema and
 * procedure name criteria are returned.  They are ordered by
 * PROCEDURE_SCHEM, and PROCEDURE_NAME.
 *
 * <P>Each procedure description has the the following columns:
 *  <OL>
 *  <LI><B>PROCEDURE_CAT</B> String => procedure catalog (may be null)
 *  <LI><B>PROCEDURE_SCHEM</B> String => procedure schema (may be null)
 *  <LI><B>PROCEDURE_NAME</B> String => procedure name
 *  <LI> reserved for future use
 *  <LI> reserved for future use
 *  <LI> reserved for future use
 *  <LI><B>REMARKS</B> String => explanatory comment on the procedure
 *  <LI><B>PROCEDURE_TYPE</B> short => kind of procedure:
 *      <UL>
 *      <LI> procedureResultUnknown - May return a result
 *      <LI> procedureNoResult - Does not return a result
 *      <LI> procedureReturnsResult - Returns a result
 *      </UL>
 *  <LI><B>SPECIFIC_NAME</B> String => The name which uniquely identifies this procedure within its schema.
 *  </OL>
 *
 * @param catalog a catalog name; "" retrieves those without a
 * catalog; null means drop catalog name from the selection criteria
 * @param schemaPattern a schema name pattern; "" retrieves those
 * without a schema
 * @param procedureNamePattern a procedure name pattern
 * @return <code>ResultSet</code> - each row is a procedure description
 * @exception SQLException if a database access error occurs
 * @see #getSearchStringEscape
 */
public ResultSet getProcedures(String catalog, String schemaPattern, String procedureNamePattern) throws SQLException {
    final RowDescriptor rowDescriptor = new RowDescriptorBuilder(9, datatypeCoder).at(0).simple(SQL_VARYING, OBJECT_NAME_LENGTH, "PROCEDURE_CAT", "PROCEDURES").addField().at(1).simple(SQL_VARYING, OBJECT_NAME_LENGTH, "PROCEDURE_SCHEM", "ROCEDURES").addField().at(2).simple(SQL_VARYING, OBJECT_NAME_LENGTH, "PROCEDURE_NAME", "PROCEDURES").addField().at(3).simple(SQL_VARYING, 31, "FUTURE1", "PROCEDURES").addField().at(4).simple(SQL_VARYING, 31, "FUTURE2", "PROCEDURES").addField().at(5).simple(SQL_VARYING, 31, "FUTURE3", "PROCEDURES").addField().at(6).simple(SQL_VARYING, Integer.MAX_VALUE, "REMARKS", "PROCEDURES").addField().at(7).simple(SQL_SHORT, 0, "PROCEDURE_TYPE", "PROCEDURES").addField().at(8).simple(SQL_VARYING, OBJECT_NAME_LENGTH, "SPECIFIC_NAME", "PROCEDURES").addField().toRowDescriptor();
    Clause procedureClause = new Clause("RDB$PROCEDURE_NAME", procedureNamePattern);
    String sql = GET_PROCEDURES_START;
    sql += procedureClause.getCondition();
    sql += GET_PROCEDURES_END;
    List<String> params = procedureClause.hasCondition() ? Collections.singletonList(procedureClause.getValue()) : Collections.<String>emptyList();
    try (ResultSet rs = doQuery(sql, params)) {
        if (!rs.next()) {
            return new FBResultSet(rowDescriptor, Collections.<RowValue>emptyList());
        }
        final List<RowValue> rows = new ArrayList<>();
        final RowValueBuilder valueBuilder = new RowValueBuilder(rowDescriptor);
        do {
            rows.add(valueBuilder.at(2).set(getBytes(rs.getString("PROCEDURE_NAME"))).at(6).set(getBytes(rs.getString("REMARKS"))).at(7).set(rs.getShort("PROCEDURE_TYPE") == 0 ? PROCEDURE_NO_RESULT : PROCEDURE_RETURNS_RESULT).at(8).set(valueBuilder.get(2)).toRowValue(true));
        } while (rs.next());
        return new FBResultSet(rowDescriptor, rows);
    }
}
Also used : RowDescriptorBuilder(org.firebirdsql.gds.ng.fields.RowDescriptorBuilder) RowValueBuilder(org.firebirdsql.gds.ng.fields.RowValueBuilder) RowValue(org.firebirdsql.gds.ng.fields.RowValue) RowDescriptor(org.firebirdsql.gds.ng.fields.RowDescriptor)

Example 13 with RowDescriptorBuilder

use of org.firebirdsql.gds.ng.fields.RowDescriptorBuilder in project jaybird by FirebirdSQL.

the class FBDatabaseMetaData method getPrimaryKeys.

/**
 * Gets a description of a table's primary key columns.  They
 * are ordered by COLUMN_NAME.
 *
 * <P>Each primary key 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>COLUMN_NAME</B> String => column name
 *  <LI><B>KEY_SEQ</B> short => sequence number within primary key
 *  <LI><B>PK_NAME</B> String => primary key name (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; "" retrieves those
 * without a schema
 * @param table a table name
 * @return <code>ResultSet</code> - each row is a primary key column description
 * @exception SQLException if a database access error occurs
 */
public ResultSet getPrimaryKeys(String catalog, String schema, String table) throws SQLException {
    RowDescriptor rowDescriptor = new RowDescriptorBuilder(6, datatypeCoder).at(0).simple(SQL_VARYING, OBJECT_NAME_LENGTH, "TABLE_CAT", "COLUMNINFO").addField().at(1).simple(SQL_VARYING, OBJECT_NAME_LENGTH, "TABLE_SCHEM", "COLUMNINFO").addField().at(2).simple(SQL_VARYING, OBJECT_NAME_LENGTH, "TABLE_NAME", "COLUMNINFO").addField().at(3).simple(SQL_VARYING, OBJECT_NAME_LENGTH, "COLUMN_NAME", "COLUMNINFO").addField().at(4).simple(SQL_SHORT, 0, "KEY_SEQ", "COLUMNINFO").addField().at(5).simple(SQL_VARYING, OBJECT_NAME_LENGTH, "PK_NAME", "COLUMNINFO").addField().toRowDescriptor();
    List<String> params = Collections.singletonList(table);
    try (ResultSet rs = doQuery(GET_PRIMARY_KEYS, params)) {
        // if nothing found, return empty result set
        if (!rs.next()) {
            return new FBResultSet(rowDescriptor, Collections.<RowValue>emptyList());
        }
        final List<RowValue> rows = new ArrayList<>();
        final RowValueBuilder valueBuilder = new RowValueBuilder(rowDescriptor);
        do {
            rows.add(valueBuilder.at(2).set(getBytes(rs.getString("TABLE_NAME"))).at(3).set(getBytes(rs.getString("COLUMN_NAME"))).at(4).set(createShort(rs.getShort("KEY_SEQ"))).at(5).set(getBytes(rs.getString("PK_NAME"))).toRowValue(true));
        } while (rs.next());
        return new FBResultSet(rowDescriptor, rows);
    }
}
Also used : RowDescriptorBuilder(org.firebirdsql.gds.ng.fields.RowDescriptorBuilder) RowValueBuilder(org.firebirdsql.gds.ng.fields.RowValueBuilder) RowValue(org.firebirdsql.gds.ng.fields.RowValue) RowDescriptor(org.firebirdsql.gds.ng.fields.RowDescriptor)

Example 14 with RowDescriptorBuilder

use of org.firebirdsql.gds.ng.fields.RowDescriptorBuilder in project jaybird by FirebirdSQL.

the class FBDatabaseMetaData method getProcedureColumns.

/**
 * Retrieves a description of the given catalog's stored procedure parameter
 * and result columns.
 *
 * <P>Only descriptions matching the schema, procedure and
 * parameter name criteria are returned.  They are ordered by
 * PROCEDURE_CAT, PROCEDURE_SCHEM, PROCEDURE_NAME and SPECIFIC_NAME. Within this, the return value,
 * if any, is first. Next are the parameter descriptions in call
 * order. The column descriptions follow in column number order.
 *
 * <P>Each row in the <code>ResultSet</code> is a parameter description or
 * column description with the following fields:
 *  <OL>
 *  <LI><B>PROCEDURE_CAT</B> String => procedure catalog (may be <code>null</code>)
 *  <LI><B>PROCEDURE_SCHEM</B> String => procedure schema (may be <code>null</code>)
 *  <LI><B>PROCEDURE_NAME</B> String => procedure name
 *  <LI><B>COLUMN_NAME</B> String => column/parameter name
 *  <LI><B>COLUMN_TYPE</B> Short => kind of column/parameter:
 *      <UL>
 *      <LI> procedureColumnUnknown - nobody knows
 *      <LI> procedureColumnIn - IN parameter
 *      <LI> procedureColumnInOut - INOUT parameter
 *      <LI> procedureColumnOut - OUT parameter
 *      <LI> procedureColumnReturn - procedure return value
 *      <LI> procedureColumnResult - result column in <code>ResultSet</code>
 *      </UL>
 *  <LI><B>DATA_TYPE</B> int => SQL type from java.sql.Types
 *  <LI><B>TYPE_NAME</B> String => SQL type name, for a UDT type the
 *  type name is fully qualified
 *  <LI><B>PRECISION</B> int => precision
 *  <LI><B>LENGTH</B> int => length in bytes of data
 *  <LI><B>SCALE</B> short => scale -  null is returned for data types where
 * SCALE is not applicable.
 *  <LI><B>RADIX</B> short => radix
 *  <LI><B>NULLABLE</B> short => can it contain NULL.
 *      <UL>
 *      <LI> procedureNoNulls - does not allow NULL values
 *      <LI> procedureNullable - allows NULL values
 *      <LI> procedureNullableUnknown - nullability unknown
 *      </UL>
 *  <LI><B>REMARKS</B> String => comment describing parameter/column
 *  <LI><B>COLUMN_DEF</B> String => default value for the column, which should be interpreted as a string when the value is enclosed in single quotes (may be <code>null</code>)
 *      <UL>
 *      <LI> The string NULL (not enclosed in quotes) - if NULL was specified as the default value
 *      <LI> TRUNCATE (not enclosed in quotes)        - if the specified default value cannot be represented without truncation
 *      <LI> NULL                                     - if a default value was not specified
 *      </UL>
 *  <LI><B>SQL_DATA_TYPE</B> int  => reserved for future use
 *  <LI><B>SQL_DATETIME_SUB</B> int  => reserved for future use
 *  <LI><B>CHAR_OCTET_LENGTH</B> int  => the maximum length of binary and character based columns.  For any other datatype the returned value is a
 * NULL
 *  <LI><B>ORDINAL_POSITION</B> int  => the ordinal position, starting from 1, for the input and output parameters for a procedure. A value of 0
 *is returned if this row describes the procedure's return value.  For result set columns, it is the
 *ordinal position of the column in the result set starting from 1.  If there are
 *multiple result sets, the column ordinal positions are implementation
 * defined.
 *  <LI><B>IS_NULLABLE</B> String  => ISO rules are used to determine the nullability for a column.
 *       <UL>
 *       <LI> YES           --- if the parameter can include NULLs
 *       <LI> NO            --- if the parameter cannot include NULLs
 *       <LI> empty string  --- if the nullability for the
 * parameter is unknown
 *       </UL>
 *  <LI><B>SPECIFIC_NAME</B> String  => the name which uniquely identifies this procedure within its schema.
 *  </OL>
 *
 * <P><B>Note:</B> Some databases may not return the column
 * descriptions for a procedure.
 *
 * <p>The PRECISION column represents the specified column size for the given column.
 * For numeric data, this is the maximum precision.  For character data, this is the length in characters.
 * For datetime datatypes, this is the length in characters of the String representation (assuming the
 * maximum allowed precision of the fractional seconds component). For binary data, this is the length in bytes.  For the ROWID datatype,
 * this is the length in bytes. Null is returned for data types where the
 * column size is not applicable.
 * @param catalog a catalog name; must match the catalog name as it
 *        is stored in the database; "" retrieves those without a catalog;
 *        <code>null</code> means that the catalog name should not be used to narrow
 *        the search
 * @param schemaPattern a schema name pattern; must match the schema name
 *        as it is stored in the database; "" retrieves those without a schema;
 *        <code>null</code> means that the schema name should not be used to narrow
 *        the search
 * @param procedureNamePattern a procedure name pattern; must match the
 *        procedure name as it is stored in the database
 * @param columnNamePattern a column name pattern; must match the column name
 *        as it is stored in the database
 * @return <code>ResultSet</code> - each row describes a stored procedure parameter or
 *      column
 * @exception SQLException if a database access error occurs
 * @see #getSearchStringEscape
 */
public ResultSet getProcedureColumns(String catalog, String schemaPattern, String procedureNamePattern, String columnNamePattern) throws SQLException {
    final RowDescriptor rowDescriptor = new RowDescriptorBuilder(20, datatypeCoder).at(0).simple(SQL_VARYING, OBJECT_NAME_LENGTH, "PROCEDURE_CAT", "COLUMNINFO").addField().at(1).simple(SQL_VARYING, OBJECT_NAME_LENGTH, "PROCEDURE_SCHEM", "COLUMNINFO").addField().at(2).simple(SQL_VARYING, OBJECT_NAME_LENGTH, "PROCEDURE_NAME", "COLUMNINFO").addField().at(3).simple(SQL_VARYING, OBJECT_NAME_LENGTH, "COLUMN_NAME", "COLUMNINFO").addField().at(4).simple(SQL_SHORT, 0, "COLUMN_TYPE", "COLUMNINFO").addField().at(5).simple(SQL_LONG, 0, "DATA_TYPE", "COLUMNINFO").addField().at(6).simple(SQL_VARYING, 31, "TYPE_NAME", "COLUMNINFO").addField().at(7).simple(SQL_LONG, 0, "PRECISION", "COLUMNINFO").addField().at(8).simple(SQL_LONG, 0, "LENGTH", "COLUMNINFO").addField().at(9).simple(SQL_SHORT, 0, "SCALE", "COLUMNINFO").addField().at(10).simple(SQL_SHORT, 0, "RADIX", "COLUMNINFO").addField().at(11).simple(SQL_SHORT, 0, "NULLABLE", "COLUMNINFO").addField().at(12).simple(SQL_VARYING, Integer.MAX_VALUE, "REMARKS", "COLUMNINFO").addField().at(13).simple(SQL_VARYING, 31, "COLUMN_DEF", "COLUMNINFO").addField().at(14).simple(SQL_LONG, 0, "SQL_DATA_TYPE", "COLUMNINFO").addField().at(15).simple(SQL_LONG, 0, "SQL_DATETIME_SUB", "COLUMNINFO").addField().at(16).simple(SQL_LONG, 0, "CHAR_OCTET_LENGTH", "COLUMNINFO").addField().at(17).simple(SQL_LONG, 0, "ORDINAL_POSITION", "COLUMNINFO").addField().at(18).simple(SQL_VARYING, 3, "IS_NULLABLE", "COLUMNINFO").addField().at(19).simple(SQL_VARYING, OBJECT_NAME_LENGTH, "SPECIFIC_NAME", "COLUMNINFO").addField().toRowDescriptor();
    Clause procedureClause = new Clause("PP.RDB$PROCEDURE_NAME", procedureNamePattern);
    Clause columnClause = new Clause("PP.RDB$PARAMETER_NAME", columnNamePattern);
    String sql = GET_PROCEDURE_COLUMNS_START;
    sql += procedureClause.getCondition();
    sql += columnClause.getCondition();
    sql += GET_PROCEDURE_COLUMNS_END;
    List<String> params = new ArrayList<>(2);
    if (procedureClause.hasCondition()) {
        params.add(procedureClause.getValue());
    }
    if (columnClause.hasCondition()) {
        params.add(columnClause.getValue());
    }
    try (ResultSet rs = doQuery(sql, params)) {
        // if nothing found, return an empty result set
        if (!rs.next()) {
            return new FBResultSet(rowDescriptor, Collections.<RowValue>emptyList());
        }
        final List<RowValue> rows = new ArrayList<>();
        final RowValueBuilder valueBuilder = new RowValueBuilder(rowDescriptor);
        do {
            final short columnType = rs.getShort("COLUMN_TYPE");
            final short fieldType = rs.getShort("FIELD_TYPE");
            final short fieldSubType = rs.getShort("FIELD_SUB_TYPE");
            final short fieldScale = rs.getShort("FIELD_SCALE");
            final int characterSetId = rs.getInt("RDB$CHARACTER_SET_ID");
            // TODO: Find out what the difference is with NULL_FLAG in RDB$PROCEDURE_PARAMETERS (might be ODS dependent)
            final short nullFlag = rs.getShort("NULL_FLAG");
            final int dataType = getDataType(fieldType, fieldSubType, fieldScale, characterSetId);
            valueBuilder.at(2).set(getBytes(rs.getString("PROCEDURE_NAME"))).at(3).set(getBytes(rs.getString("COLUMN_NAME"))).at(4).set(columnType == 0 ? PROCEDURE_COLUMN_IN : PROCEDURE_COLUMN_OUT).at(5).set(createInt(dataType)).at(6).set(getBytes(getDataTypeName(fieldType, fieldSubType, fieldScale))).at(8).set(createInt(rs.getShort("FIELD_LENGTH"))).at(10).set(RADIX_TEN_SHORT).at(11).set(nullFlag == 1 ? PROCEDURE_NO_NULLS : PROCEDURE_NULLABLE).at(12).set(getBytes(rs.getString("REMARKS"))).at(17).set(createInt(rs.getInt("PARAMETER_NUMBER"))).at(18).set(nullFlag == 1 ? NO_BYTES : YES_BYTES).at(19).set(valueBuilder.get(2));
            switch(dataType) {
                case Types.DECIMAL:
                case Types.NUMERIC:
                    valueBuilder.at(7).set(createInt(rs.getShort("FIELD_PRECISION"))).at(9).set(createShort(-1 * fieldScale));
                    break;
                case Types.CHAR:
                case Types.VARCHAR:
                case Types.BINARY:
                case Types.VARBINARY:
                    short charLen = rs.getShort("CHAR_LEN");
                    if (!rs.wasNull()) {
                        valueBuilder.at(7).set(createInt(charLen));
                    } else {
                        valueBuilder.at(8).set(valueBuilder.get(8));
                    }
                    valueBuilder.at(16).set(valueBuilder.get(8));
                    break;
                case Types.FLOAT:
                    valueBuilder.at(7).set(FLOAT_PRECISION);
                    break;
                case Types.DOUBLE:
                    valueBuilder.at(7).set(DOUBLE_PRECISION);
                    break;
                case Types.BIGINT:
                    valueBuilder.at(7).set(BIGINT_PRECISION).at(9).set(SHORT_ZERO);
                    break;
                case Types.INTEGER:
                    valueBuilder.at(7).set(INTEGER_PRECISION).at(9).set(SHORT_ZERO);
                    break;
                case Types.SMALLINT:
                    valueBuilder.at(7).set(SMALLINT_PRECISION).at(9).set(SHORT_ZERO);
                    break;
                case Types.DATE:
                    valueBuilder.at(7).set(DATE_PRECISION);
                    break;
                case Types.TIME:
                    valueBuilder.at(7).set(TIME_PRECISION);
                    break;
                case Types.TIMESTAMP:
                    valueBuilder.at(7).set(TIMESTAMP_PRECISION);
                    break;
                case Types.BOOLEAN:
                    valueBuilder.at(7).set(BOOLEAN_PRECISION).at(10).set(RADIX_BINARY_SHORT);
                    break;
                case JaybirdTypeCodes.DECFLOAT:
                    switch(fieldType) {
                        case dec16_type:
                            valueBuilder.at(7).set(DECFLOAT_16_PRECISION);
                            break;
                        case dec34_type:
                            valueBuilder.at(7).set(DECFLOAT_34_PRECISION);
                            break;
                    }
                    break;
            }
            rows.add(valueBuilder.toRowValue(true));
        } while (rs.next());
        return new FBResultSet(rowDescriptor, rows);
    }
}
Also used : RowValueBuilder(org.firebirdsql.gds.ng.fields.RowValueBuilder) RowDescriptor(org.firebirdsql.gds.ng.fields.RowDescriptor) RowDescriptorBuilder(org.firebirdsql.gds.ng.fields.RowDescriptorBuilder) RowValue(org.firebirdsql.gds.ng.fields.RowValue)

Example 15 with RowDescriptorBuilder

use of org.firebirdsql.gds.ng.fields.RowDescriptorBuilder in project jaybird by FirebirdSQL.

the class StatementInfoProcessor method handleTruncatedInfo.

/**
 * Handles info buffer truncation by requesting new information
 *
 * @param info
 *         StatementInfo
 * @throws SQLException
 */
private void handleTruncatedInfo(final StatementInfo info) throws SQLException {
    final byte[] originalInfo = statement.getStatementInfoRequestItems();
    // Adding 2 * 4 bytes for the isc_info_sql_sqlda_start item (see handling of isc_info_sql_select and isc_info_sql_bind)
    final byte[] newInfoItems = new byte[originalInfo.length + 2 * 4];
    int newIndex = 0;
    for (final byte infoItem : originalInfo) {
        assert newIndex < newInfoItems.length : "newInfoItems size too short";
        switch(infoItem) {
            case ISCConstants.isc_info_sql_select:
            case ISCConstants.isc_info_sql_bind:
                final RowDescriptorBuilder currentBuilder = infoItem == ISCConstants.isc_info_sql_select ? info.fieldBuilder : info.parameterBuilder;
                // Index of first descriptor to request; adding 1 to descriptor index as Firebird uses 1-based index for fields/parameters and builders are 0-based
                final int descriptorIndex = currentBuilder != null ? currentBuilder.getFirstUnprocessedIndex() + 1 : 1;
                // Request server to resend info starting at the specified index of the fields or parameters
                newInfoItems[newIndex++] = ISCConstants.isc_info_sql_sqlda_start;
                // size of short
                newInfoItems[newIndex++] = 2;
                newInfoItems[newIndex++] = (byte) (descriptorIndex & 0xFF);
                newInfoItems[newIndex++] = (byte) (descriptorIndex >> 8);
                newInfoItems[newIndex++] = infoItem;
                break;
            default:
                newInfoItems[newIndex++] = infoItem;
                break;
        }
    }
    assert newIndex == newInfoItems.length : "newInfoItems size too long";
    // Doubling request buffer up to the maximum
    info.requestBufferSize = Math.min(2 * info.requestBufferSize, statement.getMaxSqlInfoSize());
    info.buffer = statement.getSqlInfo(newInfoItems, info.requestBufferSize);
    info.currentIndex = 0;
}
Also used : RowDescriptorBuilder(org.firebirdsql.gds.ng.fields.RowDescriptorBuilder)

Aggregations

RowDescriptorBuilder (org.firebirdsql.gds.ng.fields.RowDescriptorBuilder)15 RowDescriptor (org.firebirdsql.gds.ng.fields.RowDescriptor)12 RowValue (org.firebirdsql.gds.ng.fields.RowValue)12 RowValueBuilder (org.firebirdsql.gds.ng.fields.RowValueBuilder)10 FieldDescriptor (org.firebirdsql.gds.ng.fields.FieldDescriptor)1 Before (org.junit.Before)1