Search in sources :

Example 21 with HsqlList

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

the class ParserRoutine method readIf.

private Statement readIf(Routine routine, StatementCompound context) {
    HsqlArrayList list = new HsqlArrayList();
    RangeVariable[] rangeVariables = context == null ? routine.getParameterRangeVariables() : context.getRangeVariables();
    HsqlList unresolved = null;
    readThis(Tokens.IF);
    Expression condition = XreadBooleanValueExpression();
    unresolved = condition.resolveColumnReferences(rangeVariables, rangeVariables.length, unresolved, false);
    ExpressionColumn.checkColumnsResolved(unresolved);
    unresolved = null;
    condition.resolveTypes(session, null);
    Statement statement = new StatementSimple(StatementTypes.CONDITION, condition);
    list.add(statement);
    readThis(Tokens.THEN);
    Statement[] statements = readSQLProcedureStatementList(routine, context);
    for (int i = 0; i < statements.length; i++) {
        list.add(statements[i]);
    }
    while (token.tokenType == Tokens.ELSEIF) {
        read();
        condition = XreadBooleanValueExpression();
        unresolved = condition.resolveColumnReferences(rangeVariables, rangeVariables.length, unresolved, false);
        ExpressionColumn.checkColumnsResolved(unresolved);
        unresolved = null;
        condition.resolveTypes(session, null);
        statement = new StatementSimple(StatementTypes.CONDITION, condition);
        list.add(statement);
        readThis(Tokens.THEN);
        statements = readSQLProcedureStatementList(routine, context);
        for (int i = 0; i < statements.length; i++) {
            list.add(statements[i]);
        }
    }
    if (token.tokenType == Tokens.ELSE) {
        read();
        condition = Expression.EXPR_TRUE;
        statement = new StatementSimple(StatementTypes.CONDITION, condition);
        list.add(statement);
        statements = readSQLProcedureStatementList(routine, context);
        for (int i = 0; i < statements.length; i++) {
            list.add(statements[i]);
        }
    }
    readThis(Tokens.END);
    readThis(Tokens.IF);
    statements = new Statement[list.size()];
    list.toArray(statements);
    StatementCompound result = new StatementCompound(StatementTypes.IF, null);
    result.setStatements(statements);
    return result;
}
Also used : HsqlArrayList(org.hsqldb_voltpatches.lib.HsqlArrayList) HsqlList(org.hsqldb_voltpatches.lib.HsqlList)

Example 22 with HsqlList

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

the class ParserCommand method compileSetTimeZone.

private Statement compileSetTimeZone() {
    Expression e;
    readThis(Tokens.ZONE);
    if (token.tokenType == Tokens.LOCAL) {
        read();
        e = new ExpressionValue(null, Type.SQL_VARCHAR);
    } else {
        e = XreadIntervalValueExpression();
        HsqlList unresolved = e.resolveColumnReferences(RangeVariable.emptyArray, null);
        ExpressionColumn.checkColumnsResolved(unresolved);
        e.resolveTypes(session, null);
        if (e.dataType == null) {
            throw Error.error(ErrorCode.X_42565);
        }
        if (e.dataType.typeCode != Types.SQL_INTERVAL_HOUR_TO_MINUTE) {
            throw Error.error(ErrorCode.X_42565);
        }
    }
    String sql = getLastPart();
    return new StatementSession(StatementTypes.SET_TIME_ZONE, new Expression[] { e });
}
Also used : HsqlList(org.hsqldb_voltpatches.lib.HsqlList)

Example 23 with HsqlList

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

the class ExpressionWindowed method resolveColumnReferences.

@Override
public HsqlList resolveColumnReferences(RangeVariable[] rangeVarArray, int rangeCount, HsqlList unresolvedSet, boolean acceptsSequences) {
    HsqlList localSet = null;
    // this is a no-op, because nodes is empty.
    for (Expression e : nodes) {
        localSet = e.resolveColumnReferences(RangeVariable.emptyArray, localSet);
    }
    for (Expression e : m_partitionByList) {
        localSet = e.resolveColumnReferences(RangeVariable.emptyArray, localSet);
    }
    if (m_sortAndSlice != null) {
        for (int i = 0; i < m_sortAndSlice.exprList.size(); i++) {
            Expression e = (Expression) m_sortAndSlice.exprList.get(i);
            assert (e instanceof ExpressionOrderBy);
            ExpressionOrderBy expr = (ExpressionOrderBy) e;
            localSet = expr.resolveColumnReferences(RangeVariable.emptyArray, localSet);
        }
    }
    if (localSet != null) {
        isCorrelated = true;
        for (int i = 0; i < localSet.size(); i++) {
            Expression e = (Expression) localSet.get(i);
            unresolvedSet = e.resolveColumnReferences(rangeVarArray, unresolvedSet);
        }
        unresolvedSet = Expression.resolveColumnSet(rangeVarArray, localSet, unresolvedSet);
    }
    return unresolvedSet;
}
Also used : HsqlList(org.hsqldb_voltpatches.lib.HsqlList)

Example 24 with HsqlList

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

the class Expression method getCheckSelect.

/**
     * Returns a Select object that can be used for checking the contents
     * of an existing table against the given CHECK search condition.
     */
static QuerySpecification getCheckSelect(Session session, Table t, Expression e) {
    CompileContext compileContext = new CompileContext(session);
    QuerySpecification s = new QuerySpecification(compileContext);
    s.exprColumns = new Expression[1];
    s.exprColumns[0] = EXPR_TRUE;
    RangeVariable range = new RangeVariable(t, null, null, null, compileContext);
    s.rangeVariables = new RangeVariable[] { range };
    HsqlList unresolved = e.resolveColumnReferences(s.rangeVariables, null);
    ExpressionColumn.checkColumnsResolved(unresolved);
    e.resolveTypes(session, null);
    if (Type.SQL_BOOLEAN != e.getDataType()) {
        throw Error.error(ErrorCode.X_42568);
    }
    Expression condition = new ExpressionLogical(OpTypes.NOT, e);
    s.queryCondition = condition;
    s.resolveReferences(session);
    s.resolveTypes(session);
    return s;
}
Also used : CompileContext(org.hsqldb_voltpatches.ParserDQL.CompileContext) HsqlList(org.hsqldb_voltpatches.lib.HsqlList)

Aggregations

HsqlList (org.hsqldb_voltpatches.lib.HsqlList)24 HsqlArrayList (org.hsqldb_voltpatches.lib.HsqlArrayList)10 OrderedHashSet (org.hsqldb_voltpatches.lib.OrderedHashSet)7 ArrayListIdentity (org.hsqldb_voltpatches.lib.ArrayListIdentity)2 HsqlName (org.hsqldb_voltpatches.HsqlNameManager.HsqlName)1 CompileContext (org.hsqldb_voltpatches.ParserDQL.CompileContext)1 Iterator (org.hsqldb_voltpatches.lib.Iterator)1 RangeIterator (org.hsqldb_voltpatches.navigator.RangeIterator)1