Search in sources :

Example 16 with Command

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

the class Parser method parseDeleteGivenTable.

private void parseDeleteGivenTable(Delete command, Expression limit, int start) {
    if (readIf("WHERE")) {
        Expression condition = readExpression();
        command.setCondition(condition);
    }
    if (readIf("LIMIT") && limit == null) {
        limit = readTerm().optimize(session);
    }
    command.setLimit(limit);
    setSQL(command, "DELETE", start);
}
Also used : Expression(org.h2.expression.Expression) ValueExpression(org.h2.expression.ValueExpression)

Example 17 with Command

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

the class Parser method parsePrepare.

private Prepared parsePrepare() {
    if (readIf("COMMIT")) {
        TransactionCommand command = new TransactionCommand(session, CommandInterface.PREPARE_COMMIT);
        command.setTransactionName(readUniqueIdentifier());
        return command;
    }
    String procedureName = readAliasIdentifier();
    if (readIf("(")) {
        ArrayList<Column> list = New.arrayList();
        for (int i = 0; ; i++) {
            Column column = parseColumnForTable("C" + i, true);
            list.add(column);
            if (readIf(")")) {
                break;
            }
            read(",");
        }
    }
    read("AS");
    Prepared prep = parsePrepared();
    PrepareProcedure command = new PrepareProcedure(session);
    command.setProcedureName(procedureName);
    command.setPrepared(prep);
    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) PrepareProcedure(org.h2.command.ddl.PrepareProcedure) TransactionCommand(org.h2.command.dml.TransactionCommand) ValueString(org.h2.value.ValueString) AlterTableRenameConstraint(org.h2.command.ddl.AlterTableRenameConstraint) AlterTableAddConstraint(org.h2.command.ddl.AlterTableAddConstraint) AlterTableDropConstraint(org.h2.command.ddl.AlterTableDropConstraint)

Example 18 with Command

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

the class Parser method parseBackup.

private Prepared parseBackup() {
    BackupCommand command = new BackupCommand(session);
    read("TO");
    command.setFileName(readExpression());
    return command;
}
Also used : BackupCommand(org.h2.command.dml.BackupCommand)

Example 19 with Command

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

the class Parser method parseCreateTable.

private CreateTable parseCreateTable(boolean temp, boolean globalTemp, boolean persistIndexes) {
    boolean ifNotExists = readIfNotExists();
    String tableName = readIdentifierWithSchema();
    if (temp && globalTemp && equalsToken("SESSION", schemaName)) {
        // support weird syntax: declare global temporary table session.xy
        // (...) not logged
        schemaName = session.getCurrentSchemaName();
        globalTemp = false;
    }
    Schema schema = getSchema();
    CreateTable command = new CreateTable(session, schema);
    command.setPersistIndexes(persistIndexes);
    command.setTemporary(temp);
    command.setGlobalTemporary(globalTemp);
    command.setIfNotExists(ifNotExists);
    command.setTableName(tableName);
    command.setComment(readCommentIf());
    if (readIf("(")) {
        if (!readIf(")")) {
            do {
                parseTableColumnDefinition(command, schema, tableName);
            } while (readIfMore(false));
        }
    }
    // Allows "COMMENT='comment'" in DDL statements (MySQL syntax)
    if (readIf("COMMENT")) {
        if (readIf("=")) {
            // read the complete string comment, but nothing with it for now
            readString();
        }
    }
    if (readIf("ENGINE")) {
        if (readIf("=")) {
            // map MySQL engine types onto H2 behavior
            String tableEngine = readUniqueIdentifier();
            if ("InnoDb".equalsIgnoreCase(tableEngine)) {
            // ok
            } else if (!"MyISAM".equalsIgnoreCase(tableEngine)) {
                throw DbException.getUnsupportedException(tableEngine);
            }
        } else {
            command.setTableEngine(readUniqueIdentifier());
        }
    }
    if (readIf("WITH")) {
        command.setTableEngineParams(readTableEngineParams());
    }
    // MySQL compatibility
    if (readIf("AUTO_INCREMENT")) {
        read("=");
        if (currentTokenType != VALUE || currentValue.getType() != Value.INT) {
            throw DbException.getSyntaxError(sqlCommand, parseIndex, "integer");
        }
        read();
    }
    readIf("DEFAULT");
    if (readIf("CHARSET")) {
        read("=");
        if (!readIf("UTF8")) {
            read("UTF8MB4");
        }
    }
    if (temp) {
        if (readIf("ON")) {
            read("COMMIT");
            if (readIf("DROP")) {
                command.setOnCommitDrop();
            } else if (readIf("DELETE")) {
                read("ROWS");
                command.setOnCommitTruncate();
            }
        } else if (readIf("NOT")) {
            if (readIf("PERSISTENT")) {
                command.setPersistData(false);
            } else {
                read("LOGGED");
            }
        }
        if (readIf("TRANSACTIONAL")) {
            command.setTransactional(true);
        }
    } else if (!persistIndexes && readIf("NOT")) {
        read("PERSISTENT");
        command.setPersistData(false);
    }
    if (readIf("HIDDEN")) {
        command.setHidden(true);
    }
    if (readIf("AS")) {
        if (readIf("SORTED")) {
            command.setSortedInsertMode(true);
        }
        command.setQuery(parseSelect());
    }
    // for MySQL compatibility
    if (readIf("ROW_FORMAT")) {
        if (readIf("=")) {
            readColumnIdentifier();
        }
    }
    return command;
}
Also used : DropSchema(org.h2.command.ddl.DropSchema) CreateSchema(org.h2.command.ddl.CreateSchema) Schema(org.h2.schema.Schema) CreateTable(org.h2.command.ddl.CreateTable) ValueString(org.h2.value.ValueString)

Example 20 with Command

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

the class Parser method parseAlterTableAddColumn.

private AlterTableAlterColumn parseAlterTableAddColumn(String tableName, Schema schema, boolean ifTableExists) {
    readIf("COLUMN");
    AlterTableAlterColumn command = new AlterTableAlterColumn(session, schema);
    command.setType(CommandInterface.ALTER_TABLE_ADD_COLUMN);
    command.setTableName(tableName);
    command.setIfTableExists(ifTableExists);
    if (readIf("(")) {
        command.setIfNotExists(false);
        do {
            parseTableColumnDefinition(command, schema, tableName);
        } while (readIfMore(true));
    } else {
        boolean ifNotExists = readIfNotExists();
        command.setIfNotExists(ifNotExists);
        parseTableColumnDefinition(command, schema, tableName);
    }
    if (readIf("BEFORE")) {
        command.setAddBefore(readColumnIdentifier());
    } else if (readIf("AFTER")) {
        command.setAddAfter(readColumnIdentifier());
    } else if (readIf("FIRST")) {
        command.setAddFirst();
    }
    return command;
}
Also used : AlterTableAlterColumn(org.h2.command.ddl.AlterTableAlterColumn)

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