Search in sources :

Example 36 with Command

use of org.h2.command.Command in project h2database by h2database.

the class Parser method parseSelectUnionExtension.

private Query parseSelectUnionExtension(Query command, int start, boolean unionOnly) {
    while (true) {
        if (readIf("UNION")) {
            SelectUnion union = new SelectUnion(session, command);
            if (readIf("ALL")) {
                union.setUnionType(SelectUnion.UnionType.UNION_ALL);
            } else {
                readIf("DISTINCT");
                union.setUnionType(SelectUnion.UnionType.UNION);
            }
            union.setRight(parseSelectSub());
            command = union;
        } else if (readIf("MINUS") || readIf("EXCEPT")) {
            SelectUnion union = new SelectUnion(session, command);
            union.setUnionType(SelectUnion.UnionType.EXCEPT);
            union.setRight(parseSelectSub());
            command = union;
        } else if (readIf("INTERSECT")) {
            SelectUnion union = new SelectUnion(session, command);
            union.setUnionType(SelectUnion.UnionType.INTERSECT);
            union.setRight(parseSelectSub());
            command = union;
        } else {
            break;
        }
    }
    if (!unionOnly) {
        parseEndOfQuery(command);
    }
    setSQL(command, null, start);
    return command;
}
Also used : SelectUnion(org.h2.command.dml.SelectUnion)

Example 37 with Command

use of org.h2.command.Command in project h2database by h2database.

the class Parser method parseCreateTrigger.

private CreateTrigger parseCreateTrigger(boolean force) {
    boolean ifNotExists = readIfNotExists();
    String triggerName = readIdentifierWithSchema(null);
    Schema schema = getSchema();
    boolean insteadOf, isBefore;
    if (readIf("INSTEAD")) {
        read("OF");
        isBefore = true;
        insteadOf = true;
    } else if (readIf("BEFORE")) {
        insteadOf = false;
        isBefore = true;
    } else {
        read("AFTER");
        insteadOf = false;
        isBefore = false;
    }
    int typeMask = 0;
    boolean onRollback = false;
    do {
        if (readIf("INSERT")) {
            typeMask |= Trigger.INSERT;
        } else if (readIf("UPDATE")) {
            typeMask |= Trigger.UPDATE;
        } else if (readIf("DELETE")) {
            typeMask |= Trigger.DELETE;
        } else if (readIf("SELECT")) {
            typeMask |= Trigger.SELECT;
        } else if (readIf("ROLLBACK")) {
            onRollback = true;
        } else {
            throw getSyntaxError();
        }
    } while (readIf(","));
    read("ON");
    String tableName = readIdentifierWithSchema();
    checkSchema(schema);
    CreateTrigger command = new CreateTrigger(session, getSchema());
    command.setForce(force);
    command.setTriggerName(triggerName);
    command.setIfNotExists(ifNotExists);
    command.setInsteadOf(insteadOf);
    command.setBefore(isBefore);
    command.setOnRollback(onRollback);
    command.setTypeMask(typeMask);
    command.setTableName(tableName);
    if (readIf("FOR")) {
        read("EACH");
        read("ROW");
        command.setRowBased(true);
    } else {
        command.setRowBased(false);
    }
    if (readIf("QUEUE")) {
        command.setQueueSize(readPositiveInt());
    }
    command.setNoWait(readIf("NOWAIT"));
    if (readIf("AS")) {
        command.setTriggerSource(readString());
    } else {
        read("CALL");
        command.setTriggerClassName(readUniqueIdentifier());
    }
    return command;
}
Also used : CreateTrigger(org.h2.command.ddl.CreateTrigger) DropSchema(org.h2.command.ddl.DropSchema) CreateSchema(org.h2.command.ddl.CreateSchema) Schema(org.h2.schema.Schema) ValueString(org.h2.value.ValueString) AlterTableRenameConstraint(org.h2.command.ddl.AlterTableRenameConstraint) AlterTableAddConstraint(org.h2.command.ddl.AlterTableAddConstraint) AlterTableDropConstraint(org.h2.command.ddl.AlterTableDropConstraint)

Example 38 with Command

use of org.h2.command.Command in project h2database by h2database.

the class Parser method parseWithStatementOrQuery.

