}
private void parseEndOfQuery(Query command) {
if (readIf("ORDER")) {
read("BY");
Select oldSelect = currentSelect;
if (command instanceof Select) {
currentSelect = (Select) command;
}
ArrayList<SelectOrderBy> orderList = New.arrayList();
do {
boolean canBeNumber = true;
if (readIf("=")) {
canBeNumber = false;
}
SelectOrderBy order = new SelectOrderBy();
Expression expr = readExpression();
if (canBeNumber && expr instanceof ValueExpression && expr.getType() == Value.INT) {
order.columnIndexExpr = expr;
} else if (expr instanceof Parameter) {
recompileAlways = true;
order.columnIndexExpr = expr;
} else {
order.expression = expr;
}
if (readIf("DESC")) {
order.descending = true;
} else {
readIf("ASC");
}
if (readIf("NULLS")) {
if (readIf("FIRST")) {
order.nullsFirst = true;
} else {
read("LAST");
order.nullsLast = true;
}
}
orderList.add(order);
} while (readIf(","));
command.setOrder(orderList);
currentSelect = oldSelect;
}
if (database.getMode().supportOffsetFetch) {
// make sure aggregate functions will not work here
Select temp = currentSelect;
currentSelect = null;
// http://sqlpro.developpez.com/SQL2008/
if (readIf("OFFSET")) {
command.setOffset(readExpression().optimize(session));
if (!readIf("ROW")) {
read("ROWS");
}
}
if (readIf("FETCH")) {
if (!readIf("FIRST")) {
read("NEXT");
}
if (readIf("ROW")) {
command.setLimit(ValueExpression.get(ValueInt.get(1)));
} else {
Expression limit = readExpression().optimize(session);
command.setLimit(limit);
if (!readIf("ROW")) {
read("ROWS");
}
}
read("ONLY");
}
currentSelect = temp;
}
if (readIf("LIMIT")) {
Select temp = currentSelect;
// make sure aggregate functions will not work here
currentSelect = null;
Expression limit = readExpression().optimize(session);
command.setLimit(limit);
if (readIf("OFFSET")) {