Search in sources :

Example 96 with Command

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

the class Parser method parseDropUserDataType.

private DropUserDataType parseDropUserDataType() {
    boolean ifExists = readIfExists(false);
    DropUserDataType command = new DropUserDataType(session);
    command.setTypeName(readUniqueIdentifier());
    ifExists = readIfExists(ifExists);
    command.setIfExists(ifExists);
    return command;
}
Also used : DropUserDataType(org.h2.command.ddl.DropUserDataType)

Example 97 with Command

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

the class Parser method parseAlterView.

private AlterView parseAlterView() {
    AlterView command = new AlterView(session);
    boolean ifExists = readIfExists(false);
    command.setIfExists(ifExists);
    String viewName = readIdentifierWithSchema();
    Table tableView = getSchema().findTableOrView(session, viewName);
    if (!(tableView instanceof TableView) && !ifExists) {
        throw DbException.get(ErrorCode.VIEW_NOT_FOUND_1, viewName);
    }
    TableView view = (TableView) tableView;
    command.setView(view);
    read("RECOMPILE");
    return command;
}
Also used : AlterView(org.h2.command.ddl.AlterView) 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) ValueString(org.h2.value.ValueString) TableView(org.h2.table.TableView)

Example 98 with Command

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

the class Parser method parseSelectSub.

private Query parseSelectSub() {
    if (readIf("(")) {
        Query command = parseSelectUnion();
        read(")");
        return command;
    }
    if (readIf("WITH")) {
        Query query = null;
        try {
            query = (Query) parseWith();
        } catch (ClassCastException e) {
            throw DbException.get(ErrorCode.SYNTAX_ERROR_1, "WITH statement supports only SELECT (query) in this context");
        }
        // recursive can not be lazy
        query.setNeverLazy(true);
        return query;
    }
    return parseSelectSimple();
}
Also used : Query(org.h2.command.dml.Query)

Example 99 with Command

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

the class Parser method parseSelectSimpleSelectPart.

private void parseSelectSimpleSelectPart(Select command) {
    Select temp = currentSelect;
    // make sure aggregate functions will not work in TOP and LIMIT
    currentSelect = null;
    if (readIf("TOP")) {
        // can't read more complex expressions here because
        // SELECT TOP 1 +? A FROM TEST could mean
        // SELECT TOP (1+?) A FROM TEST or
        // SELECT TOP 1 (+?) AS A FROM TEST
        Expression limit = readTerm().optimize(session);
        command.setLimit(limit);
    } else if (readIf("LIMIT")) {
        Expression offset = readTerm().optimize(session);
        command.setOffset(offset);
        Expression limit = readTerm().optimize(session);
        command.setLimit(limit);
    }
    currentSelect = temp;
    if (readIf("DISTINCT")) {
        command.setDistinct(true);
    } else {
        readIf("ALL");
    }
    ArrayList<Expression> expressions = New.arrayList();
    do {
        if (readIf("*")) {
            expressions.add(new Wildcard(null, null));
        } else {
            Expression expr = readExpression();
            if (readIf("AS") || currentTokenType == IDENTIFIER) {
                String alias = readAliasIdentifier();
                boolean aliasColumnName = database.getSettings().aliasColumnName;
                aliasColumnName |= database.getMode().aliasColumnName;
                expr = new Alias(expr, alias, aliasColumnName);
            }
            expressions.add(expr);
        }
    } while (readIf(","));
    command.setExpressions(expressions);
}
Also used : Expression(org.h2.expression.Expression) ValueExpression(org.h2.expression.ValueExpression) Wildcard(org.h2.expression.Wildcard) CreateFunctionAlias(org.h2.command.ddl.CreateFunctionAlias) FunctionAlias(org.h2.engine.FunctionAlias) DropFunctionAlias(org.h2.command.ddl.DropFunctionAlias) Alias(org.h2.expression.Alias) ConditionInSelect(org.h2.expression.ConditionInSelect) Select(org.h2.command.dml.Select) ValueString(org.h2.value.ValueString)

Example 100 with Command

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

the class Parser method parseDrop.

