Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
3b88858e
提交
3b88858e
authored
3月 28, 2018
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix update count for ON DUPLICATE KEY UPDATE
上级
06da38de
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
39 行增加
和
8 行删除
+39
-8
Insert.java
h2/src/main/org/h2/command/dml/Insert.java
+10
-5
Update.java
h2/src/main/org/h2/command/dml/Update.java
+15
-1
TestCompatibility.java
h2/src/test/org/h2/test/db/TestCompatibility.java
+14
-2
没有找到文件。
h2/src/main/org/h2/command/dml/Insert.java
浏览文件 @
3b88858e
...
...
@@ -181,11 +181,15 @@ public class Insert extends Prepared implements ResultTarget {
try
{
table
.
addRow
(
session
,
newRow
);
}
catch
(
DbException
de
)
{
if
(!
handleOnDuplicate
(
de
))
{
if
(
handleOnDuplicate
(
de
))
{
// MySQL returns 2 for updated row
// TODO: detect no-op change
rowNumber
++;
}
else
{
// INSERT IGNORE case
rowNumber
--;
continue
;
}
continue
;
}
generatedKeys
.
confirmRow
(
newRow
);
session
.
log
(
table
,
UndoLogRecord
.
INSERT
,
newRow
);
...
...
@@ -399,16 +403,17 @@ public class Insert extends Prepared implements ResultTarget {
}
buff
.
append
(
prepareUpdateCondition
(
foundIndex
).
getSQL
());
String
sql
=
buff
.
toString
();
Prepared
command
=
session
.
prepare
(
sql
);
Update
command
=
(
Update
)
session
.
prepare
(
sql
);
command
.
setUpdateToCurrentValuesReturnsZero
(
true
);
for
(
Parameter
param
:
command
.
getParameters
())
{
Parameter
insertParam
=
parameters
.
get
(
param
.
getIndex
());
param
.
setValue
(
insertParam
.
getValue
(
session
));
}
command
.
update
()
;
boolean
result
=
command
.
update
()
>
0
;
for
(
String
variableName
:
variableNames
)
{
session
.
setVariable
(
variableName
,
ValueNull
.
INSTANCE
);
}
return
true
;
return
result
;
}
private
Expression
prepareUpdateCondition
(
Index
foundIndex
)
{
...
...
h2/src/main/org/h2/command/dml/Update.java
浏览文件 @
3b88858e
...
...
@@ -49,6 +49,8 @@ public class Update extends Prepared {
/** The limit expression as specified in the LIMIT clause. */
private
Expression
limitExpr
;
private
boolean
updateToCurrentValuesReturnsZero
;
private
final
ArrayList
<
Column
>
columns
=
New
.
arrayList
();
private
final
HashMap
<
Column
,
Expression
>
expressionMap
=
new
HashMap
<>();
...
...
@@ -134,7 +136,7 @@ public class Update extends Prepared {
}
newRow
.
setValue
(
i
,
newValue
);
}
if
(
setOnUpdate
)
{
if
(
setOnUpdate
||
updateToCurrentValuesReturnsZero
)
{
setOnUpdate
=
false
;
for
(
int
i
=
0
;
i
<
columnCount
;
i
++)
{
// Use equals here to detect changes from numeric 0 to 0.0 and similar
...
...
@@ -152,6 +154,8 @@ public class Update extends Prepared {
}
}
}
}
else
if
(
updateToCurrentValuesReturnsZero
)
{
count
--;
}
}
table
.
validateConvertUpdateSequence
(
session
,
newRow
);
...
...
@@ -268,4 +272,14 @@ public class Update extends Prepared {
public
void
setSourceTableFilter
(
TableFilter
sourceTableFilter
)
{
this
.
sourceTableFilter
=
sourceTableFilter
;
}
/**
* Sets expected update count for update to current values case.
*
* @param updateToCurrentValuesReturnsZero if zero should be returned as update
* count if update set row to current values
*/
public
void
setUpdateToCurrentValuesReturnsZero
(
boolean
updateToCurrentValuesReturnsZero
)
{
this
.
updateToCurrentValuesReturnsZero
=
updateToCurrentValuesReturnsZero
;
}
}
h2/src/test/org/h2/test/db/TestCompatibility.java
浏览文件 @
3b88858e
...
...
@@ -63,8 +63,20 @@ public class TestCompatibility extends TestBase {
stat
.
execute
(
"create schema s2"
);
stat
.
execute
(
"create table s2.test(id int primary key, name varchar(255))"
);
stat
.
execute
(
"insert into s2.test(id, name) values(1, 'a')"
);
stat
.
execute
(
"insert into s2.test(id, name) values(1, 'b') "
+
"on duplicate key update name = values(name)"
);
assertEquals
(
2
,
stat
.
executeUpdate
(
"insert into s2.test(id, name) values(1, 'b') "
+
"on duplicate key update name = values(name)"
));
assertEquals
(
0
,
stat
.
executeUpdate
(
"insert into s2.test(id, name) values(1, 'b') "
+
"on duplicate key update name = values(name)"
));
assertEquals
(
1
,
stat
.
executeUpdate
(
"insert into s2.test(id, name) values(2, 'c') "
+
"on duplicate key update name = values(name)"
));
ResultSet
rs
=
stat
.
executeQuery
(
"select id, name from s2.test order by id"
);
assertTrue
(
rs
.
next
());
assertEquals
(
1
,
rs
.
getInt
(
1
));
assertEquals
(
"b"
,
rs
.
getString
(
2
));
assertTrue
(
rs
.
next
());
assertEquals
(
2
,
rs
.
getInt
(
1
));
assertEquals
(
"c"
,
rs
.
getString
(
2
));
assertFalse
(
rs
.
next
());
stat
.
execute
(
"drop schema s2 cascade"
);
c
.
close
();
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论