Search in sources :

Example 36 with HsqlArrayList

use of org.hsqldb_voltpatches.lib.HsqlArrayList in project voltdb by VoltDB.

the class ParserDML method compileCallStatement.

/**
     * Retrieves a CALL Statement from this parse context.
     */
// to do call argument name and type resolution
StatementDMQL compileCallStatement(RangeVariable[] outerRanges, boolean isStrictlyProcedure) {
    read();
    if (isIdentifier()) {
        checkValidCatalogName(token.namePrePrefix);
        RoutineSchema routineSchema = (RoutineSchema) database.schemaManager.findSchemaObject(token.tokenString, session.getSchemaName(token.namePrefix), SchemaObject.PROCEDURE);
        if (routineSchema != null) {
            read();
            HsqlArrayList list = new HsqlArrayList();
            readThis(Tokens.OPENBRACKET);
            if (token.tokenType == Tokens.CLOSEBRACKET) {
                read();
            } else {
                while (true) {
                    Expression e = XreadValueExpression();
                    list.add(e);
                    if (token.tokenType == Tokens.COMMA) {
                        read();
                    } else {
                        readThis(Tokens.CLOSEBRACKET);
                        break;
                    }
                }
            }
            Expression[] arguments = new Expression[list.size()];
            list.toArray(arguments);
            Routine routine = routineSchema.getSpecificRoutine(arguments.length);
            HsqlList unresolved = null;
            for (int i = 0; i < arguments.length; i++) {
                Expression e = arguments[i];
                if (e.isParam()) {
                    e.setAttributesAsColumn(routine.getParameter(i), routine.getParameter(i).isWriteable());
                } else {
                    int paramMode = routine.getParameter(i).getParameterMode();
                    unresolved = arguments[i].resolveColumnReferences(outerRanges, unresolved);
                    if (paramMode != SchemaObject.ParameterModes.PARAM_IN) {
                        if (e.getType() != OpTypes.VARIABLE) {
                            throw Error.error(ErrorCode.X_42603);
                        }
                    }
                }
            }
            ExpressionColumn.checkColumnsResolved(unresolved);
            for (int i = 0; i < arguments.length; i++) {
                arguments[i].resolveTypes(session, null);
            }
            StatementDMQL cs = new StatementProcedure(session, routine, arguments, compileContext);
            return cs;
        }
    }
    if (isStrictlyProcedure) {
        throw Error.error(ErrorCode.X_42501, token.tokenString);
    }
    Expression expression = this.XreadValueExpression();
    HsqlList unresolved = expression.resolveColumnReferences(outerRanges, null);
    ExpressionColumn.checkColumnsResolved(unresolved);
    expression.resolveTypes(session, null);
    //        expression.paramMode = PARAM_OUT;
    StatementDMQL cs = new StatementProcedure(session, expression, compileContext);
    return cs;
}
Also used : HsqlArrayList(org.hsqldb_voltpatches.lib.HsqlArrayList) HsqlList(org.hsqldb_voltpatches.lib.HsqlList)

Example 37 with HsqlArrayList

use of org.hsqldb_voltpatches.lib.HsqlArrayList in project voltdb by VoltDB.

the class ParserDML method compileUpdateStatement.

/**
     * Creates an UPDATE-type Statement from this parse context.
     */
