Unverified 提交 935dd554 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov 提交者: GitHub

Merge pull request #1017 from katzyn/enum

Return name from ValueEnumBase.getObject()
......@@ -21,6 +21,8 @@ Change Log
<h2>Next Version (unreleased)</h2>
<ul>
<li>Issue #1016: ResultSet.getObject() should return enum value, not ordinal
</li>
<li>Issue #1012: NPE when querying INFORMATION_SCHEMA.COLUMNS on a view that references an ENUM column
</li>
<li>Issue #1010: MERGE USING table not found with qualified table
......
......@@ -982,7 +982,16 @@ public abstract class Value {
case STRING_IGNORECASE:
case STRING_FIXED:
return ValueEnum.get(enumerators, getString());
default:
case JAVA_OBJECT:
Object object = JdbcUtils.deserialize(getBytesNoCopy(),
getDataHandler());
if (object instanceof String) {
return ValueEnum.get(enumerators, (String) object);
} else if (object instanceof Integer) {
return ValueEnum.get(enumerators, (int) object);
}
//$FALL-THROUGH$
default:
throw DbException.get(
ErrorCode.DATA_CONVERSION_ERROR_1, getString());
}
......
......@@ -77,7 +77,7 @@ public class ValueEnumBase extends Value {
@Override
public Object getObject() {
return ordinal;
return label;
}
@Override
......
......@@ -476,7 +476,7 @@ public class TestPreparedStatement extends TestBase {
assertEquals(goodSizes[i], rs.getString(1));
assertEquals(i, rs.getInt(1));
Object o = rs.getObject(1);
assertEquals(Integer.class, o.getClass());
assertEquals(String.class, o.getClass());
}
for (int i = 0; i < goodSizes.length; i++) {
......
......@@ -87,6 +87,7 @@ public class TestResultSet extends TestBase {
testFindColumn();
testColumnLength();
testArray();
testEnum();
testLimitMaxRows();
trace("max rows=" + stat.getMaxRows());
......@@ -1798,6 +1799,56 @@ public class TestResultSet extends TestBase {
stat.execute("DROP TABLE TEST");
}
private void testEnum() throws SQLException {
trace("Test ENUM");
stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY, VALUE ENUM('A', 'B', 'C', 'D', 'E', 'F', 'G'))");
PreparedStatement prep = conn.prepareStatement("INSERT INTO TEST VALUES(?, ?)");
prep.setInt(1, 1);
prep.setString(2, "A");
prep.executeUpdate();
prep.setInt(1, 2);
prep.setObject(2, "B");
prep.executeUpdate();
prep.setInt(1, 3);
prep.setInt(2, 2);
prep.executeUpdate();
prep.setInt(1, 4);
prep.setObject(2, "D", Types.VARCHAR);
prep.executeUpdate();
prep.setInt(1, 5);
prep.setObject(2, "E", Types.OTHER);
prep.executeUpdate();
prep.setInt(1, 6);
prep.setObject(2, 5, Types.OTHER);
prep.executeUpdate();
prep.setInt(1, 7);
prep.setObject(2, 6, Types.INTEGER);
prep.executeUpdate();
ResultSet rs = stat.executeQuery("SELECT * FROM TEST ORDER BY ID");
testEnumResult(rs, 1, "A", 0);
testEnumResult(rs, 2, "B", 1);
testEnumResult(rs, 3, "C", 2);
testEnumResult(rs, 4, "D", 3);
testEnumResult(rs, 5, "E", 4);
testEnumResult(rs, 6, "F", 5);
testEnumResult(rs, 7, "G", 6);
assertFalse(rs.next());
stat.execute("DROP TABLE TEST");
}
private void testEnumResult(ResultSet rs, int id, String name, int ordinal) throws SQLException {
assertTrue(rs.next());
assertEquals(id, rs.getInt(1));
assertEquals(name, rs.getString(2));
assertEquals(name, rs.getObject(2));
assertEquals(name, rs.getObject(2, String.class));
assertEquals(ordinal, rs.getInt(2));
assertEquals((Integer) ordinal, rs.getObject(2, Integer.class));
}
private byte[] readAllBytes(InputStream in) {
if (in == null) {
return null;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论