Search in sources :

Example 11 with Expression

use of lucee.runtime.sql.exp.Expression in project Lucee by lucee.

the class SelectParser method decsionOp.

private Expression decsionOp(ParserString raw) throws SQLParserException {
    Expression expr = plusMinusOp(raw);
    boolean hasChanged = false;
    do {
        hasChanged = false;
        // value BETWEEN value AND value
        if (raw.forwardIfCurrent("between ")) {
            raw.removeSpace();
            Expression left = plusMinusOp(raw);
            raw.removeSpace();
            if (!raw.forwardIfCurrent("and "))
                throw new SQLParserException("invalid operation (between) missing operator and");
            raw.removeSpace();
            Expression right = plusMinusOp(raw);
            raw.removeSpace();
            expr = new Operation3(expr, left, right, Operation.OPERATION3_BETWEEN);
            hasChanged = true;
        } else // value like value [escape value]
        if (raw.forwardIfCurrentAndNoWordNumberAfter("like")) {
            raw.removeSpace();
            Expression left = plusMinusOp(raw);
            raw.removeSpace();
            if (raw.forwardIfCurrentAndNoWordNumberAfter("escape ")) {
                raw.removeSpace();
                Expression right = plusMinusOp(raw);
                raw.removeSpace();
                expr = new Operation3(expr, left, right, Operation.OPERATION3_LIKE);
            } else {
                raw.removeSpace();
                expr = new Operation2(expr, left, Operation.OPERATION2_LIKE);
            }
            hasChanged = true;
        } else // IS [NOT] NULL
        if (raw.isCurrent("is ")) {
            int start = raw.getPos();
            if (raw.forwardIfCurrentAndNoWordNumberAfter("is null")) {
                raw.removeSpace();
                return new Operation1(expr, Operation.OPERATION1_IS_NULL);
            } else if (raw.forwardIfCurrentAndNoWordNumberAfter("is not null")) {
                raw.removeSpace();
                return new Operation1(expr, Operation.OPERATION1_IS_NOT_NULL);
            } else {
                raw.setPos(start);
                raw.removeSpace();
            }
        } else // not in
        if (raw.forwardIfCurrent("not in", '(')) {
            expr = new OperationN("not_in", readArguments(raw, expr));
            hasChanged = true;
        } else // in
        if (raw.forwardIfCurrent("in", '(')) {
            expr = new OperationN("in", readArguments(raw, expr));
            hasChanged = true;
        }
        // not like
        if (raw.forwardIfCurrentAndNoWordNumberAfter("not like")) {
            expr = decisionOpCreate(raw, Operation.OPERATION2_NOT_LIKE, expr);
            hasChanged = true;
        } else // =
        if (raw.forwardIfCurrent('=')) {
            expr = decisionOpCreate(raw, Operation.OPERATION2_EQ, expr);
            hasChanged = true;
        } else // !=
        if (raw.forwardIfCurrent("!=")) {
            expr = decisionOpCreate(raw, Operation.OPERATION2_NEQ, expr);
            hasChanged = true;
        } else // <>
        if (raw.forwardIfCurrent("<>")) {
            expr = decisionOpCreate(raw, Operation.OPERATION2_LTGT, expr);
            hasChanged = true;
        } else // <, <=
        if (raw.isCurrent('<')) {
            if (raw.forwardIfCurrent("<=")) {
                expr = decisionOpCreate(raw, Operation.OPERATION2_LTE, expr);
                hasChanged = true;
            } else {
                raw.next();
                expr = decisionOpCreate(raw, Operation.OPERATION2_LT, expr);
                hasChanged = true;
            }
        } else // >, =>
        if (raw.isCurrent('>')) {
            if (raw.forwardIfCurrent("=>")) {
                expr = decisionOpCreate(raw, Operation.OPERATION2_GTE, expr);
                hasChanged = true;
            }
            if (raw.forwardIfCurrent(">=")) {
                expr = decisionOpCreate(raw, Operation.OPERATION2_GTE, expr);
                hasChanged = true;
            } else {
                raw.next();
                expr = decisionOpCreate(raw, Operation.OPERATION2_GT, expr);
                hasChanged = true;
            }
        }
    } while (hasChanged);
    return expr;
}
Also used : ColumnExpression(lucee.runtime.sql.exp.ColumnExpression) Expression(lucee.runtime.sql.exp.Expression) OperationN(lucee.runtime.sql.exp.op.OperationN) Operation2(lucee.runtime.sql.exp.op.Operation2) Operation1(lucee.runtime.sql.exp.op.Operation1) Operation3(lucee.runtime.sql.exp.op.Operation3)