StatementDMQL compileUpdateStatement(RangeVariable[] outerRanges) {
    read();
    Expression[] updateExpressions;
    int[] columnMap;
    boolean[] columnCheckList;
    OrderedHashSet colNames = new OrderedHashSet();
    HsqlArrayList exprList = new HsqlArrayList();
    RangeVariable[] rangeVariables = { readSimpleRangeVariable(StatementTypes.UPDATE_WHERE) };
    Table table = rangeVariables[0].rangeTable;
    Table baseTable = table.getBaseTable();
    readThis(Tokens.SET);
    readSetClauseList(rangeVariables, colNames, exprList);
    columnMap = table.getColumnIndexes(colNames);
    columnCheckList = table.getColumnCheckList(columnMap);
    updateExpressions = new Expression[exprList.size()];
    exprList.toArray(updateExpressions);
    Expression condition = null;
    if (token.tokenType == Tokens.WHERE) {
        read();
        condition = XreadBooleanValueExpression();
        HsqlList unresolved = condition.resolveColumnReferences(outerRanges, null);
        unresolved = Expression.resolveColumnSet(rangeVariables, unresolved, null);
        ExpressionColumn.checkColumnsResolved(unresolved);
        condition.resolveTypes(session, null);
        if (condition.isParam()) {
            condition.dataType = Type.SQL_BOOLEAN;
        } else if (condition.getDataType() != Type.SQL_BOOLEAN) {
            throw Error.error(ErrorCode.X_42568);
        }
    }
    resolveUpdateExpressions(table, rangeVariables, columnMap, updateExpressions, outerRanges);
    if (baseTable != null && table != baseTable) {
        QuerySpecification select = ((TableDerived) table).getQueryExpression().getMainSelect();
        if (condition != null) {
            condition = condition.replaceColumnReferences(rangeVariables[0], select.exprColumns);
        }
        rangeVariables[0] = new RangeVariable(select.rangeVariables[0]);
        condition = ExpressionLogical.andExpressions(select.queryCondition, condition);
    }
    if (condition != null) {
        RangeVariableResolver resolver = new RangeVariableResolver(rangeVariables, condition, compileContext);
        resolver.processConditions();
        rangeVariables = resolver.rangeVariables;
    }
    if (baseTable != null && table != baseTable) {
        int[] baseColumnMap = table.getBaseTableColumnMap();
        int[] newColumnMap = new int[columnMap.length];
        ArrayUtil.projectRow(baseColumnMap, columnMap, newColumnMap);
        columnMap = newColumnMap;
    }
    StatementDMQL cs = new StatementDML(session, table, rangeVariables, columnMap, updateExpressions, columnCheckList, compileContext);
    return cs;
}
Also used : HsqlArrayList(org.hsqldb_voltpatches.lib.HsqlArrayList) HsqlList(org.hsqldb_voltpatches.lib.HsqlList) OrderedHashSet(org.hsqldb_voltpatches.lib.OrderedHashSet)

Example 38 with HsqlArrayList

use of org.hsqldb_voltpatches.lib.HsqlArrayList in project voltdb by VoltDB.

the class ParserDQL method readColumnOrFunctionExpression.

/**
     * reads a Column or Function expression
     */
private Expression readColumnOrFunctionExpression() {
    String name = token.tokenString;
    boolean isSimpleQuoted = isDelimitedSimpleName();
    String prefix = token.namePrefix;
    String prePrefix = token.namePrePrefix;
    if (isUndelimitedSimpleName()) {
        // A VoltDB extension to augment the standard sql function set.
        FunctionSQL function;
        function = FunctionForVoltDB.newVoltDBFunction(name);
        if (function == null) {
            // These seem to be JDBC ("Open Group"?) aliases and extensions to the standard sql functions.
            function = FunctionCustom.newCustomFunction(token.tokenString, token.tokenType);
        }
        if (function != null) {
            int pos = getPosition();
            // A VoltDB extension to avoid abusing the exception handling mechanism
            // for normal flow control.
            HsqlException ex = null;
            try {
                ExpressionOrException result = readSQLFunction(function, false);
                ex = result.exception();
                if (ex == null) {
                    return result.knownGood();
                }
            } catch (HsqlException caught) {
                ex = caught;
            }
            if (ex != null) {
                /* disable 3 lines ...
                try {
                    return readSQLFunction(function);
                } catch (HsqlException ex) {
                ... disabled 3 lines */
                // End of VoltDB extension
                ex.setLevel(compileContext.subQueryDepth);
                if (lastError == null || lastError.getLevel() < ex.getLevel()) {
                    lastError = ex;
                }
                rewind(pos);
            }
        } else if (isReservedKey()) {
            function = FunctionSQL.newSQLFunction(name, compileContext);
            if (function != null) {
                // but get post-processed in the similar call above for FunctionForVoltDB and FunctionCustom
                return readSQLFunction(function);
            }
        }
    }
    read();
    if (token.tokenType != Tokens.OPENBRACKET) {
        Expression column = new ExpressionColumn(prePrefix, prefix, name);
        return column;
    }
    checkValidCatalogName(prePrefix);
    prefix = session.getSchemaName(prefix);
    RoutineSchema routineSchema = (RoutineSchema) database.schemaManager.findSchemaObject(name, prefix, SchemaObject.FUNCTION);
    if (routineSchema == null && isSimpleQuoted) {
        HsqlName schema = database.schemaManager.getDefaultSchemaHsqlName();
        routineSchema = (RoutineSchema) database.schemaManager.findSchemaObject(name, schema.name, SchemaObject.FUNCTION);
        if (routineSchema == null) {
            Method[] methods = Routine.getMethods(name);
            Routine[] routines = Routine.newRoutines(methods);
            HsqlName routineName = database.nameManager.newHsqlName(schema, name, true, SchemaObject.FUNCTION);
            for (int i = 0; i < routines.length; i++) {
                routines[i].setName(routineName);
                session.database.schemaManager.addSchemaObject(routines[i]);
            }
            routineSchema = (RoutineSchema) database.schemaManager.findSchemaObject(name, schema.name, SchemaObject.FUNCTION);
        }
    }
    if (routineSchema == null) {
        throw Error.error(ErrorCode.X_42501, name);
    }
    HsqlArrayList list = new HsqlArrayList();
    readThis(Tokens.OPENBRACKET);
    if (token.tokenType == Tokens.CLOSEBRACKET) {
        read();
    } else {
        while (true) {
            Expression e = XreadValueExpression();
            list.add(e);
            if (token.tokenType == Tokens.COMMA) {
                read();
            } else {
                readThis(Tokens.CLOSEBRACKET);
                break;
            }
        }
    }
    FunctionSQLInvoked function = new FunctionSQLInvoked(routineSchema);
    Expression[] arguments = new Expression[list.size()];
    list.toArray(arguments);
    function.setArguments(arguments);
    compileContext.addRoutine(function);
    return function;
}
Also used : HsqlArrayList(org.hsqldb_voltpatches.lib.HsqlArrayList) Method(java.lang.reflect.Method) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName)

