Search in sources :

Example 11 with Command

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

the class Parser method parseSetBinaryCollation.

private Set parseSetBinaryCollation() {
    Set command = new Set(session, SetTypes.BINARY_COLLATION);
    String name = readAliasIdentifier();
    command.setString(name);
    if (equalsToken(name, CompareMode.UNSIGNED) || equalsToken(name, CompareMode.SIGNED)) {
        return command;
    }
    throw DbException.getInvalidValueException("BINARY_COLLATION", name);
}
Also used : Set(org.h2.command.dml.Set) LinkedHashSet(java.util.LinkedHashSet) AlterTableSet(org.h2.command.dml.AlterTableSet) HashSet(java.util.HashSet) ValueString(org.h2.value.ValueString)

Example 12 with Command

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

the class Parser method parseCreateAggregate.

private CreateAggregate parseCreateAggregate(boolean force) {
    boolean ifNotExists = readIfNotExists();
    CreateAggregate command = new CreateAggregate(session);
    command.setForce(force);
    String name = readIdentifierWithSchema();
    if (isKeyword(name) || Function.getFunction(database, name) != null || getAggregateType(name) != null) {
        throw DbException.get(ErrorCode.FUNCTION_ALIAS_ALREADY_EXISTS_1, name);
    }
    command.setName(name);
    command.setSchema(getSchema());
    command.setIfNotExists(ifNotExists);
    read("FOR");
    command.setJavaClassMethod(readUniqueIdentifier());
    return command;
}
Also used : ValueString(org.h2.value.ValueString) CreateAggregate(org.h2.command.ddl.CreateAggregate)

Example 13 with Command

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

the class Parser method parseCreateFunctionAlias.

private CreateFunctionAlias parseCreateFunctionAlias(boolean force) {
    boolean ifNotExists = readIfNotExists();
    String aliasName = readIdentifierWithSchema();
    final boolean newAliasSameNameAsBuiltin = Function.getFunction(database, aliasName) != null;
    if (database.isAllowBuiltinAliasOverride() && newAliasSameNameAsBuiltin) {
    // fine
    } else if (isKeyword(aliasName) || newAliasSameNameAsBuiltin || getAggregateType(aliasName) != null) {
        throw DbException.get(ErrorCode.FUNCTION_ALIAS_ALREADY_EXISTS_1, aliasName);
    }
    CreateFunctionAlias command = new CreateFunctionAlias(session, getSchema());
    command.setForce(force);
    command.setAliasName(aliasName);
    command.setIfNotExists(ifNotExists);
    command.setDeterministic(readIf("DETERMINISTIC"));
    command.setBufferResultSetToLocalTemp(!readIf("NOBUFFER"));
    if (readIf("AS")) {
        command.setSource(readString());
    } else {
        read("FOR");
        command.setJavaClassMethod(readUniqueIdentifier());
    }
    return command;
}
Also used : ValueString(org.h2.value.ValueString) CreateFunctionAlias(org.h2.command.ddl.CreateFunctionAlias)

Example 14 with Command

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

the class Parser method parseAlterSequence.

private AlterSequence parseAlterSequence() {
    boolean ifExists = readIfExists(false);
    String sequenceName = readIdentifierWithSchema();
    AlterSequence command = new AlterSequence(session, getSchema());
    command.setSequenceName(sequenceName);
    command.setIfExists(ifExists);
    while (true) {
        if (readIf("RESTART")) {
            read("WITH");
            command.setStartWith(readExpression());
        } else if (readIf("INCREMENT")) {
            read("BY");
            command.setIncrement(readExpression());
        } else if (readIf("MINVALUE")) {
            command.setMinValue(readExpression());
        } else if (readIf("NOMINVALUE")) {
            command.setMinValue(null);
        } else if (readIf("MAXVALUE")) {
            command.setMaxValue(readExpression());
        } else if (readIf("NOMAXVALUE")) {
            command.setMaxValue(null);
        } else if (readIf("CYCLE")) {
            command.setCycle(true);
        } else if (readIf("NOCYCLE")) {
            command.setCycle(false);
        } else if (readIf("NO")) {
            if (readIf("MINVALUE")) {
                command.setMinValue(null);
            } else if (readIf("MAXVALUE")) {
                command.setMaxValue(null);
            } else if (readIf("CYCLE")) {
                command.setCycle(false);
            } else if (readIf("CACHE")) {
                command.setCacheSize(ValueExpression.get(ValueLong.get(1)));
            } else {
                break;
            }
        } else if (readIf("CACHE")) {
            command.setCacheSize(readExpression());
        } else if (readIf("NOCACHE")) {
            command.setCacheSize(ValueExpression.get(ValueLong.get(1)));
        } else {
            break;
        }
    }
    return command;
}
Also used : AlterSequence(org.h2.command.dml.AlterSequence) ValueString(org.h2.value.ValueString)

Example 15 with Command

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

the class Parser method parseMerge.

private Prepared parseMerge() {
    Merge command = new Merge(session);
    currentPrepared = command;
    int start = lastParseIndex;
    read("INTO");
    List<String> excludeIdentifiers = Arrays.asList("USING", "KEY", "VALUES");
    TableFilter targetTableFilter = readSimpleTableFilter(0, excludeIdentifiers);
    command.setTargetTableFilter(targetTableFilter);
    Table table = command.getTargetTable();
    if (readIf("USING")) {
        return parseMergeUsing(command, start);
    }
    if (readIf("(")) {
        if (isSelect()) {
            command.setQuery(parseSelect());
            read(")");
            return command;
        }
        Column[] columns = parseColumnList(table);
        command.setColumns(columns);
    }
    if (readIf("KEY")) {
        read("(");
        Column[] keys = parseColumnList(table);
        command.setKeys(keys);
    }
    if (readIf("VALUES")) {
        do {
            ArrayList<Expression> values = New.arrayList();
            read("(");
            if (!readIf(")")) {
                do {
                    if (readIf("DEFAULT")) {
                        values.add(null);
                    } else {
                        values.add(readExpression());
                    }
                } while (readIfMore(false));
            }
            command.addRow(values.toArray(new Expression[0]));
        } while (readIf(","));
    } else {
        command.setQuery(parseSelect());
    }
    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) Merge(org.h2.command.dml.Merge) TableFilter(org.h2.table.TableFilter) AlterTableRenameColumn(org.h2.command.ddl.AlterTableRenameColumn) AlterTableAlterColumn(org.h2.command.ddl.AlterTableAlterColumn) Column(org.h2.table.Column) ExpressionColumn(org.h2.expression.ExpressionColumn) IndexColumn(org.h2.table.IndexColumn) Expression(org.h2.expression.Expression) ValueExpression(org.h2.expression.ValueExpression) ValueString(org.h2.value.ValueString) AlterTableRenameConstraint(org.h2.command.ddl.AlterTableRenameConstraint) AlterTableAddConstraint(org.h2.command.ddl.AlterTableAddConstraint) AlterTableDropConstraint(org.h2.command.ddl.AlterTableDropConstraint)

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