Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
7e39f8a2
提交
7e39f8a2
authored
10月 04, 2018
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Forbid deletion of non-updated rows from the same clause in MERGE USING
上级
367cb540
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
74 行增加
和
12 行删除
+74
-12
Delete.java
h2/src/main/org/h2/command/dml/Delete.java
+25
-10
MergeUsing.java
h2/src/main/org/h2/command/dml/MergeUsing.java
+9
-1
Update.java
h2/src/main/org/h2/command/dml/Update.java
+17
-1
mergeUsing.sql
h2/src/test/org/h2/test/scripts/dml/mergeUsing.sql
+23
-0
没有找到文件。
h2/src/main/org/h2/command/dml/Delete.java
浏览文件 @
7e39f8a2
...
...
@@ -5,6 +5,8 @@
*/
package
org
.
h2
.
command
.
dml
;
import
java.util.HashSet
;
import
org.h2.api.Trigger
;
import
org.h2.command.CommandInterface
;
import
org.h2.command.Prepared
;
...
...
@@ -40,6 +42,8 @@ public class Delete extends Prepared {
*/
private
TableFilter
sourceTableFilter
;
private
HashSet
<
Long
>
keysFilter
;
public
Delete
(
Session
session
)
{
super
(
session
);
}
...
...
@@ -56,6 +60,15 @@ public class Delete extends Prepared {
return
this
.
condition
;
}
/**
* Sets the keys filter.
*
* @param keysFilter the keys filter
*/
public
void
setKeysFilter
(
HashSet
<
Long
>
keysFilter
)
{
this
.
keysFilter
=
keysFilter
;
}
@Override
public
int
update
()
{
targetTableFilter
.
startQuery
(
session
);
...
...
@@ -79,6 +92,7 @@ public class Delete extends Prepared {
setCurrentRowNumber
(
rows
.
size
()
+
1
);
if
(
condition
==
null
||
condition
.
getBooleanValue
(
session
))
{
Row
row
=
targetTableFilter
.
get
();
if
(
keysFilter
==
null
||
keysFilter
.
contains
(
row
.
getKey
()))
{
boolean
done
=
false
;
if
(
table
.
fireRow
())
{
done
=
table
.
fireBeforeRow
(
session
,
row
,
null
);
...
...
@@ -92,6 +106,7 @@ public class Delete extends Prepared {
}
}
}
}
int
rowScanCount
=
0
;
for
(
rows
.
reset
();
rows
.
hasNext
();)
{
if
((++
rowScanCount
&
127
)
==
0
)
{
...
...
h2/src/main/org/h2/command/dml/MergeUsing.java
浏览文件 @
7e39f8a2
...
...
@@ -7,6 +7,7 @@ package org.h2.command.dml;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
org.h2.api.ErrorCode
;
import
org.h2.api.Trigger
;
...
...
@@ -113,6 +114,7 @@ public class MergeUsing extends Prepared {
private
int
countUpdatedRows
;
private
Select
targetMatchQuery
;
private
final
HashMap
<
Value
,
Integer
>
targetRowidsRemembered
=
new
HashMap
<>();
private
final
HashSet
<
Long
>
updatedKeys
=
new
HashSet
<>();
private
int
sourceQueryRowNumber
;
...
...
@@ -142,7 +144,8 @@ public class MergeUsing extends Prepared {
sourceQueryRowNumber
=
0
;
checkRights
();
setCurrentRowNumber
(
0
);
// Just to be sure
updatedKeys
.
clear
();
// process source select query data for row creation
ResultInterface
rows
=
query
.
query
(
0
);
targetTable
.
fire
(
session
,
evaluateTriggerMasks
(),
true
);
...
...
@@ -207,6 +210,7 @@ public class MergeUsing extends Prepared {
// allowed together
if
(
deleteCommand
!=
null
)
{
countUpdatedRows
+=
deleteCommand
.
update
();
updatedKeys
.
clear
();
}
}
else
{
if
(
insertCommand
!=
null
)
{
...
...
@@ -328,6 +332,10 @@ public class MergeUsing extends Prepared {
deleteCommand
.
setSourceTableFilter
(
sourceTableFilter
);
deleteCommand
.
setCondition
(
appendOnCondition
(
deleteCommand
));
deleteCommand
.
prepare
();
if
(
updateCommand
!=
null
)
{
updateCommand
.
setUpdatedKeysCollector
(
updatedKeys
);
deleteCommand
.
setKeysFilter
(
updatedKeys
);
}
}
if
(
insertCommand
!=
null
)
{
insertCommand
.
setSourceTableFilter
(
sourceTableFilter
);
...
...
h2/src/main/org/h2/command/dml/Update.java
浏览文件 @
7e39f8a2
...
...
@@ -7,6 +7,7 @@ package org.h2.command.dml;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.Objects
;
import
org.h2.api.ErrorCode
;
...
...
@@ -53,6 +54,8 @@ public class Update extends Prepared {
private
final
ArrayList
<
Column
>
columns
=
Utils
.
newSmallArrayList
();
private
final
HashMap
<
Column
,
Expression
>
expressionMap
=
new
HashMap
<>();
private
HashSet
<
Long
>
updatedKeysCollector
;
public
Update
(
Session
session
)
{
super
(
session
);
}
...
...
@@ -88,6 +91,15 @@ public class Update extends Prepared {
}
}
/**
* Sets the collector of updated keys.
*
* @param updatedKeysCollector the collector of updated keys
*/
public
void
setUpdatedKeysCollector
(
HashSet
<
Long
>
updatedKeysCollector
)
{
this
.
updatedKeysCollector
=
updatedKeysCollector
;
}
@Override
public
int
update
()
{
targetTableFilter
.
startQuery
(
session
);
...
...
@@ -135,7 +147,8 @@ public class Update extends Prepared {
}
newRow
.
setValue
(
i
,
newValue
);
}
newRow
.
setKey
(
oldRow
.
getKey
());
long
key
=
oldRow
.
getKey
();
newRow
.
setKey
(
key
);
if
(
setOnUpdate
||
updateToCurrentValuesReturnsZero
)
{
setOnUpdate
=
false
;
for
(
int
i
=
0
;
i
<
columnCount
;
i
++)
{
...
...
@@ -166,6 +179,9 @@ public class Update extends Prepared {
if
(!
done
)
{
rows
.
add
(
oldRow
);
rows
.
add
(
newRow
);
if
(
updatedKeysCollector
!=
null
)
{
updatedKeysCollector
.
add
(
key
);
}
}
count
++;
}
...
...
h2/src/test/org/h2/test/scripts/dml/mergeUsing.sql
浏览文件 @
7e39f8a2
...
...
@@ -259,5 +259,28 @@ SELECT * FROM TEST;
>
3
50
>
rows
:
3
MERGE
INTO
TEST
USING
(
SELECT
1
)
ON
1
=
1
WHEN
MATCHED
THEN
UPDATE
SET
VALUE
=
60
WHERE
ID
=
3
DELETE
WHERE
ID
=
2
;
>
update
count
:
1
SELECT
*
FROM
TEST
;
>
ID
VALUE
>
-- -----
>
1
50
>
2
50
>
3
60
>
rows
:
3
MERGE
INTO
TEST
USING
(
SELECT
1
)
ON
1
=
1
WHEN
MATCHED
THEN
DELETE
WHERE
ID
=
2
;
>
update
count
:
1
SELECT
*
FROM
TEST
;
>
ID
VALUE
>
-- -----
>
1
50
>
3
60
>
rows
:
2
DROP
TABLE
TEST
;
>
ok
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论