Search in sources :

Example 6 with ResultColumnDescriptor

use of org.apache.derby.iapi.sql.ResultColumnDescriptor in project derby by apache.

the class DMLWriteResultSet method normalizeRow.

/**
 * <p>
 * Normalize a row as part of the INSERT/UPDATE action of a MERGE statement.
 * This applies logic usually found in a NormalizeResultSet, which is missing for
 * the MERGE statement.
 * </p>
 * @param sourceResultSet        the result set for which this action is
 *                               to be performed
 * @param row                    the row to be normalized
 * @return                       the normalized row
 * @throws StandardException     Standard error policy
 */
protected ExecRow normalizeRow(NoPutResultSet sourceResultSet, ExecRow row) throws StandardException {
    // 
    // Make sure that the evaluated expressions fit in the base table row.
    // 
    int count = resultDescription.getColumnCount();
    if (cachedDestinations == null) {
        cachedDestinations = new DataValueDescriptor[count];
        for (int i = 0; i < count; i++) {
            int position = i + 1;
            ResultColumnDescriptor colDesc = resultDescription.getColumnDescriptor(position);
            cachedDestinations[i] = colDesc.getType().getNull();
        }
    }
    for (int i = 0; i < count; i++) {
        int position = i + 1;
        DataTypeDescriptor dtd = resultDescription.getColumnDescriptor(position).getType();
        if (row.getColumn(position) == null) {
            row.setColumn(position, dtd.getNull());
        }
        row.setColumn(position, NormalizeResultSet.normalizeColumn(dtd, row, position, cachedDestinations[i], resultDescription));
    }
    // put the row where expressions in constraints can access it
    activation.setCurrentRow(row, sourceResultSet.resultSetNumber());
    return row;
}
Also used : ResultColumnDescriptor(org.apache.derby.iapi.sql.ResultColumnDescriptor) DataTypeDescriptor(org.apache.derby.iapi.types.DataTypeDescriptor)

Example 7 with ResultColumnDescriptor

use of org.apache.derby.iapi.sql.ResultColumnDescriptor in project derby by apache.

the class NoRowsResultSetImpl method setupGeneratedColumns.

/**
 * Construct support for normalizing generated columns. This figures out
 * which columns in the target row have generation clauses which need to be run.
 */
private void setupGeneratedColumns(Activation activation, ValueRow newRow) throws StandardException {
    ResultDescription resultDescription = activation.getResultDescription();
    int columnCount = resultDescription.getColumnCount();
    ExecRow emptyRow = newRow.getNewNullRow();
    int generatedColumnCount = 0;
    // first count the number of generated columns
    for (int i = 1; i <= columnCount; i++) {
        if (i < firstColumn) {
            continue;
        }
        ResultColumnDescriptor rcd = resultDescription.getColumnDescriptor(i);
        if (rcd.hasGenerationClause()) {
            generatedColumnCount++;
        }
    }
    // now allocate and populate support structures
    generatedColumnPositions = new int[generatedColumnCount];
    normalizedGeneratedValues = new DataValueDescriptor[generatedColumnCount];
    int idx = 0;
    for (int i = 1; i <= columnCount; i++) {
        if (i < firstColumn) {
            continue;
        }
        ResultColumnDescriptor rcd = resultDescription.getColumnDescriptor(i);
        if (rcd.hasGenerationClause()) {
            generatedColumnPositions[idx] = i;
            normalizedGeneratedValues[idx] = emptyRow.getColumn(i);
            idx++;
        }
    }
}
Also used : ResultColumnDescriptor(org.apache.derby.iapi.sql.ResultColumnDescriptor) ResultDescription(org.apache.derby.iapi.sql.ResultDescription) ExecRow(org.apache.derby.iapi.sql.execute.ExecRow)

Example 8 with ResultColumnDescriptor

use of org.apache.derby.iapi.sql.ResultColumnDescriptor in project derby by apache.

the class NormalizeResultSet method fetchResultTypes.

/**
 * <p>
 * Fetch the result datatypes out of the activation.
 * </p>
 */
private DataTypeDescriptor[] fetchResultTypes(ResultDescription desc) {
    int count = desc.getColumnCount();
    DataTypeDescriptor[] result = new DataTypeDescriptor[count];
    for (int i = 1; i <= count; i++) {
        ResultColumnDescriptor colDesc = desc.getColumnDescriptor(i);
        DataTypeDescriptor dtd = colDesc.getType();
        result[i - 1] = dtd;
    }
    return result;
}
Also used : ResultColumnDescriptor(org.apache.derby.iapi.sql.ResultColumnDescriptor) DataTypeDescriptor(org.apache.derby.iapi.types.DataTypeDescriptor)

Example 9 with ResultColumnDescriptor

use of org.apache.derby.iapi.sql.ResultColumnDescriptor in project derby by apache.

the class EmbedResultSetMetaData method getTableName.

/**
 * What's a column's table name?
 *
 * @return table name or "" if not applicable
 * @exception SQLException thrown on failure
 */
public final String getTableName(int column) throws SQLException {
    ResultColumnDescriptor cd = columnInfo[column - 1];
    String s = cd.getSourceTableName();
    // database returns null when no table name to differentiate from empty name
    return (s == null ? "" : s);
}
Also used : ResultColumnDescriptor(org.apache.derby.iapi.sql.ResultColumnDescriptor)

Example 10 with ResultColumnDescriptor

use of org.apache.derby.iapi.sql.ResultColumnDescriptor in project derby by apache.

the class EmbedResultSetMetaData method getColumnName.

/**
 * What's a column's name?
 *
 * @param column the first column is 1, the second is 2, ...
 * @return column name
 * @exception SQLException thrown on failure
 */
public final String getColumnName(int column) throws SQLException {
    ResultColumnDescriptor cd = columnInfo[column - 1];
    String s = cd.getName();
    // database returns null when no column name to differentiate from empty name
    return (s == null ? "" : s);
}
Also used : ResultColumnDescriptor(org.apache.derby.iapi.sql.ResultColumnDescriptor)

Aggregations

ResultColumnDescriptor (org.apache.derby.iapi.sql.ResultColumnDescriptor)10 DataTypeDescriptor (org.apache.derby.iapi.types.DataTypeDescriptor)2 ResultDescription (org.apache.derby.iapi.sql.ResultDescription)1 ExecRow (org.apache.derby.iapi.sql.execute.ExecRow)1