Search in sources :

Example 66 with ColumnDescriptor

use of org.apache.derby.iapi.sql.dictionary.ColumnDescriptor in project derby by apache.

the class ResultColumn method bindResultColumnByPosition.

/**
 * Bind this result column by ordinal position and set the VirtualColumnId.
 * This is useful for INSERT statements like "insert into t values (1, 2, 3)",
 * where the user did not specify a column list.
 * If a columnDescriptor is not found for a given position, then
 * the user has specified more values than the # of columns in
 * the table and an exception is thrown.
 *
 * NOTE: We must set the VirtualColumnId here because INSERT does not
 * construct the ResultColumnList in the usual way.
 *
 * @param tableDescriptor	The descriptor for the table being
 *				inserted into
 * @param columnId		The ordinal position of the column
 *						in the table, starting at 1.
 *
 * @exception StandardException		Thrown on error
 */
void bindResultColumnByPosition(TableDescriptor tableDescriptor, int columnId) throws StandardException {
    ColumnDescriptor colDesc;
    colDesc = tableDescriptor.getColumnDescriptor(columnId);
    if (colDesc == null) {
        String errorString;
        String schemaName;
        errorString = "";
        schemaName = tableDescriptor.getSchemaName();
        if (schemaName != null)
            errorString += schemaName + ".";
        errorString += tableDescriptor.getName();
        throw StandardException.newException(SQLState.LANG_TOO_MANY_RESULT_COLUMNS, errorString);
    }
    setColumnDescriptor(tableDescriptor, colDesc);
    setVirtualColumnId(columnId);
}
Also used : ResultColumnDescriptor(org.apache.derby.iapi.sql.ResultColumnDescriptor) ColumnDescriptor(org.apache.derby.iapi.sql.dictionary.ColumnDescriptor)

Example 67 with ColumnDescriptor

use of org.apache.derby.iapi.sql.dictionary.ColumnDescriptor in project derby by apache.

the class ResultColumn method bindResultColumnByName.

/**
 * Bind this result column by its name and set the VirtualColumnId.
 * This is useful for update statements, and for INSERT statements
 * like "insert into t (a, b, c) values (1, 2, 3)" where the user
 * specified a column list.
 * An exception is thrown when a columnDescriptor cannot be found for a
 * given name.  (There is no column with that name.)
 *
 * NOTE: We must set the VirtualColumnId here because INSERT does not
 * construct the ResultColumnList in the usual way.
 *
 * @param tableDescriptor	The descriptor for the table being
 *				updated or inserted into
 * @param columnId		The ordinal position of the column
 *						in the table, starting at 1. (Used to
 *						set the VirtualColumnId.)
 *
 * @exception StandardException		Thrown on error
 */
void bindResultColumnByName(TableDescriptor tableDescriptor, int columnId) throws StandardException {
    ColumnDescriptor colDesc;
    colDesc = tableDescriptor.getColumnDescriptor(_derivedColumnName);
    if (colDesc == null) {
        String errorString;
        String schemaName;
        errorString = "";
        schemaName = tableDescriptor.getSchemaName();
        if (schemaName != null)
            errorString += schemaName + ".";
        errorString += tableDescriptor.getName();
        throw StandardException.newException(SQLState.LANG_COLUMN_NOT_FOUND_IN_TABLE, _derivedColumnName, errorString);
    }
    setColumnDescriptor(tableDescriptor, colDesc);
    setVirtualColumnId(columnId);
    if (isPrivilegeCollectionRequired())
        getCompilerContext().addRequiredColumnPriv(colDesc);
}
Also used : ResultColumnDescriptor(org.apache.derby.iapi.sql.ResultColumnDescriptor) ColumnDescriptor(org.apache.derby.iapi.sql.dictionary.ColumnDescriptor)

Example 68 with ColumnDescriptor

use of org.apache.derby.iapi.sql.dictionary.ColumnDescriptor in project derby by apache.

the class ResultColumnList method replaceOrForbidDefaults.

