Search in sources :

Example 81 with Command

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

the class Parser method parseAnalyze.

private Prepared parseAnalyze() {
    Analyze command = new Analyze(session);
    if (readIf("TABLE")) {
        Table table = readTableOrView();
        command.setTable(table);
    }
    if (readIf("SAMPLE_SIZE")) {
        command.setTop(readPositiveInt());
    }
    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) Analyze(org.h2.command.ddl.Analyze)

Example 82 with Command

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

the class Parser method parseCreateUserDataType.

private CreateUserDataType parseCreateUserDataType() {
    boolean ifNotExists = readIfNotExists();
    CreateUserDataType command = new CreateUserDataType(session);
    command.setTypeName(readUniqueIdentifier());
    read("AS");
    Column col = parseColumnForTable("VALUE", true);
    if (readIf("CHECK")) {
        Expression expr = readExpression();
        col.addCheckConstraint(session, expr);
    }
    col.rename(null);
    command.setColumn(col);
    command.setIfNotExists(ifNotExists);
    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) Expression(org.h2.expression.Expression) ValueExpression(org.h2.expression.ValueExpression) CreateUserDataType(org.h2.command.ddl.CreateUserDataType)

Example 83 with Command

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

the class Parser method parseReferences.

private void parseReferences(AlterTableAddConstraint command, Schema schema, String tableName) {
    if (readIf("(")) {
        command.setRefTableName(schema, tableName);
        command.setRefIndexColumns(parseIndexColumnList());
    } else {
        String refTableName = readIdentifierWithSchema(schema.getName());
        command.setRefTableName(getSchema(), refTableName);
        if (readIf("(")) {
            command.setRefIndexColumns(parseIndexColumnList());
        }
    }
    if (readIf("INDEX")) {
        String indexName = readIdentifierWithSchema();
        command.setRefIndex(getSchema().findIndex(session, indexName));
    }
    while (readIf("ON")) {
        if (readIf("DELETE")) {
            command.setDeleteAction(parseAction());
        } else {
            read("UPDATE");
            command.setUpdateAction(parseAction());
        }
    }
    if (readIf("NOT")) {
        read("DEFERRABLE");
    } else {
        readIf("DEFERRABLE");
    }
}
Also used : ValueString(org.h2.value.ValueString)

Example 84 with Command

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

the class Parser method parseCreateUser.

private CreateUser parseCreateUser() {
    CreateUser command = new CreateUser(session);
    command.setIfNotExists(readIfNotExists());
    command.setUserName(readUniqueIdentifier());
    command.setComment(readCommentIf());
    if (readIf("PASSWORD")) {
        command.setPassword(readExpression());
    } else if (readIf("SALT")) {
        command.setSalt(readExpression());
        read("HASH");
        command.setHash(readExpression());
    } else if (readIf("IDENTIFIED")) {
        read("BY");
        // uppercase if not quoted
        command.setPassword(ValueExpression.get(ValueString.get(readColumnIdentifier())));
    } else {
        throw getSyntaxError();
    }
    if (readIf("ADMIN")) {
        command.setAdmin(true);
    }
    return command;
}
Also used : CreateUser(org.h2.command.ddl.CreateUser)

Example 85 with Command

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

the class Parser method parseSet.

