Search in sources :

Example 1 with Expression

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

the class SelectParser method andOp.

private Expression andOp(ParserString raw) throws SQLParserException {
    Expression expr = notOp(raw);
    while (raw.forwardIfCurrentAndNoWordNumberAfter("and")) {
        raw.removeSpace();
        expr = new Operation2(expr, notOp(raw), Operation.OPERATION2_AND);
    }
    return expr;
}
Also used : ColumnExpression(lucee.runtime.sql.exp.ColumnExpression) Expression(lucee.runtime.sql.exp.Expression) Operation2(lucee.runtime.sql.exp.op.Operation2)

Example 2 with Expression

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

the class SelectParser method orOp.

private Expression orOp(ParserString raw) throws SQLParserException {
    Expression expr = andOp(raw);
    while (raw.forwardIfCurrentAndNoWordNumberAfter("or")) {
        raw.removeSpace();
        expr = new Operation2(expr, andOp(raw), Operation.OPERATION2_OR);
    }
    return expr;
}
Also used : ColumnExpression(lucee.runtime.sql.exp.ColumnExpression) Expression(lucee.runtime.sql.exp.Expression) Operation2(lucee.runtime.sql.exp.op.Operation2)

Example 3 with Expression

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

the class SelectParser method whereExpressions.

private void whereExpressions(ParserString raw, Select select) throws SQLParserException {
    raw.removeSpace();
    Expression exp = expression(raw);
    if (exp == null)
        throw new SQLParserException("missing where expression");
    if (!(exp instanceof Operation))
        throw new SQLParserException("invalid where expression (" + Caster.toClassName(exp) + ")");
    select.setWhereExpression((Operation) exp);
    raw.removeSpace();
}
Also used : ColumnExpression(lucee.runtime.sql.exp.ColumnExpression) Expression(lucee.runtime.sql.exp.Expression) Operation(lucee.runtime.sql.exp.op.Operation)

Example 4 with Expression

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

the class SelectParser method orderByExpressions.

private void orderByExpressions(ParserString raw, Selects selects) throws SQLParserException {
    Expression exp = null;
    do {
        raw.removeSpace();
        // print.out(raw.getCurrent());
        exp = expression(raw);
        if (!(exp instanceof Column))
            throw new SQLParserException("invalid order by part of query");
        Column col = (Column) exp;
        raw.removeSpace();
        if (raw.forwardIfCurrent("desc"))
            col.setDirectionBackward(true);
        if (raw.forwardIfCurrent("asc"))
            col.setDirectionBackward(false);
        selects.addOrderByExpression(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 5 with Expression

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

the class SelectParser method tableList.

private void tableList(ParserString raw, Select select) throws SQLParserException {
    Column column = null;
    Expression exp = null;
    do {
        raw.removeSpace();
        exp = column(raw);
        if (!(exp instanceof Column))
            throw new SQLParserException("invalid table definition");
        column = (Column) exp;
        raw.removeSpace();
        if (raw.forwardIfCurrent("as ")) {
            String alias = identifier(raw, new RefBooleanImpl(false));
            if (alias == null)
                throw new SQLParserException("missing alias in select part");
            column.setAlias(alias);
        } else {
            int start = raw.getPos();
            RefBoolean hasBracked = new RefBooleanImpl(false);
            // TODO having usw
            String alias = identifier(raw, hasBracked);
            if (!hasBracked.toBooleanValue()) {
                if ("where".equalsIgnoreCase(alias))
                    raw.setPos(start);
                else if ("group".equalsIgnoreCase(alias))
                    raw.setPos(start);
                else if ("having".equalsIgnoreCase(alias))
                    raw.setPos(start);
                else if ("union".equalsIgnoreCase(alias))
                    raw.setPos(start);
                else if ("order".equalsIgnoreCase(alias))
                    raw.setPos(start);
                else if ("limit".equalsIgnoreCase(alias))
                    raw.setPos(start);
                else if (alias != null)
                    column.setAlias(alias);
            } else {
                if (alias != null)
                    column.setAlias(alias);
            }
        }
        select.addFromExpression(column);
        raw.removeSpace();
    } while (raw.forwardIfCurrent(','));
}
Also used : RefBoolean(lucee.commons.lang.types.RefBoolean) Column(lucee.runtime.sql.exp.Column) ColumnExpression(lucee.runtime.sql.exp.ColumnExpression) Expression(lucee.runtime.sql.exp.Expression) ParserString(lucee.commons.lang.ParserString) ValueString(lucee.runtime.sql.exp.value.ValueString) RefBooleanImpl(lucee.commons.lang.types.RefBooleanImpl)

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