/**
 * Replace any DEFAULTs with the associated tree for the default if
 * allowed, or flag.
 *
 * @param ttd	The TableDescriptor for the target table.
 * @param tcl	The RCL for the target table.
 * @param allowDefaults true if allowed
 *
 * @exception StandardException		Thrown on error
 */
void replaceOrForbidDefaults(TableDescriptor ttd, ResultColumnList tcl, boolean allowDefaults) throws StandardException {
    int size = size();
    for (int index = 0; index < size; index++) {
        ResultColumn rc = elementAt(index);
        if (rc.isDefaultColumn()) {
            if (!allowDefaults) {
                throw StandardException.newException(SQLState.LANG_INVALID_USE_OF_DEFAULT);
            }
            // DefaultNode defaultNode = (DefaultNode) rc.getExpression();
            // Get ColumnDescriptor by name or by position?
            ColumnDescriptor cd = null;
            if (tcl == null) {
                cd = ttd.getColumnDescriptor(index + 1);
            } else if (index < tcl.size()) {
                ResultColumn trc = tcl.elementAt(index);
                cd = ttd.getColumnDescriptor(trc.getName());
            }
            // Too many RCs if no ColumnDescriptor
            if (cd == null) {
                throw StandardException.newException(SQLState.LANG_TOO_MANY_RESULT_COLUMNS, ttd.getQualifiedName());
            }
            if (cd.isAutoincrement()) {
                rc.setAutoincrementGenerated();
            }
            // end of if ()
            DefaultInfoImpl defaultInfo = (DefaultInfoImpl) cd.getDefaultInfo();
            // 
            if ((defaultInfo != null) && !defaultInfo.isGeneratedColumn()) {
                setDefault(rc, cd, defaultInfo);
            } else {
                rc.setExpression(new UntypedNullConstantNode(getContextManager()));
                rc.setWasDefaultColumn(true);
            }
            rc.setDefaultColumn(false);
        }
    }
}
Also used : ResultColumnDescriptor(org.apache.derby.iapi.sql.ResultColumnDescriptor) ColumnDescriptor(org.apache.derby.iapi.sql.dictionary.ColumnDescriptor) DefaultInfoImpl(org.apache.derby.catalog.types.DefaultInfoImpl)

Example 69 with ColumnDescriptor

use of org.apache.derby.iapi.sql.dictionary.ColumnDescriptor in project derby by apache.

the class ResultColumnList method buildEmptyIndexRow.

/**
 *	Build an empty index row for the given conglomerate.
 *
 *	@return	an empty row of the correct size and shape.
 * @exception StandardException		Thrown on error
 */
public ExecRow buildEmptyIndexRow(TableDescriptor td, ConglomerateDescriptor cd, StoreCostController scc, DataDictionary dd) throws StandardException {
    ResultColumn rc;
    if (SanityManager.DEBUG) {
        if (!cd.isIndex()) {
            SanityManager.THROWASSERT("ConglomerateDescriptor expected to be for index: " + cd);
        }
    }
    int[] baseCols = cd.getIndexDescriptor().baseColumnPositions();
    ExecRow row = getExecutionFactory().getValueRow(baseCols.length + 1);
    for (int i = 0; i < baseCols.length; i++) {
        ColumnDescriptor coldes = td.getColumnDescriptor(baseCols[i]);
        DataTypeDescriptor dataType = coldes.getType();
        // rc = getResultColumn(baseCols[i]);
        // rc = (ResultColumn) at(baseCols[i] - 1);
        // dataType = rc.getTypeServices();
        DataValueDescriptor dataValue = dataType.getNull();
        row.setColumn(i + 1, dataValue);
    }
    RowLocation rlTemplate = scc.newRowLocationTemplate();
    row.setColumn(baseCols.length + 1, rlTemplate);
    return row;
}
Also used : DataTypeDescriptor(org.apache.derby.iapi.types.DataTypeDescriptor) ResultColumnDescriptor(org.apache.derby.iapi.sql.ResultColumnDescriptor) ColumnDescriptor(org.apache.derby.iapi.sql.dictionary.ColumnDescriptor) ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) RowLocation(org.apache.derby.iapi.types.RowLocation)

