Search in sources :

Example 21 with HsqlName

use of org.hsqldb_voltpatches.HsqlNameManager.HsqlName in project voltdb by VoltDB.

the class ParserDDL method compileCreateStream.

// skip Export to target of statment
// skip constraint ?
StatementSchema compileCreateStream(int type) {
    HsqlName name = readNewSchemaObjectNameNoCheck(SchemaObject.TABLE);
    HsqlArrayList tempConstraints = new HsqlArrayList();
    name.setSchemaIfNull(session.getCurrentSchemaHsqlName());
    Table table = TableUtil.newTable(database, type, name);
    if (token.tokenType == Tokens.AS) {
        return readTableAsSubqueryDefinition(table);
    }
    int position = getPosition();
    readUntilThis(Tokens.OPENBRACKET);
    readThis(Tokens.OPENBRACKET);
    {
        Constraint c = new Constraint(null, true, null, Constraint.TEMP);
        tempConstraints.add(c);
    }
    boolean start = true;
    boolean startPart = true;
    boolean end = false;
    while (!end) {
        switch(token.tokenType) {
            case Tokens.LIKE:
                {
                    ColumnSchema[] likeColumns = readLikeTable(table);
                    for (int i = 0; i < likeColumns.length; i++) {
                        table.addColumn(likeColumns[i]);
                    }
                    start = false;
                    startPart = false;
                    break;
                }
            case Tokens.CONSTRAINT:
            case Tokens.PRIMARY:
            case Tokens.FOREIGN:
            // A VoltDB extension to support the assume unique attribute
            case Tokens.ASSUMEUNIQUE:
            // End of VoltDB extension
            case Tokens.UNIQUE:
            case Tokens.CHECK:
            // A VoltDB extension to support LIMIT PARTITION ROWS
            case Tokens.LIMIT:
                // End of VoltDB extension
                if (!startPart) {
                    throw unexpectedToken();
                }
                readConstraint(table, tempConstraints);
                start = false;
                startPart = false;
                break;
            case Tokens.COMMA:
                if (startPart) {
                    throw unexpectedToken();
                }
                read();
                startPart = true;
                break;
            case Tokens.CLOSEBRACKET:
                read();
                end = true;
                break;
            default:
                if (!startPart) {
                    throw unexpectedToken();
                }
                checkIsSchemaObjectName();
                HsqlName hsqlName = database.nameManager.newColumnHsqlName(name, token.tokenString, isDelimitedIdentifier());
                read();
                ColumnSchema newcolumn = readColumnDefinitionOrNull(table, hsqlName, tempConstraints);
                if (newcolumn == null) {
                    if (start) {
                        rewind(position);
                        return readTableAsSubqueryDefinition(table);
                    } else {
                        throw Error.error(ErrorCode.X_42000);
                    }
                }
                table.addColumn(newcolumn);
                start = false;
                startPart = false;
        }
    }
    if (token.tokenType == Tokens.ON) {
        if (!table.isTemp()) {
            throw unexpectedToken();
        }
        read();
        readThis(Tokens.COMMIT);
        if (token.tokenType == Tokens.DELETE) {
        } else if (token.tokenType == Tokens.PRESERVE) {
            table.persistenceScope = TableBase.SCOPE_SESSION;
        }
        read();
        readThis(Tokens.ROWS);
    }
    Object[] args = new Object[] { table, tempConstraints, null };
    String sql = getLastPart();
    return new StatementSchema(sql, StatementTypes.CREATE_TABLE, args, null, null);
}
Also used : HsqlArrayList(org.hsqldb_voltpatches.lib.HsqlArrayList) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName)

Example 22 with HsqlName

use of org.hsqldb_voltpatches.HsqlNameManager.HsqlName in project voltdb by VoltDB.

the class ParserDQL method readSchemaName.

HsqlName readSchemaName() {
    checkIsSchemaObjectName();
    checkValidCatalogName(token.namePrefix);
    HsqlName schema = session.getSchemaHsqlName(token.tokenString);
    read();
    return schema;
}
Also used : HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName)

Example 23 with HsqlName

