use of org.h2.table.Column in project h2database by h2database.
the class Expression method getExpressionColumns.
/**
* Extracts expression columns from ValueArray
*
* @param session the current session
* @param value the value to extract columns from
* @return array of expression columns
*/
static Expression[] getExpressionColumns(Session session, ValueArray value) {
Value[] list = value.getList();
ExpressionColumn[] expr = new ExpressionColumn[list.length];
for (int i = 0, len = list.length; i < len; i++) {
Value v = list[i];
Column col = new Column("C" + (i + 1), v.getType(), v.getPrecision(), v.getScale(), v.getDisplaySize());
expr[i] = new ExpressionColumn(session.getDatabase(), col);
}
return expr;
}
use of org.h2.table.Column in project h2database by h2database.
the class ExpressionColumn method getValue.
@Override
public Value getValue(Session session) {
Select select = columnResolver.getSelect();
if (select != null) {
HashMap<Expression, Object> values = select.getCurrentGroup();
if (values != null) {
Value v = (Value) values.get(this);
if (v != null) {
return v;
}
}
}
Value value = columnResolver.getValue(column);
if (value == null) {
if (select == null) {
throw DbException.get(ErrorCode.NULL_NOT_ALLOWED, getSQL());
} else {
throw DbException.get(ErrorCode.MUST_GROUP_BY_COLUMN_1, getSQL());
}
}
if (column.getEnumerators() != null && value != ValueNull.INSTANCE) {
return ValueEnum.get(column.getEnumerators(), value.getInt());
}
return value;
}
use of org.h2.table.Column in project h2database by h2database.
the class ExpressionColumn method updateAggregate.
@Override
public void updateAggregate(Session session) {
Value now = columnResolver.getValue(column);
Select select = columnResolver.getSelect();
if (select == null) {
throw DbException.get(ErrorCode.MUST_GROUP_BY_COLUMN_1, getSQL());
}
HashMap<Expression, Object> values = select.getCurrentGroup();
if (values == null) {
// this is a different level (the enclosing query)
return;
}
Value v = (Value) values.get(this);
if (v == null) {
values.put(this, now);
} else {
if (!database.areEqual(now, v)) {
throw DbException.get(ErrorCode.MUST_GROUP_BY_COLUMN_1, getSQL());
}
}
}
use of org.h2.table.Column in project h2database by h2database.
the class ExpressionList method getExpressionColumns.
@Override
public Expression[] getExpressionColumns(Session session) {
ExpressionColumn[] expr = new ExpressionColumn[list.length];
for (int i = 0; i < list.length; i++) {
Expression e = list[i];
Column col = new Column("C" + (i + 1), e.getType(), e.getPrecision(), e.getScale(), e.getDisplaySize());
expr[i] = new ExpressionColumn(session.getDatabase(), col);
}
return expr;
}
use of org.h2.table.Column in project h2database by h2database.
the class Function method getSQL.
@Override
public String getSQL() {
StatementBuilder buff = new StatementBuilder(info.name);
if (info.type == CASE) {
if (args[0] != null) {
buff.append(" ").append(args[0].getSQL());
}
for (int i = 1, len = args.length - 1; i < len; i += 2) {
buff.append(" WHEN ").append(args[i].getSQL());
buff.append(" THEN ").append(args[i + 1].getSQL());
}
if (args.length % 2 == 0) {
buff.append(" ELSE ").append(args[args.length - 1].getSQL());
}
return buff.append(" END").toString();
}
buff.append('(');
switch(info.type) {
case CAST:
{
buff.append(args[0].getSQL()).append(" AS ").append(new Column(null, dataType, precision, scale, displaySize).getCreateSQL());
break;
}
case CONVERT:
{
if (database.getMode().swapConvertFunctionParameters) {
buff.append(new Column(null, dataType, precision, scale, displaySize).getCreateSQL()).append(',').append(args[0].getSQL());
} else {
buff.append(args[0].getSQL()).append(',').append(new Column(null, dataType, precision, scale, displaySize).getCreateSQL());
}
break;
}
case EXTRACT:
{
ValueString v = (ValueString) ((ValueExpression) args[0]).getValue(null);
buff.append(v.getString()).append(" FROM ").append(args[1].getSQL());
break;
}
default:
{
for (Expression e : args) {
buff.appendExceptFirst(", ");
buff.append(e.getSQL());
}
}
}
return buff.append(')').toString();
}
Aggregations