提交 6a8ec3a5 authored 作者: Thomas Mueller's avatar Thomas Mueller

Improved date / time arithmetics. Adding and subtracting a floating point value…

Improved date / time arithmetics. Adding and subtracting a floating point value from a date or timestamp is now supported.
上级 5562036a
......@@ -18,7 +18,9 @@ Change Log
<h1>Change Log</h1>
<h2>Next Version (unreleased)</h2>
<ul><li>When creating a BLOB with in InputStream or a CLOB with a Reader, and the InputStream or Reader
<ul><li>Improved date / time arithmetics. Adding and subtracting a
floating point value from a date or timestamp is now supported.
</li><li>When creating a BLOB with in InputStream or a CLOB with a Reader, and the InputStream or Reader
threw an non-IOException, then the LOB storage was broken when storing LOBs in the database.
</li><li>EXPLAIN SELECT didn't include the sample size if one was set.
</li><li>Improved EXPLAIN plan formatting and documentation.
......
......@@ -14,6 +14,7 @@ import org.h2.table.TableFilter;
import org.h2.util.MathUtils;
import org.h2.value.DataType;
import org.h2.value.Value;
import org.h2.value.ValueInt;
import org.h2.value.ValueNull;
import org.h2.value.ValueString;
......@@ -210,6 +211,16 @@ public class Operation extends Expression {
f.setParameter(2, right);
f.doneWithParameters();
return f.optimize(session);
} else if (l == Value.DECIMAL || l == Value.FLOAT || l == Value.DOUBLE) {
// Oracle date add
Function f = Function.getFunction(session.getDatabase(), "DATEADD");
f.setParameter(0, ValueExpression.get(ValueString.get("SECOND")));
left = new Operation(Operation.MULTIPLY, ValueExpression.get(ValueInt
.get(60 * 60 * 24)), left);
f.setParameter(1, left);
f.setParameter(2, right);
f.doneWithParameters();
return f.optimize(session);
} else if (l == Value.TIME && r == Value.TIME) {
dataType = Value.TIME;
return this;
......@@ -228,6 +239,18 @@ public class Operation extends Expression {
f.setParameter(2, left);
f.doneWithParameters();
return f.optimize(session);
} else if ((l == Value.DATE || l == Value.TIMESTAMP) && (r == Value.DECIMAL || r == Value.FLOAT || r == Value.DOUBLE)) {
// Oracle date subtract
Function f = Function.getFunction(session.getDatabase(), "DATEADD");
f.setParameter(0, ValueExpression.get(ValueString.get("SECOND")));
right = new Operation(Operation.MULTIPLY, ValueExpression.get(ValueInt
.get(60 * 60 * 24)), right);
right = new Operation(NEGATE, right, null);
right = right.optimize(session);
f.setParameter(1, right);
f.setParameter(2, left);
f.doneWithParameters();
return f.optimize(session);
} else if (l == Value.DATE || l == Value.TIMESTAMP) {
if (r == Value.TIME) {
dataType = Value.TIMESTAMP;
......
......@@ -53,6 +53,24 @@ select ts + t + t - t x from test;
> 2010-01-01 01:00:00.0
> rows: 1
select ts + t * 0.5 x from test;
> X
> ---------------------
> 2010-01-01 00:30:00.0
> rows: 1
select ts + 0.5 x from test;
> X
> ---------------------
> 2010-01-01 12:00:00.0
> rows: 1
select ts - 1.5 x from test;
> X
> ---------------------
> 2009-12-30 12:00:00.0
> rows: 1
select ts + 0.5 * t + t - t x from test;
> X
> ---------------------
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论