use of org.hsqldb_voltpatches.HsqlNameManager.HsqlName in project voltdb by VoltDB.

the class ParserDQL method readNewSchemaName.

HsqlName readNewSchemaName() {
    checkIsSchemaObjectName();
    checkValidCatalogName(token.namePrefix);
    SqlInvariants.checkSchemaNameNotSystem(token.tokenString);
    HsqlName name = database.nameManager.newHsqlName(token.tokenString, isDelimitedIdentifier(), SchemaObject.SCHEMA);
    read();
    return name;
}
Also used : HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName)

Example 24 with HsqlName

use of org.hsqldb_voltpatches.HsqlNameManager.HsqlName in project voltdb by VoltDB.

the class ParserDDL method compileCreateAlias.

StatementSchema compileCreateAlias() {
    HsqlName name = null;
    Routine[] routines = null;
    String alias;
    String methodFQN = null;
    if (!session.isProcessingScript()) {
        throw super.unsupportedFeature();
    }
    read();
    try {
        alias = token.tokenString;
        read();
        readThis(Tokens.FOR);
        methodFQN = token.tokenString;
        read();
    } catch (HsqlException e) {
        alias = null;
    }
    if (alias != null) {
        HsqlName schema = database.schemaManager.getDefaultSchemaHsqlName();
        name = database.nameManager.newHsqlName(schema, alias, SchemaObject.FUNCTION);
        Method[] methods = Routine.getMethods(methodFQN);
        routines = Routine.newRoutines(methods);
    }
    String sql = getLastPart();
    Object[] args = new Object[] { name, routines };
    return new StatementSchema(sql, StatementTypes.CREATE_ALIAS, args, null, null);
}
Also used : HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName) Method(java.lang.reflect.Method)

Example 25 with HsqlName

use of org.hsqldb_voltpatches.HsqlNameManager.HsqlName in project voltdb by VoltDB.

the class ParserDDL method compileCreateUser.

StatementSchema compileCreateUser() {
    HsqlName name;
    String password;
    boolean admin = false;
    Grantee grantor = session.getGrantee();
    read();
    name = readNewUserIdentifier();
    readThis(Tokens.PASSWORD);
    password = readPassword();
    if (token.tokenType == Tokens.ADMIN) {
        read();
        admin = true;
    }
    checkDatabaseUpdateAuthorisation();
    String sql = getLastPart();
    Object[] args = new Object[] { name, password, grantor, Boolean.valueOf(admin) };
    return new StatementSchema(sql, StatementTypes.CREATE_USER, args, null, null);
}
Also used : Grantee(org.hsqldb_voltpatches.rights.Grantee) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName)

Aggregations

HsqlName (org.hsqldb_voltpatches.HsqlNameManager.HsqlName)204 Table (org.hsqldb_voltpatches.Table)86 PersistentStore (org.hsqldb_voltpatches.persist.PersistentStore)73 TextTable (org.hsqldb_voltpatches.TextTable)65 Iterator (org.hsqldb_voltpatches.lib.Iterator)64 WrapperIterator (org.hsqldb_voltpatches.lib.WrapperIterator)61 SchemaObject (org.hsqldb_voltpatches.SchemaObject)60 Constraint (org.hsqldb_voltpatches.Constraint)59 OrderedHashSet (org.hsqldb_voltpatches.lib.OrderedHashSet)48 HsqlArrayList (org.hsqldb_voltpatches.lib.HsqlArrayList)22 HsqlException (org.hsqldb_voltpatches.HsqlException)20 Type (org.hsqldb_voltpatches.types.Type)20 Session (org.hsqldb_voltpatches.Session)16 Result (org.hsqldb_voltpatches.result.Result)15 Grantee (org.hsqldb_voltpatches.rights.Grantee)12 NumberType (org.hsqldb_voltpatches.types.NumberType)10 Routine (org.hsqldb_voltpatches.Routine)7 RoutineSchema (org.hsqldb_voltpatches.RoutineSchema)7 TriggerDef (org.hsqldb_voltpatches.TriggerDef)6 Index (org.hsqldb_voltpatches.index.Index)6