Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
064d7ba8
Unverified
提交
064d7ba8
authored
3月 28, 2018
作者:
Evgenij Ryazanov
提交者:
GitHub
3月 28, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1028 from katzyn/on_update
Fix more issues with ON DUPLICATE KEY UPDATE in MySQL mode
上级
06da38de
bbe93943
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
75 行增加
和
10 行删除
+75
-10
changelog.html
h2/src/docsrc/html/changelog.html
+6
-0
Parser.java
h2/src/main/org/h2/command/Parser.java
+18
-1
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
+25
-2
dictionary.txt
h2/src/tools/org/h2/build/doc/dictionary.txt
+1
-1
没有找到文件。
h2/src/docsrc/html/changelog.html
浏览文件 @
064d7ba8
...
...
@@ -21,6 +21,12 @@ Change Log
<h2>
Next Version (unreleased)
</h2>
<ul>
<li>
Issue #1027: Add support for fully qualified names in MySQL compatibility mode
</li>
<li>
Issue #178: INSERT ON DUPLICATE KEY UPDATE returns wrong generated key
</li>
<li>
PR #1025: Remove BitField and replace its usages with BitSet
</li>
<li>
Issue #1019: Console incorrectly sorts BigDecimal columns alphanumerically
</li>
<li>
PR #1021: Update JdbcDatabaseMetaData to JDBC 4.1 (Java 7)
...
...
h2/src/main/org/h2/command/Parser.java
浏览文件 @
064d7ba8
...
...
@@ -1232,7 +1232,24 @@ public class Parser {
read
(
"KEY"
);
read
(
"UPDATE"
);
do
{
Column
column
=
parseColumn
(
table
);
String
columnName
=
readColumnIdentifier
();
if
(
readIf
(
"."
))
{
String
schemaOrTableName
=
columnName
;
String
tableOrColumnName
=
readColumnIdentifier
();
if
(
readIf
(
"."
))
{
if
(!
table
.
getSchema
().
getName
().
equals
(
schemaOrTableName
))
{
throw
DbException
.
get
(
ErrorCode
.
SCHEMA_NAME_MUST_MATCH
);
}
columnName
=
readColumnIdentifier
();
}
else
{
columnName
=
tableOrColumnName
;
tableOrColumnName
=
schemaOrTableName
;
}
if
(!
table
.
getName
().
equals
(
tableOrColumnName
))
{
throw
DbException
.
get
(
ErrorCode
.
TABLE_OR_VIEW_NOT_FOUND_1
,
tableOrColumnName
);
}
}
Column
column
=
table
.
getColumn
(
columnName
);
read
(
"="
);
Expression
expression
;
if
(
readIf
(
"DEFAULT"
))
{
...
...
h2/src/main/org/h2/command/dml/Insert.java
浏览文件 @
064d7ba8
...
...
@@ -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
浏览文件 @
064d7ba8
...
...
@@ -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
浏览文件 @
064d7ba8
...
...
@@ -63,8 +63,31 @@ 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
());
// Check qualified names in ON UPDATE case
assertEquals
(
2
,
stat
.
executeUpdate
(
"insert into s2.test(id, name) values(2, 'd') "
+
"on duplicate key update test.name = values(name)"
));
assertThrows
(
ErrorCode
.
TABLE_OR_VIEW_NOT_FOUND_1
,
stat
)
.
executeUpdate
(
"insert into s2.test(id, name) values(2, 'd') "
+
"on duplicate key update test2.name = values(name)"
);
assertEquals
(
2
,
stat
.
executeUpdate
(
"insert into s2.test(id, name) values(2, 'e') "
+
"on duplicate key update s2.test.name = values(name)"
));
assertThrows
(
ErrorCode
.
SCHEMA_NAME_MUST_MATCH
,
stat
)
.
executeUpdate
(
"insert into s2.test(id, name) values(2, 'd') "
+
"on duplicate key update s3.test.name = values(name)"
);
stat
.
execute
(
"drop schema s2 cascade"
);
c
.
close
();
}
...
...
h2/src/tools/org/h2/build/doc/dictionary.txt
浏览文件 @
064d7ba8
...
...
@@ -771,4 +771,4 @@ openoffice organize libre systemtables gmane sea borders announced millennium al
opti excessively
iterators tech enums incompatibilities loses reimplement readme reorganize milli subdirectory linkplain inspections
geometries sourceschema destschema generatedcolumn alphanumerically
geometries sourceschema destschema generatedcolumn alphanumerically
usages
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论