Search in sources :

Example 96 with Column

use of org.gridgain.internal.h2.table.Column in project h2database by h2database.

the class ConstraintReferential method checkRowRefTable.

private void checkRowRefTable(SessionLocal session, Row oldRow, Row newRow) {
    if (oldRow == null) {
        // this is an insert
        return;
    }
    if (newRow != null && isEqual(oldRow, newRow)) {
        // on an update, if both old and new are the same, don't do anything
        return;
    }
    if (newRow == null) {
        // this is a delete
        if (deleteAction == ConstraintActionType.RESTRICT) {
            checkRow(session, oldRow);
        } else {
            int i = deleteAction == ConstraintActionType.CASCADE ? 0 : columns.length;
            Prepared deleteCommand = getDelete(session);
            setWhere(deleteCommand, i, oldRow);
            updateWithSkipCheck(deleteCommand);
        }
    } else {
        // this is an update
        if (updateAction == ConstraintActionType.RESTRICT) {
            checkRow(session, oldRow);
        } else {
            Prepared updateCommand = getUpdate(session);
            if (updateAction == ConstraintActionType.CASCADE) {
                ArrayList<Parameter> params = updateCommand.getParameters();
                for (int i = 0, len = columns.length; i < len; i++) {
                    Parameter param = params.get(i);
                    Column refCol = refColumns[i].column;
                    param.setValue(newRow.getValue(refCol.getColumnId()));
                }
            }
            setWhere(updateCommand, columns.length, oldRow);
            updateWithSkipCheck(updateCommand);
        }
    }
}
Also used : Column(org.h2.table.Column) IndexColumn(org.h2.table.IndexColumn) Prepared(org.h2.command.Prepared) Parameter(org.h2.expression.Parameter)

Example 97 with Column

use of org.gridgain.internal.h2.table.Column in project h2database by h2database.

the class DatabaseMetaLocal method addPrivilege.

private void addPrivilege(SimpleResult result, Value catalogValue, Value schemaValue, Value tableValue, Value granteeValue, String right, boolean isAdmin, CompareLike columnLike, Column[] columns) {
    if (columns == null) {
        result.addRow(// TABLE_CAT
        catalogValue, // TABLE_SCHEM
        schemaValue, // TABLE_NAME
        tableValue, // GRANTOR
        ValueNull.INSTANCE, // GRANTEE
        granteeValue, // PRIVILEGE
        getString(right), // IS_GRANTABLE
        isAdmin ? YES : NO);
    } else {
        for (Column column : columns) {
            String columnName = column.getName();
            if (columnLike != null && !columnLike.test(columnName)) {
                continue;
            }
            result.addRow(// TABLE_CAT
            catalogValue, // TABLE_SCHEM
            schemaValue, // TABLE_NAME
            tableValue, // COLUMN_NAME
            getString(columnName), // GRANTOR
            ValueNull.INSTANCE, // GRANTEE
            granteeValue, // PRIVILEGE
            getString(right), // IS_GRANTABLE
            isAdmin ? YES : NO);
        }
    }
}
Also used : Column(org.h2.table.Column) IndexColumn(org.h2.table.IndexColumn)

Example 98 with Column

use of org.gridgain.internal.h2.table.Column in project h2database by h2database.

the class Parser method parseAlterTableDrop.

