提交 95c8ef4c authored 作者: Thomas Mueller's avatar Thomas Mueller

--no commit message

--no commit message
上级 99a149ea
......@@ -15,7 +15,7 @@ Change Log
<h2>Next Version (unreleased)</h2>
<ul>
<li>-
<li>UPDATE SET column=DEFAULT is now supported.
</li></ul>
<h2>Version 1.0.67 (2008-02-22)</h2>
......
......@@ -635,7 +635,12 @@ public class Parser {
do {
Column column = readTableColumn(filter);
read("=");
Expression expression = readExpression();
Expression expression;
if (readIf("DEFAULT")) {
expression = ValueExpression.DEFAULT;
} else {
expression = readExpression();
}
command.setAssignment(column, expression);
} while (readIf(","));
}
......
......@@ -11,6 +11,7 @@ import org.h2.constant.ErrorCode;
import org.h2.engine.Right;
import org.h2.engine.Session;
import org.h2.expression.Expression;
import org.h2.expression.ValueExpression;
import org.h2.message.Message;
import org.h2.result.LocalResult;
import org.h2.result.Row;
......@@ -80,6 +81,9 @@ public class Update extends Prepared {
Value newValue;
if (newExpr == null) {
newValue = oldRow.getValue(i);
} else if (newExpr == ValueExpression.DEFAULT) {
Column column = table.getColumn(i);
newValue = column.getDefaultExpression().getValue(session).convertTo(column.getType());
} else {
Column column = table.getColumn(i);
newValue = newExpr.getValue(session).convertTo(column.getType());
......
......@@ -22,6 +22,7 @@ public class ValueExpression extends Expression {
private Value value;
public static final ValueExpression NULL = new ValueExpression(ValueNull.INSTANCE);
public static final ValueExpression DEFAULT = new ValueExpression(ValueNull.INSTANCE);
public static ValueExpression get(Value v) {
if (v == ValueNull.INSTANCE) {
......@@ -86,7 +87,11 @@ public class ValueExpression extends Expression {
}
public String getSQL() {
return value.getSQL();
if (this == DEFAULT) {
return "DEFAULT";
} else {
return value.getSQL();
}
}
public void updateAggregate(Session session) throws SQLException {
......
......@@ -29,7 +29,7 @@ INSERT INTO TEST VALUES(1, 'Hello')
"Commands (DML)","UPDATE","
UPDATE tableName
SET {columnName=expression} [,...]
SET {columnName= {DEFAULT | expression} } [,...]
[WHERE expression]
","
Updates data in a table.
......
--- special grammar and test cases ---------------------------------------------------------------------------------------------
create table test(a int, b int default 1);
> ok
insert into test values(1, default), (2, 2), (3, null);
> update count: 3
select * from test;
> A B
> - ----
> 1 1
> 2 2
> 3 null
> rows: 3
update test set b = default where a = 2;
> update count: 1
explain update test set b = default where a = 2;
> PLAN
> ---------------------------------------------------------------------------
> UPDATE PUBLIC.TEST /* PUBLIC.TEST_TABLE_SCAN */ SET B = DEFAULT WHERE A = 2
> rows: 1
select * from test;
> A B
> - ----
> 1 1
> 2 1
> 3 null
> rows: 3
drop table test;
> ok
CREATE ROLE X;
> ok
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论