提交 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 { ...@@ -4198,10 +4198,18 @@ public class Parser {
} }
} else if (dataType.enumerated) { } else if (dataType.enumerated) {
if (readIf("(")) { if (readIf("(")) {
enumerators.add(readString()); original += '(';
while(readIf(",")) String enumerator0 = readString();
enumerators.add(readString()); enumerators.add(enumerator0);
original += "'" + enumerator0 + "'";
while(readIf(",")) {
original += ',';
String enumeratorN = readString();
original += "'" + enumeratorN + "'";
enumerators.add(enumeratorN);
}
read(")"); read(")");
original += ')';
} }
} else if (readIf("(")) { } else if (readIf("(")) {
// Support for MySQL: INT(11), MEDIUMINT(8) and so on. // Support for MySQL: INT(11), MEDIUMINT(8) and so on.
......
...@@ -13,7 +13,6 @@ import org.h2.table.TableFilter; ...@@ -13,7 +13,6 @@ import org.h2.table.TableFilter;
import org.h2.value.Value; import org.h2.value.Value;
import org.h2.value.ValueArray; import org.h2.value.ValueArray;
import org.h2.value.ValueBoolean; import org.h2.value.ValueBoolean;
import org.h2.value.ValueEnum;
import org.h2.value.ValueNull; import org.h2.value.ValueNull;
/** /**
......
...@@ -686,11 +686,10 @@ public class DataType { ...@@ -686,11 +686,10 @@ public class DataType {
break; break;
} }
case Value.ENUM: { case Value.ENUM: {
Object x = rs.getObject(columnIndex); int value = rs.getInt(columnIndex);
if (x == null) { v = rs.wasNull() ? (Value) ValueNull.INSTANCE :
return ValueNull.INSTANCE; ValueInt.get(value);
} break;
return ValueEnum.get((String)x);
} }
case Value.RESULT_SET: { case Value.RESULT_SET: {
ResultSet x = (ResultSet) rs.getObject(columnIndex); ResultSet x = (ResultSet) rs.getObject(columnIndex);
...@@ -1026,9 +1025,6 @@ public class DataType { ...@@ -1026,9 +1025,6 @@ public class DataType {
return ValueJavaObject.getNoCopy(x, null, session.getDataHandler()); return ValueJavaObject.getNoCopy(x, null, session.getDataHandler());
} }
if (x instanceof String) { if (x instanceof String) {
if (type == Value.ENUM) {
return ValueEnum.get((String) x);
}
return ValueString.get((String) x); return ValueString.get((String) x);
} else if (x instanceof Value) { } else if (x instanceof Value) {
return (Value) x; return (Value) x;
......
...@@ -175,7 +175,7 @@ public abstract class Value { ...@@ -175,7 +175,7 @@ public abstract class Value {
/** /**
* The number of value types. * 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 = private static SoftReference<Value[]> softCache =
new SoftReference<Value[]>(null); 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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论