提交 d0fe846b authored 作者: Max Englander's avatar Max Englander

display enum labels while maintaining sort-on-int-value

上级 7f4b8391
...@@ -22,6 +22,7 @@ import org.h2.table.Table; ...@@ -22,6 +22,7 @@ import org.h2.table.Table;
import org.h2.table.TableFilter; import org.h2.table.TableFilter;
import org.h2.value.Value; import org.h2.value.Value;
import org.h2.value.ValueBoolean; import org.h2.value.ValueBoolean;
import org.h2.value.ValueEnum;
/** /**
* A expression that represents a column of a table or view. * A expression that represents a column of a table or view.
...@@ -187,6 +188,11 @@ public class ExpressionColumn extends Expression { ...@@ -187,6 +188,11 @@ public class ExpressionColumn extends Expression {
columnResolver.getValue(column); columnResolver.getValue(column);
throw DbException.get(ErrorCode.MUST_GROUP_BY_COLUMN_1, getSQL()); throw DbException.get(ErrorCode.MUST_GROUP_BY_COLUMN_1, getSQL());
} }
if (column.getEnumerators() != null) {
final int ordinal = value.getInt();
return new ValueEnum(column.getEnumerators()
.toArray(new String[column.getEnumerators().size()]), ordinal);
}
return value; return value;
} }
......
...@@ -38,6 +38,7 @@ import org.h2.util.StringUtils; ...@@ -38,6 +38,7 @@ import org.h2.util.StringUtils;
import org.h2.value.Transfer; import org.h2.value.Transfer;
import org.h2.value.Value; import org.h2.value.Value;
import org.h2.value.ValueLobDb; import org.h2.value.ValueLobDb;
import org.h2.value.ValueString;
/** /**
* One server thread is opened per client connection. * One server thread is opened per client connection.
......
...@@ -32,6 +32,7 @@ import org.h2.util.StatementBuilder; ...@@ -32,6 +32,7 @@ import org.h2.util.StatementBuilder;
import org.h2.util.StringUtils; import org.h2.util.StringUtils;
import org.h2.value.Value; import org.h2.value.Value;
import org.h2.value.ValueLong; import org.h2.value.ValueLong;
import org.h2.value.ValueString;
import org.h2.value.ValueNull; import org.h2.value.ValueNull;
/** /**
......
package org.h2.value;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import org.h2.util.MathUtils;
public class ValueEnum extends Value {
public static final int PRECISION = 10;
public static final int DISPLAY_SIZE = 11;
private final String[] labels;
private final String label;
private final int ordinal;
public ValueEnum(final String[] labels, final int ordinal) {
this.label = labels[ordinal];
this.labels = labels;
this.ordinal = ordinal;
}
@Override
public Value add(final Value v) {
throw new UnsupportedOperationException("Not yet implemented");
}
@Override
protected int compareSecure(final Value o, final CompareMode mode) {
final ValueEnum v = (ValueEnum) o;
return MathUtils.compareInt(ordinal(), v.ordinal());
}
@Override
public Value divide(final Value v) {
throw new UnsupportedOperationException("Not yet implemented");
}
@Override
public boolean equals(final Object other) {
return other instanceof ValueEnum &&
ordinal() == ((ValueEnum) other).ordinal();
}
@Override
public int getDisplaySize() {
return DISPLAY_SIZE;
}
@Override
public int getInt() {
return ordinal;
}
@Override
public long getLong() {
return ordinal;
}
@Override
public Object getObject() {
return ordinal;
}
@Override
public long getPrecision() {
return PRECISION;
}
@Override
public int getSignum() {
return Integer.signum(ordinal);
}
@Override
public String getSQL() {
return getString();
}
@Override
public String getString() {
return label;
}
@Override
public int hashCode() {
return ordinal;
}
@Override
public int getType() {
return Value.INT;
}
@Override
public Value modulus(final Value v) {
throw new UnsupportedOperationException("Not yet implemented");
}
@Override
public Value multiply(final Value v) {
throw new UnsupportedOperationException("Not yet implemented");
}
@Override
public Value negate() {
throw new UnsupportedOperationException("Not yet implemented");
}
protected int ordinal() {
return ordinal;
}
@Override
public void set(final PreparedStatement prep, final int parameterIndex)
throws SQLException {
prep.setInt(parameterIndex, ordinal);
}
@Override
public Value subtract(final Value v) {
throw new UnsupportedOperationException("Not yet implemented");
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论