use of lucee.runtime.sql.exp.ColumnExpression in project Lucee by lucee.
the class SelectParser method column.
private Expression column(ParserString raw) throws SQLParserException {
RefBoolean hb = new RefBooleanImpl(false);
String name = identifier(raw, hb);
if (name == null)
return null;
if (!hb.toBooleanValue()) {
if ("true".equalsIgnoreCase(name))
return ValueBoolean.TRUE;
if ("false".equalsIgnoreCase(name))
return ValueBoolean.FALSE;
if ("null".equalsIgnoreCase(name))
return ValueNull.NULL;
}
ColumnExpression column = new ColumnExpression(name, name.equals("?") ? columnIndex++ : 0);
raw.removeSpace();
while (raw.forwardIfCurrent(".")) {
raw.removeSpace();
String sub = identifier(raw, hb);
if (sub == null)
throw new SQLParserException("invalid column definition");
column.setSub(sub);
}
raw.removeSpace();
if (raw.forwardIfCurrent('(')) {
return new OperationN(column.getFullName(), readArguments(raw));
}
return column;
}
use of lucee.runtime.sql.exp.ColumnExpression 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);
}
Aggregations