private Prepared parseWithStatementOrQuery() {
    int paramIndex = parameters.size();
    Prepared command = parseWith();
    ArrayList<Parameter> params = New.arrayList();
    for (int i = paramIndex, size = parameters.size(); i < size; i++) {
        params.add(parameters.get(i));
    }
    command.setParameterList(params);
    if (command instanceof Query) {
        Query query = (Query) command;
        query.init();
    }
    return command;
}
Also used : Query(org.h2.command.dml.Query) Parameter(org.h2.expression.Parameter) ConditionInParameter(org.h2.expression.ConditionInParameter) AlterTableRenameConstraint(org.h2.command.ddl.AlterTableRenameConstraint) AlterTableAddConstraint(org.h2.command.ddl.AlterTableAddConstraint) AlterTableDropConstraint(org.h2.command.ddl.AlterTableDropConstraint)

Example 39 with Command

use of org.h2.command.Command in project h2database by h2database.

the class Parser method parseGrantRevoke.

private GrantRevoke parseGrantRevoke(int operationType) {
    GrantRevoke command = new GrantRevoke(session);
    command.setOperationType(operationType);
    boolean tableClauseExpected = addRoleOrRight(command);
    while (readIf(",")) {
        addRoleOrRight(command);
        if (command.isRightMode() && command.isRoleMode()) {
            throw DbException.get(ErrorCode.ROLES_AND_RIGHT_CANNOT_BE_MIXED);
        }
    }
    if (tableClauseExpected) {
        if (readIf("ON")) {
            if (readIf("SCHEMA")) {
                Schema schema = database.getSchema(readAliasIdentifier());
                command.setSchema(schema);
            } else {
                do {
                    Table table = readTableOrView();
                    command.addTable(table);
                } while (readIf(","));
            }
        }
    }
    if (operationType == CommandInterface.GRANT) {
        read("TO");
    } else {
        read("FROM");
    }
    command.setGranteeName(readUniqueIdentifier());
    return command;
}
Also used : RangeTable(org.h2.table.RangeTable) TruncateTable(org.h2.command.ddl.TruncateTable) CreateTable(org.h2.command.ddl.CreateTable) FunctionTable(org.h2.table.FunctionTable) CreateLinkedTable(org.h2.command.ddl.CreateLinkedTable) Table(org.h2.table.Table) DropTable(org.h2.command.ddl.DropTable) DropSchema(org.h2.command.ddl.DropSchema) CreateSchema(org.h2.command.ddl.CreateSchema) Schema(org.h2.schema.Schema) GrantRevoke(org.h2.command.ddl.GrantRevoke)

Example 40 with Command

use of org.h2.command.Command in project h2database by h2database.

the class Parser method parseCommit.

private TransactionCommand parseCommit() {
    TransactionCommand command;
    if (readIf("TRANSACTION")) {
        command = new TransactionCommand(session, CommandInterface.COMMIT_TRANSACTION);
        command.setTransactionName(readUniqueIdentifier());
        return command;
    }
    command = new TransactionCommand(session, CommandInterface.COMMIT);
    readIf("WORK");
    return command;
}
Also used : TransactionCommand(org.h2.command.dml.TransactionCommand)

Aggregations

ValueString (org.h2.value.ValueString)37 Expression (org.h2.expression.Expression)20 ValueExpression (org.h2.expression.ValueExpression)19 AlterTableAddConstraint (org.h2.command.ddl.AlterTableAddConstraint)17 AlterTableDropConstraint (org.h2.command.ddl.AlterTableDropConstraint)16 AlterTableRenameConstraint (org.h2.command.ddl.AlterTableRenameConstraint)16 Column (org.h2.table.Column)16 IndexColumn (org.h2.table.IndexColumn)13 AlterTableAlterColumn (org.h2.command.ddl.AlterTableAlterColumn)12 ExpressionColumn (org.h2.expression.ExpressionColumn)12 Table (org.h2.table.Table)12 AlterTableRenameColumn (org.h2.command.ddl.AlterTableRenameColumn)11 Connection (java.sql.Connection)10 CreateLinkedTable (org.h2.command.ddl.CreateLinkedTable)10 CreateSchema (org.h2.command.ddl.CreateSchema)10 CreateTable (org.h2.command.ddl.CreateTable)10 DropSchema (org.h2.command.ddl.DropSchema)10 DropTable (org.h2.command.ddl.DropTable)10 Schema (org.h2.schema.Schema)10 TruncateTable (org.h2.command.ddl.TruncateTable)9