提交 7f4b8391 authored 作者: Max Englander's avatar Max Englander

enum-support: drop ValueEnum.java (for now); fix originalSQL when parsing enum columns

上级 9015bc1e
......@@ -4198,10 +4198,18 @@ public class Parser {
}
} else if (dataType.enumerated) {
if (readIf("(")) {
enumerators.add(readString());
while(readIf(","))
enumerators.add(readString());
original += '(';
String enumerator0 = readString();
enumerators.add(enumerator0);
original += "'" + enumerator0 + "'";
while(readIf(",")) {
original += ',';
String enumeratorN = readString();
original += "'" + enumeratorN + "'";
enumerators.add(enumeratorN);
}
read(")");
original += ')';
}
} else if (readIf("(")) {
// Support for MySQL: INT(11), MEDIUMINT(8) and so on.
......
......@@ -13,7 +13,6 @@ import org.h2.table.TableFilter;
import org.h2.value.Value;
import org.h2.value.ValueArray;
import org.h2.value.ValueBoolean;
import org.h2.value.ValueEnum;
import org.h2.value.ValueNull;
/**
......
......@@ -686,11 +686,10 @@ public class DataType {
break;
}
case Value.ENUM: {
Object x = rs.getObject(columnIndex);
if (x == null) {
return ValueNull.INSTANCE;
}
return ValueEnum.get((String)x);
int value = rs.getInt(columnIndex);
v = rs.wasNull() ? (Value) ValueNull.INSTANCE :
ValueInt.get(value);
break;
}
case Value.RESULT_SET: {
ResultSet x = (ResultSet) rs.getObject(columnIndex);
......@@ -1026,9 +1025,6 @@ public class DataType {
return ValueJavaObject.getNoCopy(x, null, session.getDataHandler());
}
if (x instanceof String) {
if (type == Value.ENUM) {
return ValueEnum.get((String) x);
}
return ValueString.get((String) x);
} else if (x instanceof Value) {
return (Value) x;
......
......@@ -175,7 +175,7 @@ public abstract class Value {
/**
* The number of value types.
*/
public static final int TYPE_COUNT = TIMESTAMP_TZ;
public static final int TYPE_COUNT = ENUM;
private static SoftReference<Value[]> softCache =
new SoftReference<Value[]>(null);
......
/*
* Copyright 2004-2014 H2 Group. Multiple-Licensed under the MPL 2.0,
* and the EPL 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.value;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import org.h2.engine.SysProperties;
import org.h2.util.MathUtils;
import org.h2.util.StringUtils;
/**
* Implementation of the ENUM data type.
*/
public class ValueEnum extends ValueString {
protected ValueEnum(String value) {
super(value);
}
@Override
public boolean equals(Object other) {
return other instanceof ValueEnum
&& value.equals(((ValueEnum) other).value);
}
@Override
protected int compareSecure(Value o, CompareMode mode) {
// compatibility: the other object could be another type
ValueEnum v = (ValueEnum) o;
return mode.compareString(value, v.value, false);
}
@Override
public int getType() {
return Value.ENUM;
}
/**
* Create a new String value of the current class.
* This method is meant to be overridden by subclasses.
*
* @param s the string
* @return the value
*/
protected Value getNew(String s) {
return ValueEnum.get(s);
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论