private Prepared parseAlterTableDrop(Schema schema, String tableName, boolean ifTableExists) {
    if (readIf(CONSTRAINT)) {
        boolean ifExists = readIfExists(false);
        String constraintName = readIdentifierWithSchema(schema.getName());
        ifExists = readIfExists(ifExists);
        checkSchema(schema);
        AlterTableDropConstraint command = new AlterTableDropConstraint(session, getSchema(), ifExists);
        command.setTableName(tableName);
        command.setIfTableExists(ifTableExists);
        command.setConstraintName(constraintName);
        ConstraintActionType dropAction = parseCascadeOrRestrict();
        if (dropAction != null) {
            command.setDropAction(dropAction);
        }
        return command;
    } else if (readIf(PRIMARY)) {
        read(KEY);
        Table table = tableIfTableExists(schema, tableName, ifTableExists);
        if (table == null) {
            return new NoOperation(session);
        }
        Index idx = table.getPrimaryKey();
        DropIndex command = new DropIndex(session, schema);
        command.setIndexName(idx.getName());
        return command;
    } else if (database.getMode().alterTableExtensionsMySQL) {
        Prepared command = parseAlterTableDropCompatibility(schema, tableName, ifTableExists);
        if (command != null) {
            return command;
        }
    }
    readIf("COLUMN");
    boolean ifExists = readIfExists(false);
    ArrayList<Column> columnsToRemove = new ArrayList<>();
    Table table = tableIfTableExists(schema, tableName, ifTableExists);
    // For Oracle compatibility - open bracket required
    boolean openingBracketDetected = readIf(OPEN_PAREN);
    do {
        String columnName = readIdentifier();
        if (table != null) {
            Column column = table.getColumn(columnName, ifExists);
            if (column != null) {
                columnsToRemove.add(column);
            }
        }
    } while (readIf(COMMA));
    if (openingBracketDetected) {
        // For Oracle compatibility - close bracket
        read(CLOSE_PAREN);
    }
    if (table == null || columnsToRemove.isEmpty()) {
        return new NoOperation(session);
    }
    AlterTableAlterColumn command = new AlterTableAlterColumn(session, schema);
    command.setType(CommandInterface.ALTER_TABLE_DROP_COLUMN);
    command.setTableName(tableName);
    command.setIfTableExists(ifTableExists);
    command.setColumnsToRemove(columnsToRemove);
    return command;
}
Also used : DataChangeDeltaTable(org.h2.table.DataChangeDeltaTable) DualTable(org.h2.table.DualTable) CreateLinkedTable(org.h2.command.ddl.CreateLinkedTable) Table(org.h2.table.Table) RangeTable(org.h2.table.RangeTable) DropTable(org.h2.command.ddl.DropTable) TruncateTable(org.h2.command.ddl.TruncateTable) FunctionTable(org.h2.table.FunctionTable) QueryExpressionTable(org.h2.table.QueryExpressionTable) CreateTable(org.h2.command.ddl.CreateTable) ArrayList(java.util.ArrayList) DropIndex(org.h2.command.ddl.DropIndex) Index(org.h2.index.Index) CreateIndex(org.h2.command.ddl.CreateIndex) AlterTableAlterColumn(org.h2.command.ddl.AlterTableAlterColumn) AlterTableDropConstraint(org.h2.command.ddl.AlterTableDropConstraint) NoOperation(org.h2.command.dml.NoOperation) AlterTableRenameColumn(org.h2.command.ddl.AlterTableRenameColumn) IndexColumn(org.h2.table.IndexColumn) ExpressionColumn(org.h2.expression.ExpressionColumn) AlterTableAlterColumn(org.h2.command.ddl.AlterTableAlterColumn) Column(org.h2.table.Column) ConstraintActionType(org.h2.constraint.ConstraintActionType) DropIndex(org.h2.command.ddl.DropIndex)

Example 99 with Column

use of org.gridgain.internal.h2.table.Column in project h2database by h2database.

the class Parser method getColumnWithDomain.

private static Column getColumnWithDomain(String columnName, Domain domain) {
    Column column = new Column(columnName, domain.getDataType());
    column.setComment(domain.getComment());
    column.setDomain(domain);
    return column;
}
Also used : AlterTableRenameColumn(org.h2.command.ddl.AlterTableRenameColumn) IndexColumn(org.h2.table.IndexColumn) ExpressionColumn(org.h2.expression.ExpressionColumn) AlterTableAlterColumn(org.h2.command.ddl.AlterTableAlterColumn) Column(org.h2.table.Column)

Example 100 with Column

use of org.gridgain.internal.h2.table.Column in project h2database by h2database.

the class Parser method parseColumnForTable.

