提交 c8872a9e authored 作者: Thomas Mueller's avatar Thomas Mueller

Referential integrity: it was not allowed to delete a row with NULL in the…

Referential integrity: it was not allowed to delete a row with NULL in the parent table, if there was a row with NULL in the child table.
上级 28077cb0
...@@ -18,7 +18,9 @@ Change Log ...@@ -18,7 +18,9 @@ Change Log
<h1>Change Log</h1> <h1>Change Log</h1>
<h2>Next Version (unreleased)</h2> <h2>Next Version (unreleased)</h2>
<ul><li>Experimental feature to support case sensitive catalog names <ul><li>Referential integrity: it was not allowed to delete a row with NULL in the parent table,
if there was a row with NULL in the child table.
</li><li>Experimental feature to support case sensitive catalog names
and database names using the DATABASE() method. and database names using the DATABASE() method.
To use this feature, set the system property h2.databaseToUpper to false. To use this feature, set the system property h2.databaseToUpper to false.
The plan is to set the property to false by default in version 1.3.x. The plan is to set the property to false by default in version 1.3.x.
......
...@@ -370,6 +370,9 @@ public class ConstraintReferential extends Constraint { ...@@ -370,6 +370,9 @@ public class ConstraintReferential extends Constraint {
int refIdx = refCol.getColumnId(); int refIdx = refCol.getColumnId();
Column col = columns[i].column; Column col = columns[i].column;
Value v = col.convert(oldRow.getValue(refIdx)); Value v = col.convert(oldRow.getValue(refIdx));
if (v == ValueNull.INSTANCE) {
return;
}
check.setValue(col.getColumnId(), v); check.setValue(col.getColumnId(), v);
} }
// exclude the row only for self-referencing constraints // exclude the row only for self-referencing constraints
......
--- special grammar and test cases --------------------------------------------------------------------------------------------- --- special grammar and test cases ---------------------------------------------------------------------------------------------
create table a(x int, y int);
> ok
create unique index a_xy on a(x, y);
> ok
create table b(x int, y int, foreign key(x, y) references a(x, y));
> ok
insert into a values(null, null), (null, 0), (0, null), (0, 0);
> update count: 4
insert into b values(null, null), (null, 0), (0, null), (0, 0);
> update count: 4
delete from a where x is null and y is null;
> update count: 1
delete from a where x is null and y = 0;
> update count: 1
delete from a where x = 0 and y is null;
> update count: 1
delete from a where x = 0 and y = 0;
> exception
drop table b;
> ok
drop table a;
> ok
select * from (select null as x) where x=1; select * from (select null as x) where x=1;
> X > X
> - > -
......
create table a(id int) as select null;
create table b(id int references a(id)) as select null;
delete from a;
drop table a, b;
create table test(a int, b int) as select 2, 0; create table test(a int, b int) as select 2, 0;
create index idx on test(b, a); create index idx on test(b, a);
select count(*) from test where a in(2, 10) and b in(0, null); select count(*) from test where a in(2, 10) and b in(0, null);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论