提交 a7a5ab8a authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Return name from ValueEnumBase.getObject()

上级 cc0f5b06
...@@ -21,6 +21,8 @@ Change Log ...@@ -21,6 +21,8 @@ Change Log
<h2>Next Version (unreleased)</h2> <h2>Next Version (unreleased)</h2>
<ul> <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>Issue #1012: NPE when querying INFORMATION_SCHEMA.COLUMNS on a view that references an ENUM column
</li> </li>
<li>Issue #1010: MERGE USING table not found with qualified table <li>Issue #1010: MERGE USING table not found with qualified table
......
...@@ -77,7 +77,7 @@ public class ValueEnumBase extends Value { ...@@ -77,7 +77,7 @@ public class ValueEnumBase extends Value {
@Override @Override
public Object getObject() { public Object getObject() {
return ordinal; return label;
} }
@Override @Override
......
...@@ -87,6 +87,7 @@ public class TestResultSet extends TestBase { ...@@ -87,6 +87,7 @@ public class TestResultSet extends TestBase {
testFindColumn(); testFindColumn();
testColumnLength(); testColumnLength();
testArray(); testArray();
testEnum();
testLimitMaxRows(); testLimitMaxRows();
trace("max rows=" + stat.getMaxRows()); trace("max rows=" + stat.getMaxRows());
...@@ -1798,6 +1799,40 @@ public class TestResultSet extends TestBase { ...@@ -1798,6 +1799,40 @@ public class TestResultSet extends TestBase {
stat.execute("DROP TABLE TEST"); 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'))");
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.setObject(2, "C");
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);
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) { private byte[] readAllBytes(InputStream in) {
if (in == null) { if (in == null) {
return null; return null;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论