use of org.firebirdsql.gds.ng.fields.RowValueBuilder in project jaybird by FirebirdSQL.
the class FBDatabaseMetaData method getImportedKeys.
/**
* Gets 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; "" 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
* @see #getExportedKeys
*/
public ResultSet getImportedKeys(String catalog, String schema, String table) throws SQLException {
final RowDescriptor rowDescriptor = new RowDescriptorBuilder(14, datatypeCoder).at(0).simple(SQL_VARYING, OBJECT_NAME_LENGTH, "PKTABLE_CAT", "COLUMNINFO").addField().at(1).simple(SQL_VARYING, OBJECT_NAME_LENGTH, "PKTABLE_SCHEM", "COLUMNINFO").addField().at(2).simple(SQL_VARYING, OBJECT_NAME_LENGTH, "PKTABLE_NAME", "COLUMNINFO").addField().at(3).simple(SQL_VARYING, OBJECT_NAME_LENGTH, "PKCOLUMN_NAME", "COLUMNINFO").addField().at(4).simple(SQL_VARYING, OBJECT_NAME_LENGTH, "FKTABLE_CAT", "COLUMNINFO").addField().at(5).simple(SQL_VARYING, OBJECT_NAME_LENGTH, "FKTABLE_SCHEM", "COLUMNINFO").addField().at(6).simple(SQL_VARYING, OBJECT_NAME_LENGTH, "FKTABLE_NAME", "COLUMNINFO").addField().at(7).simple(SQL_VARYING, OBJECT_NAME_LENGTH, "FKCOLUMN_NAME", "COLUMNINFO").addField().at(8).simple(SQL_SHORT, 0, "KEY_SEQ", "COLUMNINFO").addField().at(9).simple(SQL_SHORT, 0, "UPDATE_RULE", "COLUMNINFO").addField().at(10).simple(SQL_SHORT, 0, "DELETE_RULE", "COLUMNINFO").addField().at(11).simple(SQL_VARYING, OBJECT_NAME_LENGTH, "FK_NAME", "COLUMNINFO").addField().at(12).simple(SQL_VARYING, OBJECT_NAME_LENGTH, "PK_NAME", "COLUMNINFO").addField().at(13).simple(SQL_SHORT, 0, "DEFERRABILITY", "COLUMNINFO").addField().toRowDescriptor();
List<String> params = Collections.singletonList(table);
try (ResultSet rs = doQuery(GET_IMPORTED_KEYS, 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 {
rows.add(valueBuilder.at(2).set(getBytes(rs.getString("PKTABLE_NAME"))).at(3).set(getBytes(rs.getString("PKCOLUMN_NAME"))).at(6).set(getBytes(rs.getString("FKTABLE_NAME"))).at(7).set(getBytes(rs.getString("FKCOLUMN_NAME"))).at(8).set(createShort(rs.getShort("KEY_SEQ"))).at(9).set(mapAction(rs.getString("UPDATE_RULE"))).at(10).set(mapAction(rs.getString("DELETE_RULE"))).at(11).set(getBytes(rs.getString("FK_NAME"))).at(12).set(getBytes(rs.getString("PK_NAME"))).at(13).set(IMPORTED_KEY_NOT_DEFERRABLE).toRowValue(true));
} while (rs.next());
return new FBResultSet(rowDescriptor, rows);
}
}
use of org.firebirdsql.gds.ng.fields.RowValueBuilder 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);
}
}
use of org.firebirdsql.gds.ng.fields.RowValueBuilder 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);
}
}
use of org.firebirdsql.gds.ng.fields.RowValueBuilder 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);
}
}
use of org.firebirdsql.gds.ng.fields.RowValueBuilder 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);
}
}
Aggregations