private Prepared parseDrop() {
    if (readIf("TABLE")) {
        boolean ifExists = readIfExists(false);
        String tableName = readIdentifierWithSchema();
        DropTable command = new DropTable(session, getSchema());
        command.setTableName(tableName);
        while (readIf(",")) {
            tableName = readIdentifierWithSchema();
            DropTable next = new DropTable(session, getSchema());
            next.setTableName(tableName);
            command.addNextDropTable(next);
        }
        ifExists = readIfExists(ifExists);
        command.setIfExists(ifExists);
        if (readIf("CASCADE")) {
            command.setDropAction(ConstraintActionType.CASCADE);
            readIf("CONSTRAINTS");
        } else if (readIf("RESTRICT")) {
            command.setDropAction(ConstraintActionType.RESTRICT);
        } else if (readIf("IGNORE")) {
            command.setDropAction(ConstraintActionType.SET_DEFAULT);
        }
        return command;
    } else if (readIf("INDEX")) {
        boolean ifExists = readIfExists(false);
        String indexName = readIdentifierWithSchema();
        DropIndex command = new DropIndex(session, getSchema());
        command.setIndexName(indexName);
        ifExists = readIfExists(ifExists);
        command.setIfExists(ifExists);
        // Support for MySQL: DROP INDEX index_name ON tbl_name
        if (readIf("ON")) {
            readIdentifierWithSchema();
        }
        return command;
    } else if (readIf("USER")) {
        boolean ifExists = readIfExists(false);
        DropUser command = new DropUser(session);
        command.setUserName(readUniqueIdentifier());
        ifExists = readIfExists(ifExists);
        readIf("CASCADE");
        command.setIfExists(ifExists);
        return command;
    } else if (readIf("SEQUENCE")) {
        boolean ifExists = readIfExists(false);
        String sequenceName = readIdentifierWithSchema();
        DropSequence command = new DropSequence(session, getSchema());
        command.setSequenceName(sequenceName);
        ifExists = readIfExists(ifExists);
        command.setIfExists(ifExists);
        return command;
    } else if (readIf("CONSTANT")) {
        boolean ifExists = readIfExists(false);
        String constantName = readIdentifierWithSchema();
        DropConstant command = new DropConstant(session, getSchema());
        command.setConstantName(constantName);
        ifExists = readIfExists(ifExists);
        command.setIfExists(ifExists);
        return command;
    } else if (readIf("TRIGGER")) {
        boolean ifExists = readIfExists(false);
        String triggerName = readIdentifierWithSchema();
        DropTrigger command = new DropTrigger(session, getSchema());
        command.setTriggerName(triggerName);
        ifExists = readIfExists(ifExists);
        command.setIfExists(ifExists);
        return command;
    } else if (readIf("VIEW")) {
        boolean ifExists = readIfExists(false);
        String viewName = readIdentifierWithSchema();
        DropView command = new DropView(session, getSchema());
        command.setViewName(viewName);
        ifExists = readIfExists(ifExists);
        command.setIfExists(ifExists);
        ConstraintActionType dropAction = parseCascadeOrRestrict();
        if (dropAction != null) {
            command.setDropAction(dropAction);
        }
        return command;
    } else if (readIf("ROLE")) {
        boolean ifExists = readIfExists(false);
        DropRole command = new DropRole(session);
        command.setRoleName(readUniqueIdentifier());
        ifExists = readIfExists(ifExists);
        command.setIfExists(ifExists);
        return command;
    } else if (readIf("ALIAS")) {
        boolean ifExists = readIfExists(false);
        String aliasName = readIdentifierWithSchema();
        DropFunctionAlias command = new DropFunctionAlias(session, getSchema());
        command.setAliasName(aliasName);
        ifExists = readIfExists(ifExists);
        command.setIfExists(ifExists);
        return command;
    } else if (readIf("SCHEMA")) {
        boolean ifExists = readIfExists(false);
        DropSchema command = new DropSchema(session);
        command.setSchemaName(readUniqueIdentifier());
        ifExists = readIfExists(ifExists);
        command.setIfExists(ifExists);
        if (readIf("CASCADE")) {
            command.setDropAction(ConstraintActionType.CASCADE);
        } else if (readIf("RESTRICT")) {
            command.setDropAction(ConstraintActionType.RESTRICT);
        }
        return command;
    } else if (readIf("ALL")) {
        read("OBJECTS");
        DropDatabase command = new DropDatabase(session);
        command.setDropAllObjects(true);
        if (readIf("DELETE")) {
            read("FILES");
            command.setDeleteFiles(true);
        }
        return command;
    } else if (readIf("DOMAIN")) {
        return parseDropUserDataType();
    } else if (readIf("TYPE")) {
        return parseDropUserDataType();
    } else if (readIf("DATATYPE")) {
        return parseDropUserDataType();
    } else if (readIf("AGGREGATE")) {
        return parseDropAggregate();
    } else if (readIf("SYNONYM")) {
        boolean ifExists = readIfExists(false);
        String synonymName = readIdentifierWithSchema();
        DropSynonym command = new DropSynonym(session, getSchema());
        command.setSynonymName(synonymName);
        ifExists = readIfExists(ifExists);
        command.setIfExists(ifExists);
        return command;
    }
    throw getSyntaxError();
}
Also used : DropConstant(org.h2.command.ddl.DropConstant) DropTrigger(org.h2.command.ddl.DropTrigger) DropView(org.h2.command.ddl.DropView) DropUser(org.h2.command.ddl.DropUser) DropSynonym(org.h2.command.ddl.DropSynonym) DropSequence(org.h2.command.ddl.DropSequence) ValueString(org.h2.value.ValueString) DropTable(org.h2.command.ddl.DropTable) DropSchema(org.h2.command.ddl.DropSchema) DropRole(org.h2.command.ddl.DropRole) DropFunctionAlias(org.h2.command.ddl.DropFunctionAlias) DropDatabase(org.h2.command.ddl.DropDatabase) ConstraintActionType(org.h2.constraint.ConstraintActionType) DropIndex(org.h2.command.ddl.DropIndex)

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