Example 12 with Expression

use of lucee.runtime.sql.exp.Expression in project Lucee by lucee.

the class SelectParser method modOp.

private Expression modOp(ParserString raw) throws SQLParserException {
    Expression expr = divMultiOp(raw);
    // Modulus Operation
    while (raw.forwardIfCurrent('%')) {
        raw.removeSpace();
        expr = new Operation2(expr, divMultiOp(raw), Operation.OPERATION2_MOD);
    }
    return expr;
}
Also used : ColumnExpression(lucee.runtime.sql.exp.ColumnExpression) Expression(lucee.runtime.sql.exp.Expression) Operation2(lucee.runtime.sql.exp.op.Operation2)

Example 13 with Expression

use of lucee.runtime.sql.exp.Expression in project Lucee by lucee.

the class SelectParser method readArguments.

private List readArguments(ParserString raw, Expression exp) throws SQLParserException {
    List args = new ArrayList();
    Expression arg;
    if (exp != null)
        args.add(exp);
    do {
        raw.removeSpace();
        if (raw.isCurrent(')'))
            break;
        args.add(arg = expression(raw));
        raw.removeSpace();
        // check for alias
        if (raw.forwardIfCurrent("as ")) {
            raw.removeSpace();
            arg.setAlias(identifier(raw, null));
            raw.removeSpace();
        }
    } while (raw.forwardIfCurrent(','));
    if (!raw.forwardIfCurrent(')'))
        throw new SQLParserException("missing closing )");
    raw.removeSpace();
    return args;
}
Also used : ColumnExpression(lucee.runtime.sql.exp.ColumnExpression) Expression(lucee.runtime.sql.exp.Expression) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 14 with Expression

use of lucee.runtime.sql.exp.Expression in project Lucee by lucee.

the class SelectParser method groupByExpressions.

private void groupByExpressions(ParserString raw, Select select) throws SQLParserException {
    Expression exp = null;
    do {
        raw.removeSpace();
        // print.out(raw.getCurrent());
        exp = expression(raw);
        if (!(exp instanceof Column))
            throw new SQLParserException("invalid group by part of query");
        Column col = (Column) exp;
        select.addGroupByExpression(col);
        raw.removeSpace();
    } while (raw.forwardIfCurrent(','));
    raw.removeSpace();
}
Also used : ColumnExpression(lucee.runtime.sql.exp.ColumnExpression) Expression(lucee.runtime.sql.exp.Expression) Column(lucee.runtime.sql.exp.Column)

Example 15 with Expression

use of lucee.runtime.sql.exp.Expression in project Lucee by lucee.

the class SelectParser method expoOp.

private Expression expoOp(ParserString raw) throws SQLParserException {
    Expression exp = negateMinusOp(raw);
    // Modulus Operation
    while (raw.forwardIfCurrent('^')) {
        raw.removeSpace();
        exp = new Operation2(exp, negateMinusOp(raw), Operation.OPERATION2_EXP);
    }
    return exp;
}
Also used : ColumnExpression(lucee.runtime.sql.exp.ColumnExpression) Expression(lucee.runtime.sql.exp.Expression) Operation2(lucee.runtime.sql.exp.op.Operation2)

Aggregations

Expression (lucee.runtime.sql.exp.Expression)20 ColumnExpression (lucee.runtime.sql.exp.ColumnExpression)18 Operation2 (lucee.runtime.sql.exp.op.Operation2)9 Column (lucee.runtime.sql.exp.Column)4 Operation (lucee.runtime.sql.exp.op.Operation)4 ParserString (lucee.commons.lang.ParserString)2 RefBoolean (lucee.commons.lang.types.RefBoolean)2 RefBooleanImpl (lucee.commons.lang.types.RefBooleanImpl)2 DatabaseException (lucee.runtime.exp.DatabaseException)2 BracketExpression (lucee.runtime.sql.exp.BracketExpression)2 Operation1 (lucee.runtime.sql.exp.op.Operation1)2 Operation3 (lucee.runtime.sql.exp.op.Operation3)2 OperationN (lucee.runtime.sql.exp.op.OperationN)2 ValueNumber (lucee.runtime.sql.exp.value.ValueNumber)2 ValueString (lucee.runtime.sql.exp.value.ValueString)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Collection (lucee.runtime.type.Collection)1