Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
47ff9145
Unverified
提交
47ff9145
authored
5月 27, 2018
作者:
Evgenij Ryazanov
提交者:
GitHub
5月 27, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1164 from katzyn/parser
More fixes for parsing of MERGE USING and other changes in Parser
上级
3c10d9c9
505759e4
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
8 个修改的文件
包含
157 行增加
和
114 行删除
+157
-114
help.csv
h2/src/docsrc/help/help.csv
+41
-13
Command.java
h2/src/main/org/h2/command/Command.java
+2
-2
CommandContainer.java
h2/src/main/org/h2/command/CommandContainer.java
+3
-2
CommandList.java
h2/src/main/org/h2/command/CommandList.java
+4
-2
Parser.java
h2/src/main/org/h2/command/Parser.java
+80
-84
MergeUsing.java
h2/src/main/org/h2/command/dml/MergeUsing.java
+0
-10
TestMergeUsing.java
h2/src/test/org/h2/test/db/TestMergeUsing.java
+1
-1
mergeUsing.sql
h2/src/test/org/h2/test/scripts/dml/mergeUsing.sql
+26
-0
没有找到文件。
h2/src/docsrc/help/help.csv
浏览文件 @
47ff9145
...
@@ -45,11 +45,7 @@ SELECT * FROM (SELECT ID, COUNT(*) FROM TEST
...
@@ -45,11 +45,7 @@ SELECT * FROM (SELECT ID, COUNT(*) FROM TEST
"
"
"Commands (DML)","INSERT","
"Commands (DML)","INSERT","
INSERT INTO tableName
INSERT INTO tableName insertColumnsAndSource
{ [ ( columnName [,...] ) ]
{ VALUES { ( { DEFAULT | expression } [,...] ) } [,...]
| [ DIRECT ] [ SORTED ] select } } |
{ SET { columnName = { DEFAULT | expression } } [,...] }
","
","
Inserts a new row / new rows into a table.
Inserts a new row / new rows into a table.
...
@@ -61,9 +57,7 @@ INSERT INTO TEST VALUES(1, 'Hello')
...
@@ -61,9 +57,7 @@ INSERT INTO TEST VALUES(1, 'Hello')
"
"
"Commands (DML)","UPDATE","
"Commands (DML)","UPDATE","
UPDATE tableName [ [ AS ] newTableAlias ] SET
UPDATE tableName [ [ AS ] newTableAlias ] SET setClauseList
{ { columnName = { DEFAULT | expression } } [,...] } |
{ ( columnName [,...] ) = ( select ) }
[ WHERE expression ] [ ORDER BY order [,...] ] [ LIMIT expression ]
[ WHERE expression ] [ ORDER BY order [,...] ] [ LIMIT expression ]
","
","
Updates data in a table.
Updates data in a table.
...
@@ -74,7 +68,7 @@ UPDATE PERSON P SET NAME=(SELECT A.NAME FROM ADDRESS A WHERE A.ID=P.ID);
...
@@ -74,7 +68,7 @@ UPDATE PERSON P SET NAME=(SELECT A.NAME FROM ADDRESS A WHERE A.ID=P.ID);
"
"
"Commands (DML)","DELETE","
"Commands (DML)","DELETE","
DELETE [ TOP term ] FROM tableName
[ WHERE expression ] [ LIMIT term ]
DELETE [ TOP term ] FROM tableName
deleteSearchCondition
","
","
Deletes rows form a table.
Deletes rows form a table.
If TOP or LIMIT is specified, at most the specified number of rows are deleted (no limit if null or smaller than zero).
If TOP or LIMIT is specified, at most the specified number of rows are deleted (no limit if null or smaller than zero).
...
@@ -129,16 +123,19 @@ MERGE INTO TEST KEY(ID) VALUES(2, 'World')
...
@@ -129,16 +123,19 @@ MERGE INTO TEST KEY(ID) VALUES(2, 'World')
MERGE INTO targetTableName [ [AS] targetAlias]
MERGE INTO targetTableName [ [AS] targetAlias]
USING { ( select ) | sourceTableName }[ [AS] sourceAlias ]
USING { ( select ) | sourceTableName }[ [AS] sourceAlias ]
ON ( expression )
ON ( expression )
[ WHEN MATCHED THEN [ update ] [ delete] ]
[ WHEN MATCHED THEN
[ WHEN NOT MATCHED THEN insert ]
[ UPDATE SET setClauseList ] [ DELETE deleteSearchCondition ] ]
[ WHEN NOT MATCHED THEN INSERT insertColumnsAndSource ]
","
","
Updates or deletes existing rows, and insert rows that don't exist. The ON clause
Updates or deletes existing rows, and insert rows that don't exist. The ON clause
specifies the matching column expression and must be specified. If more than one row
specifies the matching column expression and must be specified. If more than one row
is updated per input row, an exception is thrown.
is updated per input row, an exception is thrown.
If the source data contains duplicate rows (specifically those columns used in the
If the source data contains duplicate rows (specifically those columns used in the
row matching ON clause), then an exception is thrown to prevent two updates applying
row matching ON clause), then an exception is thrown to prevent two updates applying
to the same target row. The embedded update, delete or insert statements can not re-specify
to the same target row.
the target table name.
WHEN MATCHED THEN or WHEN NOT MATCHED THEN clauses or both of them in any order should be specified.
If WHEN MATCHED THEN is specified it should contain UPDATE or DELETE clauses of both of them.
If statement doesn't need a source table a DUAL table can be substituted.
","
","
MERGE INTO TARGET_TABLE AS T USING SOURCE_TABLE AS S
MERGE INTO TARGET_TABLE AS T USING SOURCE_TABLE AS S
ON (T.ID = S.ID)
ON (T.ID = S.ID)
...
@@ -154,6 +151,9 @@ MERGE INTO TARGET_TABLE AS T USING (SELECT * FROM SOURCE_TABLE) AS S
...
@@ -154,6 +151,9 @@ MERGE INTO TARGET_TABLE AS T USING (SELECT * FROM SOURCE_TABLE) AS S
DELETE WHERE T.COL2='FINAL'
DELETE WHERE T.COL2='FINAL'
WHEN NOT MATCHED THEN
WHEN NOT MATCHED THEN
INSERT (ID,COL1,COL2) VALUES(S.ID,S.COL1,S.COL2)
INSERT (ID,COL1,COL2) VALUES(S.ID,S.COL1,S.COL2)
MERGE INTO TARGET_TABLE USING DUAL ON (ID = 1)
WHEN NOT MATCHED THEN INSERT (ID, NAME) VALUES (1, 'Test')
WHEN MATCHED THEN UPDATE SET NAME = 'Test'
"
"
"Commands (DML)","RUNSCRIPT","
"Commands (DML)","RUNSCRIPT","
...
@@ -2252,6 +2252,14 @@ SELECT CAST(0 AS DOUBLE)
...
@@ -2252,6 +2252,14 @@ SELECT CAST(0 AS DOUBLE)
SELECT -1.4e-10
SELECT -1.4e-10
"
"
"Other Grammar","Delete search condition","
[ WHERE expression ] [ LIMIT term ]
","
Search condition for DELETE statement.
","
WHERE ID = 2
"
"Other Grammar","Digit","
"Other Grammar","Digit","
0-9
0-9
","
","
...
@@ -2313,6 +2321,17 @@ the column in the same way.
...
@@ -2313,6 +2321,17 @@ the column in the same way.
NAME
NAME
"
"
"Other Grammar","Insert columns and source","
{ [ ( columnName [,...] ) ]
{ VALUES { ( { DEFAULT | expression } [,...] ) } [,...]
| [ DIRECT ] [ SORTED ] select } } |
{ SET { columnName = { DEFAULT | expression } } [,...] }
","
Names of columns and their values for INSERT statement.
","
(ID, NAME) VALUES (1, 'Test')
"
"Other Grammar","Int","
"Other Grammar","Int","
[ + | - ] number
[ + | - ] number
","
","
...
@@ -2438,6 +2457,15 @@ An expression in a SELECT statement.
...
@@ -2438,6 +2457,15 @@ An expression in a SELECT statement.
ID AS VALUE
ID AS VALUE
"
"
"Other Grammar","Set clause list","
{ { columnName = { DEFAULT | expression } } [,...] } |
{ ( columnName [,...] ) = ( select ) }
","
List of SET clauses.
","
NAME = 'Test', VALUE = 2
"
"Other Grammar","String","
"Other Grammar","String","
'anythingExceptSingleQuote'
'anythingExceptSingleQuote'
","
","
...
...
h2/src/main/org/h2/command/Command.java
浏览文件 @
47ff9145
...
@@ -46,8 +46,8 @@ public abstract class Command implements CommandInterface {
...
@@ -46,8 +46,8 @@ public abstract class Command implements CommandInterface {
private
boolean
canReuse
;
private
boolean
canReuse
;
Command
(
Parser
parser
,
String
sql
)
{
Command
(
Session
session
,
String
sql
)
{
this
.
session
=
parser
.
getSession
()
;
this
.
session
=
session
;
this
.
sql
=
sql
;
this
.
sql
=
sql
;
trace
=
session
.
getDatabase
().
getTrace
(
Trace
.
COMMAND
);
trace
=
session
.
getDatabase
().
getTrace
(
Trace
.
COMMAND
);
}
}
...
...
h2/src/main/org/h2/command/CommandContainer.java
浏览文件 @
47ff9145
...
@@ -9,6 +9,7 @@ import java.util.ArrayList;
...
@@ -9,6 +9,7 @@ import java.util.ArrayList;
import
org.h2.api.DatabaseEventListener
;
import
org.h2.api.DatabaseEventListener
;
import
org.h2.command.dml.Explain
;
import
org.h2.command.dml.Explain
;
import
org.h2.command.dml.Query
;
import
org.h2.command.dml.Query
;
import
org.h2.engine.Session
;
import
org.h2.expression.Parameter
;
import
org.h2.expression.Parameter
;
import
org.h2.expression.ParameterInterface
;
import
org.h2.expression.ParameterInterface
;
import
org.h2.result.ResultInterface
;
import
org.h2.result.ResultInterface
;
...
@@ -26,8 +27,8 @@ public class CommandContainer extends Command {
...
@@ -26,8 +27,8 @@ public class CommandContainer extends Command {
private
boolean
readOnlyKnown
;
private
boolean
readOnlyKnown
;
private
boolean
readOnly
;
private
boolean
readOnly
;
CommandContainer
(
Parser
parser
,
String
sql
,
Prepared
prepared
)
{
CommandContainer
(
Session
session
,
String
sql
,
Prepared
prepared
)
{
super
(
parser
,
sql
);
super
(
session
,
sql
);
prepared
.
setCommand
(
this
);
prepared
.
setCommand
(
this
);
this
.
prepared
=
prepared
;
this
.
prepared
=
prepared
;
}
}
...
...
h2/src/main/org/h2/command/CommandList.java
浏览文件 @
47ff9145
...
@@ -6,6 +6,8 @@
...
@@ -6,6 +6,8 @@
package
org
.
h2
.
command
;
package
org
.
h2
.
command
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
org.h2.engine.Session
;
import
org.h2.expression.ParameterInterface
;
import
org.h2.expression.ParameterInterface
;
import
org.h2.result.ResultInterface
;
import
org.h2.result.ResultInterface
;
...
@@ -17,8 +19,8 @@ class CommandList extends Command {
...
@@ -17,8 +19,8 @@ class CommandList extends Command {
private
final
Command
command
;
private
final
Command
command
;
private
final
String
remaining
;
private
final
String
remaining
;
CommandList
(
Parser
parser
,
String
sql
,
Command
c
,
String
remaining
)
{
CommandList
(
Session
session
,
String
sql
,
Command
c
,
String
remaining
)
{
super
(
parser
,
sql
);
super
(
session
,
sql
);
this
.
command
=
c
;
this
.
command
=
c
;
this
.
remaining
=
remaining
;
this
.
remaining
=
remaining
;
}
}
...
...
h2/src/main/org/h2/command/Parser.java
浏览文件 @
47ff9145
差异被折叠。
点击展开。
h2/src/main/org/h2/command/dml/MergeUsing.java
浏览文件 @
47ff9145
...
@@ -390,31 +390,21 @@ public class MergeUsing extends Prepared {
...
@@ -390,31 +390,21 @@ public class MergeUsing extends Prepared {
query
.
prepare
();
query
.
prepare
();
}
}
int
embeddedStatementsCount
=
0
;
// Prepare each of the sub-commands ready to aid in the MERGE
// Prepare each of the sub-commands ready to aid in the MERGE
// collaboration
// collaboration
if
(
updateCommand
!=
null
)
{
if
(
updateCommand
!=
null
)
{
updateCommand
.
setSourceTableFilter
(
sourceTableFilter
);
updateCommand
.
setSourceTableFilter
(
sourceTableFilter
);
updateCommand
.
setCondition
(
appendOnCondition
(
updateCommand
));
updateCommand
.
setCondition
(
appendOnCondition
(
updateCommand
));
updateCommand
.
prepare
();
updateCommand
.
prepare
();
embeddedStatementsCount
++;
}
}
if
(
deleteCommand
!=
null
)
{
if
(
deleteCommand
!=
null
)
{
deleteCommand
.
setSourceTableFilter
(
sourceTableFilter
);
deleteCommand
.
setSourceTableFilter
(
sourceTableFilter
);
deleteCommand
.
setCondition
(
appendOnCondition
(
deleteCommand
));
deleteCommand
.
setCondition
(
appendOnCondition
(
deleteCommand
));
deleteCommand
.
prepare
();
deleteCommand
.
prepare
();
embeddedStatementsCount
++;
}
}
if
(
insertCommand
!=
null
)
{
if
(
insertCommand
!=
null
)
{
insertCommand
.
setSourceTableFilter
(
sourceTableFilter
);
insertCommand
.
setSourceTableFilter
(
sourceTableFilter
);
insertCommand
.
prepare
();
insertCommand
.
prepare
();
embeddedStatementsCount
++;
}
if
(
embeddedStatementsCount
==
0
)
{
throw
DbException
.
get
(
ErrorCode
.
SYNTAX_ERROR_1
,
"At least UPDATE, DELETE or INSERT embedded statement must be supplied."
);
}
}
// setup the targetMatchQuery - for detecting if the target row exists
// setup the targetMatchQuery - for detecting if the target row exists
...
...
h2/src/test/org/h2/test/db/TestMergeUsing.java
浏览文件 @
47ff9145
...
@@ -161,7 +161,7 @@ public class TestMergeUsing extends TestBase implements Trigger {
...
@@ -161,7 +161,7 @@ public class TestMergeUsing extends TestBase implements Trigger {
GATHER_ORDERED_RESULTS_SQL
,
GATHER_ORDERED_RESULTS_SQL
,
"SELECT X AS ID, 'Marcy'||X AS NAME FROM SYSTEM_RANGE(1,3) WHERE X<0"
,
"SELECT X AS ID, 'Marcy'||X AS NAME FROM SYSTEM_RANGE(1,3) WHERE X<0"
,
0
,
0
,
"
At least UPDATE, DELETE or INSERT embedded statement must be supplied.
"
);
"
expected \"WHEN\"
"
);
// Two updates to same row - update and delete together - emptying the
// Two updates to same row - update and delete together - emptying the
// parent table
// parent table
testMergeUsing
(
testMergeUsing
(
...
...
h2/src/test/org/h2/test/scripts/dml/mergeUsing.sql
浏览文件 @
47ff9145
...
@@ -149,3 +149,29 @@ SELECT * FROM TEST ORDER BY C1, C2;
...
@@ -149,3 +149,29 @@ 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
MATCHED
THEN
UPDATE
SET
VALUE
=
1
WHEN
NOT
MATCHED
THEN
;
>
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
MERGE
INTO
TEST
USING
DUAL
ON
(
ID
=
1
)
WHEN
NOT
MATCHED
THEN
INSERT
(
ID
,
VALUE
)
VALUES
(
1
,
1
)
WHEN
MATCHED
THEN
;
>
exception
SYNTAX_ERROR_2
DROP
TABLE
TEST
;
>
ok
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论