private Prepared parseSet() {
    if (readIf("@")) {
        Set command = new Set(session, SetTypes.VARIABLE);
        command.setString(readAliasIdentifier());
        readIfEqualOrTo();
        command.setExpression(readExpression());
        return command;
    } else if (readIf("AUTOCOMMIT")) {
        readIfEqualOrTo();
        boolean value = readBooleanSetting();
        int setting = value ? CommandInterface.SET_AUTOCOMMIT_TRUE : CommandInterface.SET_AUTOCOMMIT_FALSE;
        return new TransactionCommand(session, setting);
    } else if (readIf("MVCC")) {
        readIfEqualOrTo();
        boolean value = readBooleanSetting();
        Set command = new Set(session, SetTypes.MVCC);
        command.setInt(value ? 1 : 0);
        return command;
    } else if (readIf("EXCLUSIVE")) {
        readIfEqualOrTo();
        Set command = new Set(session, SetTypes.EXCLUSIVE);
        command.setExpression(readExpression());
        return command;
    } else if (readIf("IGNORECASE")) {
        readIfEqualOrTo();
        boolean value = readBooleanSetting();
        Set command = new Set(session, SetTypes.IGNORECASE);
        command.setInt(value ? 1 : 0);
        return command;
    } else if (readIf("PASSWORD")) {
        readIfEqualOrTo();
        AlterUser command = new AlterUser(session);
        command.setType(CommandInterface.ALTER_USER_SET_PASSWORD);
        command.setUser(session.getUser());
        command.setPassword(readExpression());
        return command;
    } else if (readIf("SALT")) {
        readIfEqualOrTo();
        AlterUser command = new AlterUser(session);
        command.setType(CommandInterface.ALTER_USER_SET_PASSWORD);
        command.setUser(session.getUser());
        command.setSalt(readExpression());
        read("HASH");
        command.setHash(readExpression());
        return command;
    } else if (readIf("MODE")) {
        readIfEqualOrTo();
        Set command = new Set(session, SetTypes.MODE);
        command.setString(readAliasIdentifier());
        return command;
    } else if (readIf("COMPRESS_LOB")) {
        readIfEqualOrTo();
        Set command = new Set(session, SetTypes.COMPRESS_LOB);
        if (currentTokenType == VALUE) {
            command.setString(readString());
        } else {
            command.setString(readUniqueIdentifier());
        }
        return command;
    } else if (readIf("DATABASE")) {
        readIfEqualOrTo();
        read("COLLATION");
        return parseSetCollation();
    } else if (readIf("COLLATION")) {
        readIfEqualOrTo();
        return parseSetCollation();
    } else if (readIf("BINARY_COLLATION")) {
        readIfEqualOrTo();
        return parseSetBinaryCollation();
    } else if (readIf("CLUSTER")) {
        readIfEqualOrTo();
        Set command = new Set(session, SetTypes.CLUSTER);
        command.setString(readString());
        return command;
    } else if (readIf("DATABASE_EVENT_LISTENER")) {
        readIfEqualOrTo();
        Set command = new Set(session, SetTypes.DATABASE_EVENT_LISTENER);
        command.setString(readString());
        return command;
    } else if (readIf("ALLOW_LITERALS")) {
        readIfEqualOrTo();
        Set command = new Set(session, SetTypes.ALLOW_LITERALS);
        if (readIf("NONE")) {
            command.setInt(Constants.ALLOW_LITERALS_NONE);
        } else if (readIf("ALL")) {
            command.setInt(Constants.ALLOW_LITERALS_ALL);
        } else if (readIf("NUMBERS")) {
            command.setInt(Constants.ALLOW_LITERALS_NUMBERS);
        } else {
            command.setInt(readPositiveInt());
        }
        return command;
    } else if (readIf("DEFAULT_TABLE_TYPE")) {
        readIfEqualOrTo();
        Set command = new Set(session, SetTypes.DEFAULT_TABLE_TYPE);
        if (readIf("MEMORY")) {
            command.setInt(Table.TYPE_MEMORY);
        } else if (readIf("CACHED")) {
            command.setInt(Table.TYPE_CACHED);
        } else {
            command.setInt(readPositiveInt());
        }
        return command;
    } else if (readIf("CREATE")) {
        readIfEqualOrTo();
        // Derby compatibility (CREATE=TRUE in the database URL)
        read();
        return new NoOperation(session);
    } else if (readIf("HSQLDB.DEFAULT_TABLE_TYPE")) {
        readIfEqualOrTo();
        read();
        return new NoOperation(session);
    } else if (readIf("PAGE_STORE")) {
        readIfEqualOrTo();
        read();
        return new NoOperation(session);
    } else if (readIf("CACHE_TYPE")) {
        readIfEqualOrTo();
        read();
        return new NoOperation(session);
    } else if (readIf("FILE_LOCK")) {
        readIfEqualOrTo();
        read();
        return new NoOperation(session);
    } else if (readIf("DB_CLOSE_ON_EXIT")) {
        readIfEqualOrTo();
        read();
        return new NoOperation(session);
    } else if (readIf("AUTO_SERVER")) {
        readIfEqualOrTo();
        read();
        return new NoOperation(session);
    } else if (readIf("AUTO_SERVER_PORT")) {
        readIfEqualOrTo();
        read();
        return new NoOperation(session);
    } else if (readIf("AUTO_RECONNECT")) {
        readIfEqualOrTo();
        read();
        return new NoOperation(session);
    } else if (readIf("ASSERT")) {
        readIfEqualOrTo();
        read();
        return new NoOperation(session);
    } else if (readIf("ACCESS_MODE_DATA")) {
        readIfEqualOrTo();
        read();
        return new NoOperation(session);
    } else if (readIf("OPEN_NEW")) {
        readIfEqualOrTo();
        read();
        return new NoOperation(session);
    } else if (readIf("JMX")) {
        readIfEqualOrTo();
        read();
        return new NoOperation(session);
    } else if (readIf("PAGE_SIZE")) {
        readIfEqualOrTo();
        read();
        return new NoOperation(session);
    } else if (readIf("RECOVER")) {
        readIfEqualOrTo();
        read();
        return new NoOperation(session);
    } else if (readIf("NAMES")) {
        // Quercus PHP MySQL driver compatibility
        readIfEqualOrTo();
        read();
        return new NoOperation(session);
    } else if (readIf("SCOPE_GENERATED_KEYS")) {
        readIfEqualOrTo();
        read();
        return new NoOperation(session);
    } else if (readIf("SCHEMA")) {
        readIfEqualOrTo();
        Set command = new Set(session, SetTypes.SCHEMA);
        command.setString(readAliasIdentifier());
        return command;
    } else if (readIf("DATESTYLE")) {
        // PostgreSQL compatibility
        readIfEqualOrTo();
        if (!readIf("ISO")) {
            String s = readString();
            if (!equalsToken(s, "ISO")) {
                throw getSyntaxError();
            }
        }
        return new NoOperation(session);
    } else if (readIf("SEARCH_PATH") || readIf(SetTypes.getTypeName(SetTypes.SCHEMA_SEARCH_PATH))) {
        readIfEqualOrTo();
        Set command = new Set(session, SetTypes.SCHEMA_SEARCH_PATH);
        ArrayList<String> list = New.arrayList();
        list.add(readAliasIdentifier());
        while (readIf(",")) {
            list.add(readAliasIdentifier());
        }
        command.setStringArray(list.toArray(new String[0]));
        return command;
    } else if (readIf("JAVA_OBJECT_SERIALIZER")) {
        readIfEqualOrTo();
        return parseSetJavaObjectSerializer();
    } else {
        if (isToken("LOGSIZE")) {
            // HSQLDB compatibility
            currentToken = SetTypes.getTypeName(SetTypes.MAX_LOG_SIZE);
        }
        if (isToken("FOREIGN_KEY_CHECKS")) {
            // MySQL compatibility
            currentToken = SetTypes.getTypeName(SetTypes.REFERENTIAL_INTEGRITY);
        }
        int type = SetTypes.getType(currentToken);
        if (type < 0) {
            throw getSyntaxError();
        }
        read();
        readIfEqualOrTo();
        Set command = new Set(session, type);
        command.setExpression(readExpression());
        return command;
    }
}
Also used : Set(org.h2.command.dml.Set) LinkedHashSet(java.util.LinkedHashSet) AlterTableSet(org.h2.command.dml.AlterTableSet) HashSet(java.util.HashSet) NoOperation(org.h2.command.dml.NoOperation) ArrayList(java.util.ArrayList) TransactionCommand(org.h2.command.dml.TransactionCommand) AlterUser(org.h2.command.ddl.AlterUser) 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