Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
40f3269b
提交
40f3269b
authored
5月 27, 2018
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Require MATCHED THEN | NOT MATCHED THEN after WHERE in MERGE USING
上级
39c36dd2
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
37 行增加
和
33 行删除
+37
-33
Parser.java
h2/src/main/org/h2/command/Parser.java
+21
-33
mergeUsing.sql
h2/src/test/org/h2/test/scripts/dml/mergeUsing.sql
+16
-0
没有找到文件。
h2/src/main/org/h2/command/Parser.java
浏览文件 @
40f3269b
...
@@ -1172,10 +1172,22 @@ public class Parser {
...
@@ -1172,10 +1172,22 @@ public class Parser {
command
.
setOnCondition
(
condition
);
command
.
setOnCondition
(
condition
);
read
(
")"
);
read
(
")"
);
boolean
matched
=
parseWhenMatched
(
command
);
if
(
readIf
(
"WHEN"
))
{
if
(
parseWhenNotMatched
(
command
)
&&
!
matched
)
{
boolean
matched
=
readIf
(
"MATCHED"
);
if
(
matched
)
{
parseWhenMatched
(
command
);
}
else
{
parseWhenNotMatched
(
command
);
}
if
(
readIf
(
"WHEN"
))
{
if
(
matched
)
{
parseWhenNotMatched
(
command
);
}
else
{
read
(
"MATCHED"
);
parseWhenMatched
(
command
);
parseWhenMatched
(
command
);
}
}
}
}
setSQL
(
command
,
"MERGE"
,
start
);
setSQL
(
command
,
"MERGE"
,
start
);
...
@@ -1192,10 +1204,8 @@ public class Parser {
...
@@ -1192,10 +1204,8 @@ public class Parser {
return
command
;
return
command
;
}
}
private
boolean
parseWhenMatched
(
MergeUsing
command
)
{
private
void
parseWhenMatched
(
MergeUsing
command
)
{
if
(!
readIfAll
(
"WHEN"
,
"MATCHED"
,
"THEN"
))
{
read
(
"THEN"
);
return
false
;
}
int
startMatched
=
lastParseIndex
;
int
startMatched
=
lastParseIndex
;
if
(
readIf
(
"UPDATE"
))
{
if
(
readIf
(
"UPDATE"
))
{
Update
updateCommand
=
new
Update
(
session
);
Update
updateCommand
=
new
Update
(
session
);
...
@@ -1212,20 +1222,18 @@ public class Parser {
...
@@ -1212,20 +1222,18 @@ public class Parser {
parseDeleteGivenTable
(
deleteCommand
,
null
,
startMatched
);
parseDeleteGivenTable
(
deleteCommand
,
null
,
startMatched
);
command
.
setDeleteCommand
(
deleteCommand
);
command
.
setDeleteCommand
(
deleteCommand
);
}
}
return
true
;
}
}
private
boolean
parseWhenNotMatched
(
MergeUsing
command
)
{
private
void
parseWhenNotMatched
(
MergeUsing
command
)
{
if
(!
readIfAll
(
"WHEN"
,
"NOT"
,
"MATCHED"
,
"THEN"
))
{
read
(
"NOT"
);
return
false
;
read
(
"MATCHED"
)
;
}
read
(
"THEN"
);
if
(
readIf
(
"INSERT"
))
{
if
(
readIf
(
"INSERT"
))
{
Insert
insertCommand
=
new
Insert
(
session
);
Insert
insertCommand
=
new
Insert
(
session
);
insertCommand
.
setTable
(
command
.
getTargetTable
());
insertCommand
.
setTable
(
command
.
getTargetTable
());
parseInsertGivenTable
(
insertCommand
,
command
.
getTargetTable
());
parseInsertGivenTable
(
insertCommand
,
command
.
getTargetTable
());
command
.
setInsertCommand
(
insertCommand
);
command
.
setInsertCommand
(
insertCommand
);
}
}
return
true
;
}
}
private
static
void
appendTableWithSchemaAndAlias
(
StringBuilder
buff
,
Table
table
,
String
alias
)
{
private
static
void
appendTableWithSchemaAndAlias
(
StringBuilder
buff
,
Table
table
,
String
alias
)
{
...
@@ -3554,26 +3562,6 @@ public class Parser {
...
@@ -3554,26 +3562,6 @@ public class Parser {
return
false
;
return
false
;
}
}
/*
* Reads every token in list, in order - returns true if all are found.
* If any are not found, returns false - AND resets parsing back to state when called.
*/
private
boolean
readIfAll
(
String
...
tokens
)
{
// save parse location in case we have to fail this test
int
start
=
lastParseIndex
;
for
(
String
token:
tokens
)
{
if
(!
currentTokenQuoted
&&
equalsToken
(
token
,
currentToken
))
{
read
();
}
else
{
// read failed - revert parse location to before when called
parseIndex
=
start
;
read
();
return
false
;
}
}
return
true
;
}
private
boolean
isToken
(
String
token
)
{
private
boolean
isToken
(
String
token
)
{
boolean
result
=
equalsToken
(
token
,
currentToken
)
&&
boolean
result
=
equalsToken
(
token
,
currentToken
)
&&
!
currentTokenQuoted
;
!
currentTokenQuoted
;
...
...
h2/src/test/org/h2/test/scripts/dml/mergeUsing.sql
浏览文件 @
40f3269b
...
@@ -149,3 +149,19 @@ SELECT * FROM TEST ORDER BY C1, C2;
...
@@ -149,3 +149,19 @@ SELECT * FROM TEST ORDER BY C1, C2;
DROP
TABLE
TEST
;
DROP
TABLE
TEST
;
>
ok
>
ok
CREATE
TABLE
TEST
(
ID
INT
,
VALUE
INT
);
>
ok
MERGE
INTO
TEST
USING
DUAL
ON
(
ID
=
1
)
WHEN
MATCHED
THEN
UPDATE
SET
VALUE
=
1
WHEN
;
>
exception
SYNTAX_ERROR_2
MERGE
INTO
TEST
USING
DUAL
ON
(
ID
=
1
)
WHEN
NOT
MATCHED
THEN
INSERT
(
ID
,
VALUE
)
VALUES
(
1
,
1
)
WHEN
;
>
exception
SYNTAX_ERROR_2
DROP
TABLE
TEST
;
>
ok
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论