Example 70 with ColumnDescriptor

use of org.apache.derby.iapi.sql.dictionary.ColumnDescriptor in project derby by apache.

the class ResultColumnList method forbidOverrides.

/**
 * check if any autoincrement or generated columns exist in the result column list.
 * called from insert or update where you cannot insert/update the value
 * of a generated or autoincrement column.
 *
 * @exception StandardException		If the column is an ai column
 */
void forbidOverrides(ResultColumnList sourceRSRCL, boolean defaultsWereReplaced) throws StandardException {
    int size = size();
    for (int index = 0; index < size; index++) {
        ResultColumn rc = elementAt(index);
        ResultColumn sourceRC = (sourceRSRCL == null) ? null : sourceRSRCL.elementAt(index);
        ColumnDescriptor cd = rc.getTableColumnDescriptor();
        if ((cd != null) && cd.hasGenerationClause()) {
            if (!defaultsWereReplaced && (sourceRC != null) && !sourceRC.hasGenerationClause() && !sourceRC.wasDefaultColumn()) {
                throw StandardException.newException(SQLState.LANG_CANT_OVERRIDE_GENERATION_CLAUSE, rc.getName());
            }
            if (sourceRC != null) {
                sourceRC.setColumnDescriptor(cd.getTableDescriptor(), cd);
            }
        }
        if ((cd != null) && (cd.isAutoincrement())) {
            if (((sourceRC != null) && (sourceRC.isAutoincrementGenerated())) || (cd.isAutoincAlways() && defaultsWereReplaced)) {
                sourceRC.setColumnDescriptor(cd.getTableDescriptor(), cd);
            } else {
                if (cd.isAutoincAlways())
                    throw StandardException.newException(SQLState.LANG_AI_CANNOT_MODIFY_AI, rc.getName());
            }
        }
    }
}
Also used : ResultColumnDescriptor(org.apache.derby.iapi.sql.ResultColumnDescriptor) ColumnDescriptor(org.apache.derby.iapi.sql.dictionary.ColumnDescriptor)

Aggregations

ColumnDescriptor (org.apache.derby.iapi.sql.dictionary.ColumnDescriptor)79 ColumnDescriptorList (org.apache.derby.iapi.sql.dictionary.ColumnDescriptorList)23 TableDescriptor (org.apache.derby.iapi.sql.dictionary.TableDescriptor)20 ResultColumnDescriptor (org.apache.derby.iapi.sql.ResultColumnDescriptor)19 UUID (org.apache.derby.catalog.UUID)15 DataTypeDescriptor (org.apache.derby.iapi.types.DataTypeDescriptor)14 ExecRow (org.apache.derby.iapi.sql.execute.ExecRow)10 ConglomerateDescriptor (org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor)8 SchemaDescriptor (org.apache.derby.iapi.sql.dictionary.SchemaDescriptor)8 TransactionController (org.apache.derby.iapi.store.access.TransactionController)8 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)8 SQLLongint (org.apache.derby.iapi.types.SQLLongint)8 LanguageConnectionContext (org.apache.derby.iapi.sql.conn.LanguageConnectionContext)7 DependencyManager (org.apache.derby.iapi.sql.depend.DependencyManager)7 ConstraintDescriptor (org.apache.derby.iapi.sql.dictionary.ConstraintDescriptor)7 DataDictionary (org.apache.derby.iapi.sql.dictionary.DataDictionary)7 RowLocation (org.apache.derby.iapi.types.RowLocation)7 DefaultInfoImpl (org.apache.derby.catalog.types.DefaultInfoImpl)6 ConstraintDescriptorList (org.apache.derby.iapi.sql.dictionary.ConstraintDescriptorList)6 DefaultDescriptor (org.apache.derby.iapi.sql.dictionary.DefaultDescriptor)6