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;
}
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;
}
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;
}
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();
}
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;
}
Aggregations