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

Allow to set ENUM value with Types.OTHER

上级 a7a5ab8a
...@@ -982,7 +982,16 @@ public abstract class Value { ...@@ -982,7 +982,16 @@ public abstract class Value {
case STRING_IGNORECASE: case STRING_IGNORECASE:
case STRING_FIXED: case STRING_FIXED:
return ValueEnum.get(enumerators, getString()); 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( throw DbException.get(
ErrorCode.DATA_CONVERSION_ERROR_1, getString()); ErrorCode.DATA_CONVERSION_ERROR_1, getString());
} }
......
...@@ -1802,7 +1802,7 @@ public class TestResultSet extends TestBase { ...@@ -1802,7 +1802,7 @@ public class TestResultSet extends TestBase {
private void testEnum() throws SQLException { private void testEnum() throws SQLException {
trace("Test ENUM"); trace("Test ENUM");
stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY, VALUE ENUM('A', 'B', 'C'))"); 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(?, ?)"); PreparedStatement prep = conn.prepareStatement("INSERT INTO TEST VALUES(?, ?)");
prep.setInt(1, 1); prep.setInt(1, 1);
prep.setString(2, "A"); prep.setString(2, "A");
...@@ -1811,13 +1811,29 @@ public class TestResultSet extends TestBase { ...@@ -1811,13 +1811,29 @@ public class TestResultSet extends TestBase {
prep.setObject(2, "B"); prep.setObject(2, "B");
prep.executeUpdate(); prep.executeUpdate();
prep.setInt(1, 3); prep.setInt(1, 3);
prep.setObject(2, "C"); 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(); prep.executeUpdate();
ResultSet rs = stat.executeQuery("SELECT * FROM TEST ORDER BY ID"); ResultSet rs = stat.executeQuery("SELECT * FROM TEST ORDER BY ID");
testEnumResult(rs, 1, "A", 0); testEnumResult(rs, 1, "A", 0);
testEnumResult(rs, 2, "B", 1); testEnumResult(rs, 2, "B", 1);
testEnumResult(rs, 3, "C", 2); 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()); assertFalse(rs.next());
stat.execute("DROP TABLE TEST"); stat.execute("DROP TABLE TEST");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论