提交 3f900196 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Support Interval class in more places

上级 41c30c1c
...@@ -30,6 +30,7 @@ import java.util.HashMap; ...@@ -30,6 +30,7 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import org.h2.api.ErrorCode; import org.h2.api.ErrorCode;
import org.h2.api.Interval;
import org.h2.api.TimestampWithTimeZone; import org.h2.api.TimestampWithTimeZone;
import org.h2.command.CommandInterface; import org.h2.command.CommandInterface;
import org.h2.engine.Mode; import org.h2.engine.Mode;
...@@ -53,6 +54,7 @@ import org.h2.value.ValueDecimal; ...@@ -53,6 +54,7 @@ import org.h2.value.ValueDecimal;
import org.h2.value.ValueDouble; import org.h2.value.ValueDouble;
import org.h2.value.ValueFloat; import org.h2.value.ValueFloat;
import org.h2.value.ValueInt; import org.h2.value.ValueInt;
import org.h2.value.ValueInterval;
import org.h2.value.ValueLong; import org.h2.value.ValueLong;
import org.h2.value.ValueNull; import org.h2.value.ValueNull;
import org.h2.value.ValueShort; import org.h2.value.ValueShort;
...@@ -3929,6 +3931,12 @@ public class JdbcResultSet extends TraceObject implements ResultSet, JdbcResultS ...@@ -3929,6 +3931,12 @@ public class JdbcResultSet extends TraceObject implements ResultSet, JdbcResultS
} else if (type == TimestampWithTimeZone.class) { } else if (type == TimestampWithTimeZone.class) {
ValueTimestampTimeZone v = (ValueTimestampTimeZone) value.convertTo(Value.TIMESTAMP_TZ); ValueTimestampTimeZone v = (ValueTimestampTimeZone) value.convertTo(Value.TIMESTAMP_TZ);
return type.cast(new TimestampWithTimeZone(v.getDateValue(), v.getTimeNanos(), v.getTimeZoneOffsetMins())); return type.cast(new TimestampWithTimeZone(v.getDateValue(), v.getTimeNanos(), v.getTimeZoneOffsetMins()));
} else if (type == Interval.class) {
if (!(value instanceof ValueInterval)) {
value = value.convertTo(Value.INTERVAL_DAY_TO_SECOND);
}
ValueInterval v = (ValueInterval) value;
return type.cast(new Interval(v.getQualifier(), v.getLeading(), v.getRemaining()));
} else if (DataType.isGeometryClass(type)) { } else if (DataType.isGeometryClass(type)) {
return type.cast(value.convertTo(Value.GEOMETRY).getObject()); return type.cast(value.convertTo(Value.GEOMETRY).getObject());
} else if (type == LocalDateTimeUtils.LOCAL_DATE) { } else if (type == LocalDateTimeUtils.LOCAL_DATE) {
......
...@@ -896,6 +896,21 @@ public class DataType { ...@@ -896,6 +896,21 @@ public class DataType {
return ResultSet.class.getName(); return ResultSet.class.getName();
case Value.GEOMETRY: case Value.GEOMETRY:
return GEOMETRY_CLASS_NAME; return GEOMETRY_CLASS_NAME;
case Value.INTERVAL_YEAR:
case Value.INTERVAL_MONTH:
case Value.INTERVAL_DAY:
case Value.INTERVAL_HOUR:
case Value.INTERVAL_MINUTE:
case Value.INTERVAL_SECOND:
case Value.INTERVAL_YEAR_TO_MONTH:
case Value.INTERVAL_DAY_TO_HOUR:
case Value.INTERVAL_DAY_TO_MINUTE:
case Value.INTERVAL_DAY_TO_SECOND:
case Value.INTERVAL_HOUR_TO_MINUTE:
case Value.INTERVAL_HOUR_TO_SECOND:
case Value.INTERVAL_MINUTE_TO_SECOND:
// "org.h2.api.Interval"
return Interval.class.getName();
default: default:
if (JdbcUtils.customDataTypesHandler != null) { if (JdbcUtils.customDataTypesHandler != null) {
return JdbcUtils.customDataTypesHandler.getDataTypeClassName(type); return JdbcUtils.customDataTypesHandler.getDataTypeClassName(type);
...@@ -1257,6 +1272,9 @@ public class DataType { ...@@ -1257,6 +1272,9 @@ public class DataType {
return LocalDateTimeUtils.offsetDateTimeToValue(x); return LocalDateTimeUtils.offsetDateTimeToValue(x);
} else if (x instanceof TimestampWithTimeZone) { } else if (x instanceof TimestampWithTimeZone) {
return ValueTimestampTimeZone.get((TimestampWithTimeZone) x); return ValueTimestampTimeZone.get((TimestampWithTimeZone) x);
} else if (x instanceof Interval) {
Interval i = (Interval) x;
return ValueInterval.from(i.getQualifier(), i.getLeading(), i.getRemaining());
} else { } else {
if (JdbcUtils.customDataTypesHandler != null) { if (JdbcUtils.customDataTypesHandler != null) {
return JdbcUtils.customDataTypesHandler.getValue(type, x, return JdbcUtils.customDataTypesHandler.getValue(type, x,
......
...@@ -30,6 +30,8 @@ import java.util.GregorianCalendar; ...@@ -30,6 +30,8 @@ import java.util.GregorianCalendar;
import java.util.UUID; import java.util.UUID;
import org.h2.api.ErrorCode; import org.h2.api.ErrorCode;
import org.h2.api.Interval;
import org.h2.api.IntervalQualifier;
import org.h2.api.Trigger; import org.h2.api.Trigger;
import org.h2.engine.SysProperties; import org.h2.engine.SysProperties;
import org.h2.message.DbException; import org.h2.message.DbException;
...@@ -180,6 +182,7 @@ public class TestPreparedStatement extends TestDb { ...@@ -180,6 +182,7 @@ public class TestPreparedStatement extends TestDb {
testDateTime8(conn); testDateTime8(conn);
testOffsetDateTime8(conn); testOffsetDateTime8(conn);
testInstant8(conn); testInstant8(conn);
testInterval(conn);
testArray(conn); testArray(conn);
testSetObject(conn); testSetObject(conn);
testPreparedSubquery(conn); testPreparedSubquery(conn);
...@@ -902,6 +905,17 @@ public class TestPreparedStatement extends TestDb { ...@@ -902,6 +905,17 @@ public class TestPreparedStatement extends TestDb {
rs.close(); rs.close();
} }
private void testInterval(Connection conn) throws SQLException {
PreparedStatement prep = conn.prepareStatement("SELECT ?");
Interval interval = new Interval(IntervalQualifier.MINUTE, 100, 0);
prep.setObject(1, interval);
ResultSet rs = prep.executeQuery();
rs.next();
assertEquals("INTERVAL '100' MINUTE", rs.getString(1));
assertEquals(interval, rs.getObject(1));
assertEquals(interval, rs.getObject(1, Interval.class));
}
private void testPreparedSubquery(Connection conn) throws SQLException { private void testPreparedSubquery(Connection conn) throws SQLException {
Statement s = conn.createStatement(); Statement s = conn.createStatement();
s.executeUpdate("CREATE TABLE TEST(ID IDENTITY, FLAG BIT)"); s.executeUpdate("CREATE TABLE TEST(ID IDENTITY, FLAG BIT)");
......
...@@ -37,6 +37,8 @@ import java.util.Collections; ...@@ -37,6 +37,8 @@ import java.util.Collections;
import java.util.TimeZone; import java.util.TimeZone;
import org.h2.api.ErrorCode; import org.h2.api.ErrorCode;
import org.h2.api.Interval;
import org.h2.api.IntervalQualifier;
import org.h2.engine.SysProperties; import org.h2.engine.SysProperties;
import org.h2.test.TestBase; import org.h2.test.TestBase;
import org.h2.test.TestDb; import org.h2.test.TestDb;
...@@ -103,6 +105,7 @@ public class TestResultSet extends TestDb { ...@@ -103,6 +105,7 @@ public class TestResultSet extends TestDb {
testDoubleFloat(); testDoubleFloat();
testDatetime(); testDatetime();
testDatetimeWithCalendar(); testDatetimeWithCalendar();
testInterval();
testBlob(); testBlob();
testClob(); testClob();
testAutoIncrement(); testAutoIncrement();
...@@ -1562,6 +1565,22 @@ public class TestResultSet extends TestDb { ...@@ -1562,6 +1565,22 @@ public class TestResultSet extends TestDb {
stat.execute("DROP TABLE TEST"); stat.execute("DROP TABLE TEST");
} }
private void testInterval() throws SQLException {
trace("Test INTERVAL");
ResultSet rs;
rs = stat.executeQuery("CALL INTERVAL '10' YEAR");
rs.next();
assertEquals("INTERVAL '10' YEAR", rs.getString(1));
Interval expected = new Interval(IntervalQualifier.YEAR, 10, 0);
assertEquals(expected, rs.getObject(1));
assertEquals(expected, rs.getObject(1, Interval.class));
ResultSetMetaData metaData = rs.getMetaData();
assertEquals(Types.OTHER, metaData.getColumnType(1));
assertEquals("INTERVAL YEAR", metaData.getColumnTypeName(1));
assertEquals(Interval.class.getName(), metaData.getColumnClassName(1));
}
private void testBlob() throws SQLException { private void testBlob() throws SQLException {
trace("Test BLOB"); trace("Test BLOB");
ResultSet rs; ResultSet rs;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论