提交 8013da33 authored 作者: Noel Grandin's avatar Noel Grandin 提交者: GitHub

Merge pull request #615 from andreitokar/issue_611

issue#611 getMetaData().getColumnClassName() fails
...@@ -23,6 +23,7 @@ import org.h2.table.TableFilter; ...@@ -23,6 +23,7 @@ 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; import org.h2.value.ValueEnum;
import org.h2.value.ValueNull;
/** /**
* A expression that represents a column of a table or view. * A expression that represents a column of a table or view.
...@@ -188,7 +189,7 @@ public class ExpressionColumn extends Expression { ...@@ -188,7 +189,7 @@ 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) { if (column.getEnumerators() != null && value != ValueNull.INSTANCE) {
return ValueEnum.get(column.getEnumerators(), value.getInt()); return ValueEnum.get(column.getEnumerators(), value.getInt());
} }
return value; return value;
......
...@@ -383,7 +383,7 @@ public class Column { ...@@ -383,7 +383,7 @@ public class Column {
getCreateSQL(), s + " (" + value.getPrecision() + ")"); getCreateSQL(), s + " (" + value.getPrecision() + ")");
} }
} }
if (isEnumerated()) { if (isEnumerated() && value != ValueNull.INSTANCE) {
if (!ValueEnum.isValid(enumerators, value)) { if (!ValueEnum.isValid(enumerators, value)) {
String s = value.getTraceSQL(); String s = value.getTraceSQL();
if (s.length() > 127) { if (s.length() > 127) {
......
...@@ -727,6 +727,7 @@ public class DataType { ...@@ -727,6 +727,7 @@ public class DataType {
// "java.lang.Short"; // "java.lang.Short";
return Short.class.getName(); return Short.class.getName();
case Value.INT: case Value.INT:
case Value.ENUM:
// "java.lang.Integer"; // "java.lang.Integer";
return Integer.class.getName(); return Integer.class.getName();
case Value.LONG: case Value.LONG:
......
...@@ -7,8 +7,8 @@ ...@@ -7,8 +7,8 @@
create table card (rank int, suit enum('hearts', 'clubs', 'spades')); create table card (rank int, suit enum('hearts', 'clubs', 'spades'));
> ok > ok
insert into card (rank, suit) values (0, 'clubs'), (3, 'hearts'); insert into card (rank, suit) values (0, 'clubs'), (3, 'hearts'), (4, NULL);
> update count: 2 > update count: 3
alter table card alter column suit enum('hearts', 'clubs', 'spades', 'diamonds'); alter table card alter column suit enum('hearts', 'clubs', 'spades', 'diamonds');
> ok > ok
...@@ -18,10 +18,12 @@ select * from card; ...@@ -18,10 +18,12 @@ select * from card;
> ---- ------ > ---- ------
> 0 clubs > 0 clubs
> 3 hearts > 3 hearts
> 4 null
select * from card order by suit; select * from card order by suit;
> RANK SUIT > RANK SUIT
> ---- ------ > ---- ------
> 4 null
> 3 hearts > 3 hearts
> 0 clubs > 0 clubs
...@@ -31,6 +33,7 @@ insert into card (rank, suit) values (8, 'diamonds'), (10, 'clubs'), (7, 'hearts ...@@ -31,6 +33,7 @@ insert into card (rank, suit) values (8, 'diamonds'), (10, 'clubs'), (7, 'hearts
select suit, count(rank) from card group by suit order by suit, count(rank); select suit, count(rank) from card group by suit order by suit, count(rank);
> SUIT COUNT(RANK) > SUIT COUNT(RANK)
> -------- ----------- > -------- -----------
> null 1
> hearts 2 > hearts 2
> clubs 2 > clubs 2
> diamonds 1 > diamonds 1
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论