Search in sources :

Example 16 with Expression

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

the class SelectParser method xorOp.

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

Example 17 with Expression

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

the class SelectParser method plusMinusOp.

private Expression plusMinusOp(ParserString raw) throws SQLParserException {
    Expression expr = modOp(raw);
    while (!raw.isLast()) {
        // Plus Operation
        if (raw.forwardIfCurrent('+')) {
            raw.removeSpace();
            expr = new Operation2(expr, modOp(raw), Operation.OPERATION2_PLUS);
        } else // Minus Operation
        if (raw.forwardIfCurrent('-')) {
            raw.removeSpace();
            expr = new Operation2(expr, modOp(raw), Operation.OPERATION2_MINUS);
        } else
            break;
    }
    return expr;
}
Also used : ColumnExpression(lucee.runtime.sql.exp.ColumnExpression) Expression(lucee.runtime.sql.exp.Expression) Operation2(lucee.runtime.sql.exp.op.Operation2)

Example 18 with Expression

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

the class SelectParser method divMultiOp.

private Expression divMultiOp(ParserString raw) throws SQLParserException {
    Expression expr = expoOp(raw);
    while (!raw.isLast()) {
        // Multiply Operation
        if (raw.forwardIfCurrent('*')) {
            raw.removeSpace();
            expr = new Operation2(expr, expoOp(raw), Operation.OPERATION2_MULTIPLY);
        } else // Divide Operation
        if (raw.forwardIfCurrent('/')) {
            raw.removeSpace();
            expr = new Operation2(expr, expoOp(raw), Operation.OPERATION2_DIVIDE);
        } else {
            break;
        }
    }
    return expr;
}
Also used : ColumnExpression(lucee.runtime.sql.exp.ColumnExpression) Expression(lucee.runtime.sql.exp.Expression) Operation2(lucee.runtime.sql.exp.op.Operation2)

Example 19 with Expression

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

the class OperationN method toString.

@Override
public String toString(boolean noAlias) {
    if (!hasIndex() || noAlias) {
        StringBuffer sb = new StringBuffer();
        sb.append(operator);
        sb.append('(');
        Iterator it = operants.iterator();
        boolean isFirst = true;
        while (it.hasNext()) {
            if (!isFirst)
                sb.append(',');
            Expression exp = (Expression) it.next();
            sb.append(exp.toString(!operator.equalsIgnoreCase("cast")));
            isFirst = false;
        }
        sb.append(')');
        return sb.toString();
    }
    return toString(true) + " as " + getAlias();
}
Also used : Expression(lucee.runtime.sql.exp.Expression) Iterator(java.util.Iterator)

Example 20 with Expression

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

the class QoQ method executeSingle.

private void executeSingle(PageContext pc, Select select, Query qr, QueryImpl target, int maxrows, SQL sql, boolean hasOrders) throws PageException {
    ValueNumber oTop = select.getTop();
    if (oTop != null) {
        int top = (int) oTop.getValueAsDouble();
        if (maxrows == -1 || maxrows > top)
            maxrows = top;
    }
    int recCount = qr.getRecordcount();
    Expression[] expSelects = select.getSelects();
    int selCount = expSelects.length;
    Map<Collection.Key, Object> selects = new HashMap<Collection.Key, Object>();
    Iterator<Key> it;
    Key k;
    // headers
    for (int i = 0; i < selCount; i++) {
        Expression expSelect = expSelects[i];
        if (expSelect.getAlias().equals("*")) {
            it = qr.keyIterator();
            while (it.hasNext()) {
                k = it.next();
                selects.put(k, k);
                queryAddColumn(target, k, qr.getColumn(k).getType());
            }
        } else {
            Key alias = Caster.toKey(expSelect.getAlias());
            selects.put(alias, expSelect);
            int type = Types.OTHER;
            if (expSelect instanceof ColumnExpression)
                type = qr.getColumn(Caster.toKey(((ColumnExpression) expSelect).getColumnName())).getType();
            queryAddColumn(target, alias, type);
        }
    }
    Collection.Key[] headers = selects.keySet().toArray(new Collection.Key[selects.size()]);
    // loop records
    Operation where = select.getWhere();
    boolean hasMaxrow = maxrows > -1 && !hasOrders;
    // get target columns
    QueryColumn[] trgColumns = new QueryColumn[headers.length];
    Object[] trgValues = new Object[headers.length];
    for (int cell = 0; cell < headers.length; cell++) {
        trgColumns[cell] = target.getColumn(headers[cell]);
        trgValues[cell] = selects.get(headers[cell]);
    }
    for (int row = 1; row <= recCount; row++) {
        sql.setPosition(0);
        if (hasMaxrow && maxrows <= target.getRecordcount())
            break;
        boolean useRow = where == null || Caster.toBooleanValue(executeExp(pc, sql, qr, where, row));
        if (useRow) {
            target.addRow(1);
            for (int cell = 0; cell < headers.length; cell++) {
                // Object value = selects.get(headers[cell]);
                trgColumns[cell].set(target.getRecordcount(), getValue(pc, sql, qr, row, headers[cell], trgValues[cell]));
            /*target.setAt(
							headers[cell],
							target.getRecordcount(),
							getValue(pc,sql,qr,row,headers[cell],trgValues[cell])
						);*/
            }
        }
    }
    // Group By
    if (select.getGroupbys().length > 0)
        throw new DatabaseException("group by are not supported at the moment", null, sql, null);
    if (select.getHaving() != null)
        throw new DatabaseException("having is not supported at the moment", null, sql, null);
}
Also used : HashMap(java.util.HashMap) Operation(lucee.runtime.sql.exp.op.Operation) BracketExpression(lucee.runtime.sql.exp.BracketExpression) ColumnExpression(lucee.runtime.sql.exp.ColumnExpression) Expression(lucee.runtime.sql.exp.Expression) ColumnExpression(lucee.runtime.sql.exp.ColumnExpression) QueryColumn(lucee.runtime.type.QueryColumn) ValueNumber(lucee.runtime.sql.exp.value.ValueNumber) Collection(lucee.runtime.type.Collection) DatabaseException(lucee.runtime.exp.DatabaseException) Key(lucee.runtime.type.Collection.Key)

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