Search in sources :

Example 26 with Command

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

the class Parser method parseCreateSequence.

private CreateSequence parseCreateSequence() {
    boolean ifNotExists = readIfNotExists();
    String sequenceName = readIdentifierWithSchema();
    CreateSequence command = new CreateSequence(session, getSchema());
    command.setIfNotExists(ifNotExists);
    command.setSequenceName(sequenceName);
    while (true) {
        if (readIf("START")) {
            readIf("WITH");
            command.setStartWith(readExpression());
        } else if (readIf("INCREMENT")) {
            readIf("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 if (readIf("BELONGS_TO_TABLE")) {
            command.setBelongsToTable(true);
        } else if (readIf("ORDER")) {
        // Oracle compatibility
        } else {
            break;
        }
    }
    return command;
}
Also used : CreateSequence(org.h2.command.ddl.CreateSequence) ValueString(org.h2.value.ValueString)

Example 27 with Command

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

the class Parser method parseScript.

private ScriptCommand parseScript() {
    ScriptCommand command = new ScriptCommand(session);
    boolean data = true, passwords = true, settings = true;
    boolean dropTables = false, simple = false;
    if (readIf("SIMPLE")) {
        simple = true;
    }
    if (readIf("NODATA")) {
        data = false;
    }
    if (readIf("NOPASSWORDS")) {
        passwords = false;
    }
    if (readIf("NOSETTINGS")) {
        settings = false;
    }
    if (readIf("DROP")) {
        dropTables = true;
    }
    if (readIf("BLOCKSIZE")) {
        long blockSize = readLong();
        command.setLobBlockSize(blockSize);
    }
    command.setData(data);
    command.setPasswords(passwords);
    command.setSettings(settings);
    command.setDrop(dropTables);
    command.setSimple(simple);
    if (readIf("TO")) {
        command.setFileNameExpr(readExpression());
        if (readIf("COMPRESSION")) {
            command.setCompressionAlgorithm(readUniqueIdentifier());
        }
        if (readIf("CIPHER")) {
            command.setCipher(readUniqueIdentifier());
            if (readIf("PASSWORD")) {
                command.setPassword(readExpression());
            }
        }
        if (readIf("CHARSET")) {
            command.setCharset(Charset.forName(readString()));
        }
    }
    if (readIf("SCHEMA")) {
        HashSet<String> schemaNames = new HashSet<>();
        do {
            schemaNames.add(readUniqueIdentifier());
        } while (readIf(","));
        command.setSchemaNames(schemaNames);
    } else if (readIf("TABLE")) {
        ArrayList<Table> tables = New.arrayList();
        do {
            tables.add(readTableOrView());
        } while (readIf(","));
        command.setTables(tables);
    }
    return command;
}
Also used : ArrayList(java.util.ArrayList) ValueString(org.h2.value.ValueString) RunScriptCommand(org.h2.command.dml.RunScriptCommand) ScriptCommand(org.h2.command.dml.ScriptCommand) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet)

Example 28 with Command

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

the class Parser method parseDeallocate.

private DeallocateProcedure parseDeallocate() {
    readIf("PLAN");
    String procedureName = readAliasIdentifier();
    DeallocateProcedure command = new DeallocateProcedure(session);
    command.setProcedureName(procedureName);
    return command;
}
Also used : DeallocateProcedure(org.h2.command.ddl.DeallocateProcedure) ValueString(org.h2.value.ValueString)

Example 29 with Command

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

the class Parser method parseSelectUnion.

private Query parseSelectUnion() {
    int start = lastParseIndex;
    Query command = parseSelectSub();
    return parseSelectUnionExtension(command, start, false);
}
Also used : Query(org.h2.command.dml.Query) AlterTableRenameConstraint(org.h2.command.ddl.AlterTableRenameConstraint) AlterTableAddConstraint(org.h2.command.ddl.AlterTableAddConstraint) AlterTableDropConstraint(org.h2.command.ddl.AlterTableDropConstraint)

Example 30 with Command

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

the class AlterTableAlterColumn method checkNoNullValues.

private void checkNoNullValues(Table table) {
    String sql = "SELECT COUNT(*) FROM " + table.getSQL() + " WHERE " + oldColumn.getSQL() + " IS NULL";
    Prepared command = session.prepare(sql);
    ResultInterface result = command.query(0);
    result.next();
    if (result.currentRow()[0].getInt() > 0) {
        throw DbException.get(ErrorCode.COLUMN_CONTAINS_NULL_VALUES_1, oldColumn.getSQL());
    }
}
Also used : ResultInterface(org.h2.result.ResultInterface) Prepared(org.h2.command.Prepared)

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