Unverified 提交 ca720764 authored 作者: Noel Grandin's avatar Noel Grandin 提交者: GitHub

Merge pull request #767 from katzyn/getObject

Fix ResultSet.getObject() for BigInteger and remove unneeded check
...@@ -60,7 +60,6 @@ import org.h2.value.ValueShort; ...@@ -60,7 +60,6 @@ import org.h2.value.ValueShort;
import org.h2.value.ValueString; import org.h2.value.ValueString;
import org.h2.value.ValueTime; import org.h2.value.ValueTime;
import org.h2.value.ValueTimestamp; import org.h2.value.ValueTimestamp;
import org.h2.value.ValueTimestampTimeZone;
/** /**
* <p> * <p>
...@@ -3773,7 +3772,7 @@ public class JdbcResultSet extends TraceObject implements ResultSet, JdbcResultS ...@@ -3773,7 +3772,7 @@ public class JdbcResultSet extends TraceObject implements ResultSet, JdbcResultS
if (type == BigDecimal.class) { if (type == BigDecimal.class) {
return type.cast(value.getBigDecimal()); return type.cast(value.getBigDecimal());
} else if (type == BigInteger.class) { } else if (type == BigInteger.class) {
return type.cast(BigInteger.valueOf(value.getLong())); return type.cast(value.getBigDecimal().toBigInteger());
} else if (type == String.class) { } else if (type == String.class) {
return type.cast(value.getString()); return type.cast(value.getString());
} else if (type == Boolean.class) { } else if (type == Boolean.class) {
...@@ -3827,8 +3826,7 @@ public class JdbcResultSet extends TraceObject implements ResultSet, JdbcResultS ...@@ -3827,8 +3826,7 @@ public class JdbcResultSet extends TraceObject implements ResultSet, JdbcResultS
return type.cast(LocalDateTimeUtils.valueToLocalDateTime(value)); return type.cast(LocalDateTimeUtils.valueToLocalDateTime(value));
} else if (LocalDateTimeUtils.isInstant(type)) { } else if (LocalDateTimeUtils.isInstant(type)) {
return type.cast(LocalDateTimeUtils.valueToInstant(value)); return type.cast(LocalDateTimeUtils.valueToInstant(value));
} else if (LocalDateTimeUtils.isOffsetDateTime(type) && } else if (LocalDateTimeUtils.isOffsetDateTime(type)) {
value instanceof ValueTimestampTimeZone) {
return type.cast(LocalDateTimeUtils.valueToOffsetDateTime(value)); return type.cast(LocalDateTimeUtils.valueToOffsetDateTime(value));
} else { } else {
throw unsupported(type.getName()); throw unsupported(type.getName());
......
...@@ -1152,6 +1152,18 @@ public class TestResultSet extends TestBase { ...@@ -1152,6 +1152,18 @@ public class TestResultSet extends TestBase {
assertTrue(!rs.next()); assertTrue(!rs.next());
stat.execute("DROP TABLE TEST"); stat.execute("DROP TABLE TEST");
stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY,VALUE DECIMAL(22,2))");
stat.execute("INSERT INTO TEST VALUES(1,-12345678909876543210)");
stat.execute("INSERT INTO TEST VALUES(2,12345678901234567890.12345)");
rs = stat.executeQuery("SELECT * FROM TEST ORDER BY ID");
rs.next();
assertEquals(new BigDecimal("-12345678909876543210.00"), rs.getBigDecimal(2));
assertEquals(new BigInteger("-12345678909876543210"), rs.getObject(2, BigInteger.class));
rs.next();
assertEquals(new BigDecimal("12345678901234567890.12"), rs.getBigDecimal(2));
assertEquals(new BigInteger("12345678901234567890"), rs.getObject(2, BigInteger.class));
stat.execute("DROP TABLE TEST");
} }
private void testDoubleFloat() throws SQLException { private void testDoubleFloat() throws SQLException {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论