Search in sources :

Example 91 with Command

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

the class Parser method parseCreateLinkedTable.

private CreateLinkedTable parseCreateLinkedTable(boolean temp, boolean globalTemp, boolean force) {
    read("TABLE");
    boolean ifNotExists = readIfNotExists();
    String tableName = readIdentifierWithSchema();
    CreateLinkedTable command = new CreateLinkedTable(session, getSchema());
    command.setTemporary(temp);
    command.setGlobalTemporary(globalTemp);
    command.setForce(force);
    command.setIfNotExists(ifNotExists);
    command.setTableName(tableName);
    command.setComment(readCommentIf());
    read("(");
    command.setDriver(readString());
    read(",");
    command.setUrl(readString());
    read(",");
    command.setUser(readString());
    read(",");
    command.setPassword(readString());
    read(",");
    String originalTable = readString();
    if (readIf(",")) {
        command.setOriginalSchema(originalTable);
        originalTable = readString();
    }
    command.setOriginalTable(originalTable);
    read(")");
    if (readIf("EMIT")) {
        read("UPDATES");
        command.setEmitUpdates(true);
    } else if (readIf("READONLY")) {
        command.setReadOnly(true);
    }
    return command;
}
Also used : CreateLinkedTable(org.h2.command.ddl.CreateLinkedTable) ValueString(org.h2.value.ValueString)

Example 92 with Command

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

the class Parser method parseAlterSchema.

private Prepared parseAlterSchema() {
    boolean ifExists = readIfExists(false);
    String schemaName = readIdentifierWithSchema();
    Schema old = getSchema();
    read("RENAME");
    read("TO");
    String newName = readIdentifierWithSchema(old.getName());
    Schema schema = findSchema(schemaName);
    if (schema == null) {
        if (ifExists) {
            return new NoOperation(session);
        }
        throw DbException.get(ErrorCode.SCHEMA_NOT_FOUND_1, schemaName);
    }
    AlterSchemaRename command = new AlterSchemaRename(session);
    command.setOldSchema(schema);
    checkSchema(old);
    command.setNewName(newName);
    return command;
}
Also used : NoOperation(org.h2.command.dml.NoOperation) DropSchema(org.h2.command.ddl.DropSchema) CreateSchema(org.h2.command.ddl.CreateSchema) Schema(org.h2.schema.Schema) AlterSchemaRename(org.h2.command.ddl.AlterSchemaRename) ValueString(org.h2.value.ValueString)

Example 93 with Command

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

the class Parser method parseSelectSimple.

private Select parseSelectSimple() {
    boolean fromFirst;
    if (readIf("SELECT")) {
        fromFirst = false;
    } else if (readIf("FROM")) {
        fromFirst = true;
    } else {
        throw getSyntaxError();
    }
    Select command = new Select(session);
    int start = lastParseIndex;
    Select oldSelect = currentSelect;
    currentSelect = command;
    currentPrepared = command;
    if (fromFirst) {
        parseSelectSimpleFromPart(command);
        read("SELECT");
        parseSelectSimpleSelectPart(command);
    } else {
        parseSelectSimpleSelectPart(command);
        if (!readIf("FROM")) {
            // select without FROM: convert to SELECT ... FROM
            // SYSTEM_RANGE(1,1)
            Table dual = getDualTable(false);
            TableFilter filter = new TableFilter(session, dual, null, rightsChecked, currentSelect, 0, null);
            command.addTableFilter(filter, true);
        } else {
            parseSelectSimpleFromPart(command);
        }
    }
    if (readIf("WHERE")) {
        Expression condition = readExpression();
        command.addCondition(condition);
    }
    // the group by is read for the outer select (or not a select)
    // so that columns that are not grouped can be used
    currentSelect = oldSelect;
    if (readIf("GROUP")) {
        read("BY");
        command.setGroupQuery();
        ArrayList<Expression> list = New.arrayList();
        do {
            Expression expr = readExpression();
            list.add(expr);
        } while (readIf(","));
        command.setGroupBy(list);
    }
    currentSelect = command;
    if (readIf("HAVING")) {
        command.setGroupQuery();
        Expression condition = readExpression();
        command.setHaving(condition);
    }
    command.setParameterList(parameters);
    currentSelect = oldSelect;
    setSQL(command, "SELECT", start);
    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) TableFilter(org.h2.table.TableFilter) Expression(org.h2.expression.Expression) ValueExpression(org.h2.expression.ValueExpression) ConditionInSelect(org.h2.expression.ConditionInSelect) Select(org.h2.command.dml.Select) AlterTableRenameConstraint(org.h2.command.ddl.AlterTableRenameConstraint) AlterTableAddConstraint(org.h2.command.ddl.AlterTableAddConstraint) AlterTableDropConstraint(org.h2.command.ddl.AlterTableDropConstraint)

Example 94 with Command

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

the class Parser method parseAlterTableAlterColumnType.

private AlterTableAlterColumn parseAlterTableAlterColumnType(Schema schema, String tableName, String columnName, boolean ifTableExists) {
    Column oldColumn = columnIfTableExists(schema, tableName, columnName, ifTableExists);
    Column newColumn = parseColumnForTable(columnName, oldColumn == null ? true : oldColumn.isNullable());
    AlterTableAlterColumn command = new AlterTableAlterColumn(session, schema);
    command.setTableName(tableName);
    command.setIfTableExists(ifTableExists);
    command.setType(CommandInterface.ALTER_TABLE_ALTER_COLUMN_CHANGE_TYPE);
    command.setOldColumn(oldColumn);
    command.setNewColumn(newColumn);
    return command;
}
Also used : 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) AlterTableAlterColumn(org.h2.command.ddl.AlterTableAlterColumn)

Example 95 with Command

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

the class Parser method parseExecute.

private Prepared parseExecute() {
    ExecuteProcedure command = new ExecuteProcedure(session);
    String procedureName = readAliasIdentifier();
    Procedure p = session.getProcedure(procedureName);
    if (p == null) {
        throw DbException.get(ErrorCode.FUNCTION_ALIAS_NOT_FOUND_1, procedureName);
    }
    command.setProcedure(p);
    if (readIf("(")) {
        for (int i = 0; ; i++) {
            command.setExpression(i, readExpression());
            if (readIf(")")) {
                break;
            }
            read(",");
        }
    }
    return command;
}
Also used : ExecuteProcedure(org.h2.command.dml.ExecuteProcedure) Procedure(org.h2.engine.Procedure) DeallocateProcedure(org.h2.command.ddl.DeallocateProcedure) ExecuteProcedure(org.h2.command.dml.ExecuteProcedure) PrepareProcedure(org.h2.command.ddl.PrepareProcedure) 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