Example 39 with HsqlArrayList

use of org.hsqldb_voltpatches.lib.HsqlArrayList in project voltdb by VoltDB.

the class ParserDQL method XreadRowElementList.

Expression XreadRowElementList(boolean multiple) {
    Expression e;
    HsqlArrayList list = new HsqlArrayList();
    while (true) {
        e = XreadValueExpression();
        list.add(e);
        if (token.tokenType == Tokens.COMMA) {
            read();
            continue;
        }
        if (multiple && list.size() == 1) {
            return e;
        }
        break;
    }
    Expression[] array = new Expression[list.size()];
    list.toArray(array);
    return new Expression(OpTypes.ROW, array);
}
Also used : HsqlArrayList(org.hsqldb_voltpatches.lib.HsqlArrayList)

Example 40 with HsqlArrayList

use of org.hsqldb_voltpatches.lib.HsqlArrayList in project voltdb by VoltDB.

the class ParserRoutine method compileSetStatement.

/**
     * Creates SET Statement for PSM from this parse context.
     */
StatementSimple compileSetStatement(RangeVariable[] rangeVars) {
    read();
    OrderedHashSet colNames = new OrderedHashSet();
    HsqlArrayList exprList = new HsqlArrayList();
    readSetClauseList(rangeVars, colNames, exprList);
    if (exprList.size() > 1) {
        throw Error.error(ErrorCode.X_42602);
    }
    Expression expression = (Expression) exprList.get(0);
    if (expression.getDegree() != colNames.size()) {
    //            throw Error.error(ErrorCode.X_42546);
    }
    int[] indexes = new int[colNames.size()];
    ColumnSchema[] variables = new ColumnSchema[colNames.size()];
    setVariables(rangeVars, colNames, indexes, variables);
    HsqlList unresolved = expression.resolveColumnReferences(rangeVars, rangeVars.length, null, false);
    unresolved = Expression.resolveColumnSet(rangeVars, unresolved, null);
    ExpressionColumn.checkColumnsResolved(unresolved);
    expression.resolveTypes(session, null);
    StatementSimple cs = new StatementSimple(StatementTypes.ASSIGNMENT, variables, expression, indexes);
    return cs;
}
Also used : HsqlArrayList(org.hsqldb_voltpatches.lib.HsqlArrayList) OrderedHashSet(org.hsqldb_voltpatches.lib.OrderedHashSet) HsqlList(org.hsqldb_voltpatches.lib.HsqlList)

Aggregations

HsqlArrayList (org.hsqldb_voltpatches.lib.HsqlArrayList)69 HsqlName (org.hsqldb_voltpatches.HsqlNameManager.HsqlName)21 Iterator (org.hsqldb_voltpatches.lib.Iterator)14 HsqlList (org.hsqldb_voltpatches.lib.HsqlList)11 OrderedHashSet (org.hsqldb_voltpatches.lib.OrderedHashSet)10 WrapperIterator (org.hsqldb_voltpatches.lib.WrapperIterator)10 Table (org.hsqldb_voltpatches.Table)7 Type (org.hsqldb_voltpatches.types.Type)6 SchemaObject (org.hsqldb_voltpatches.SchemaObject)5 Method (java.lang.reflect.Method)4 Constraint (org.hsqldb_voltpatches.Constraint)3 HashMappedList (org.hsqldb_voltpatches.lib.HashMappedList)3 Grantee (org.hsqldb_voltpatches.rights.Grantee)3 PersistentStore (org.hsqldb_voltpatches.persist.PersistentStore)2 Result (org.hsqldb_voltpatches.result.Result)2 BufferedOutputStream (java.io.BufferedOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 HSQLParseException (org.hsqldb_voltpatches.HSQLInterface.HSQLParseException)1 NumberSequence (org.hsqldb_voltpatches.NumberSequence)1