private Column parseColumnForTable(String columnName, boolean defaultNullable) {
    Column column;
    Mode mode = database.getMode();
    if (mode.identityDataType && readIf("IDENTITY")) {
        column = new Column(columnName, TypeInfo.TYPE_BIGINT);
        parseCompatibilityIdentityOptions(column);
        column.setPrimaryKey(true);
    } else if (mode.serialDataTypes && readIf("BIGSERIAL")) {
        column = new Column(columnName, TypeInfo.TYPE_BIGINT);
        column.setIdentityOptions(new SequenceOptions(), false);
    } else if (mode.serialDataTypes && readIf("SERIAL")) {
        column = new Column(columnName, TypeInfo.TYPE_INTEGER);
        column.setIdentityOptions(new SequenceOptions(), false);
    } else {
        column = parseColumnWithType(columnName);
    }
    if (readIf("INVISIBLE")) {
        column.setVisible(false);
    } else if (readIf("VISIBLE")) {
        column.setVisible(true);
    }
    boolean defaultOnNull = false;
    NullConstraintType nullConstraint = parseNotNullConstraint();
    defaultIdentityGeneration: if (!column.isIdentity()) {
        if (readIf(AS)) {
            column.setGeneratedExpression(readExpression());
        } else if (readIf(DEFAULT)) {
            if (readIf(ON)) {
                read(NULL);
                defaultOnNull = true;
                break defaultIdentityGeneration;
            }
            column.setDefaultExpression(session, readExpression());
        } else if (readIf("GENERATED")) {
            boolean always = readIf("ALWAYS");
            if (!always) {
                read("BY");
                read(DEFAULT);
            }
            read(AS);
            if (readIf("IDENTITY")) {
                SequenceOptions options = new SequenceOptions();
                if (readIf(OPEN_PAREN)) {
                    parseSequenceOptions(options, null, false, false);
                    read(CLOSE_PAREN);
                }
                column.setIdentityOptions(options, always);
                break defaultIdentityGeneration;
            } else if (!always) {
                throw getSyntaxError();
            } else {
                column.setGeneratedExpression(readExpression());
            }
        }
        if (!column.isGenerated() && readIf(ON)) {
            read("UPDATE");
            column.setOnUpdateExpression(session, readExpression());
        }
        nullConstraint = parseNotNullConstraint(nullConstraint);
        if (parseCompatibilityIdentity(column, mode)) {
            nullConstraint = parseNotNullConstraint(nullConstraint);
        }
    }
    switch(nullConstraint) {
        case NULL_IS_ALLOWED:
            if (column.isIdentity()) {
                throw DbException.get(ErrorCode.COLUMN_MUST_NOT_BE_NULLABLE_1, column.getName());
            }
            column.setNullable(true);
            break;
        case NULL_IS_NOT_ALLOWED:
            column.setNullable(false);
            break;
        case NO_NULL_CONSTRAINT_FOUND:
            if (!column.isIdentity()) {
                column.setNullable(defaultNullable);
            }
            break;
        default:
            throw DbException.get(ErrorCode.UNKNOWN_MODE_1, "Internal Error - unhandled case: " + nullConstraint.name());
    }
    if (!defaultOnNull) {
        if (readIf(DEFAULT)) {
            read(ON);
            read(NULL);
            defaultOnNull = true;
        } else if (readIf("NULL_TO_DEFAULT")) {
            defaultOnNull = true;
        }
    }
    if (defaultOnNull) {
        column.setDefaultOnNull(true);
    }
    if (!column.isGenerated()) {
        if (readIf("SEQUENCE")) {
            column.setSequence(readSequence(), column.isGeneratedAlways());
        }
    }
    if (readIf("SELECTIVITY")) {
        column.setSelectivity(readNonNegativeInt());
    }
    if (mode.getEnum() == ModeEnum.MySQL) {
        if (readIf("CHARACTER")) {
            readIf(SET);
            readMySQLCharset();
        }
        if (readIf("COLLATE")) {
            readMySQLCharset();
        }
    }
    String comment = readCommentIf();
    if (comment != null) {
        column.setComment(comment);
    }
    return column;
}
Also used : AlterTableRenameColumn(org.h2.command.ddl.AlterTableRenameColumn) IndexColumn(org.h2.table.IndexColumn) ExpressionColumn(org.h2.expression.ExpressionColumn) AlterTableAlterColumn(org.h2.command.ddl.AlterTableAlterColumn) Column(org.h2.table.Column) Mode(org.h2.engine.Mode) CompareMode(org.h2.value.CompareMode) SequenceOptions(org.h2.command.ddl.SequenceOptions)

Aggregations

Column (org.h2.table.Column)300 IndexColumn (org.h2.table.IndexColumn)156 Column (org.gridgain.internal.h2.table.Column)150 ExpressionColumn (org.h2.expression.ExpressionColumn)117 Expression (org.h2.expression.Expression)94 Value (org.gridgain.internal.h2.value.Value)88 IndexColumn (org.gridgain.internal.h2.table.IndexColumn)82 ArrayList (java.util.ArrayList)81 DbException (org.gridgain.internal.h2.message.DbException)70 SQLException (java.sql.SQLException)69 AlterTableAlterColumn (org.h2.command.ddl.AlterTableAlterColumn)68 Value (org.h2.value.Value)63 ExpressionColumn (org.gridgain.internal.h2.expression.ExpressionColumn)59 AlterTableRenameColumn (org.h2.command.ddl.AlterTableRenameColumn)59 Table (org.h2.table.Table)52 Expression (org.gridgain.internal.h2.expression.Expression)50 ValueExpression (org.h2.expression.ValueExpression)48 Index (org.h2.index.Index)46 IgniteSQLException (org.apache.ignite.internal.processors.query.IgniteSQLException)40 Database (org.h2.engine.Database)35