Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
75f5b528
提交
75f5b528
authored
12月 05, 2017
作者:
Owner
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added with.sql ad mergeUsing.sql test cases
上级
a0fd76d8
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
111 行增加
和
43 行删除
+111
-43
TestGeneralCommonTableQueries.java
...rc/test/org/h2/test/db/TestGeneralCommonTableQueries.java
+20
-0
TestScript.java
h2/src/test/org/h2/test/scripts/TestScript.java
+3
-0
mergeUsing.sql
h2/src/test/org/h2/test/scripts/dml/mergeUsing.sql
+33
-0
with.sql
h2/src/test/org/h2/test/scripts/dml/with.sql
+55
-0
testScript.sql
h2/src/test/org/h2/test/scripts/testScript.sql
+0
-43
没有找到文件。
h2/src/test/org/h2/test/db/TestGeneralCommonTableQueries.java
浏览文件 @
75f5b528
...
...
@@ -42,6 +42,7 @@ public class TestGeneralCommonTableQueries extends AbstractBaseForCommonTableExp
testCreateTable
();
testNestedSQL
();
testSimple4RowRecursiveQuery
();
testSimple2By4RowRecursiveQuery
();
}
private
void
testSimpleSelect
()
throws
Exception
{
...
...
@@ -489,5 +490,24 @@ public class TestGeneralCommonTableQueries extends AbstractBaseForCommonTableExp
WITH_QUERY
,
maxRetries
-
1
,
expectedColumnTypes
);
}
private
void
testSimple2By4RowRecursiveQuery
()
throws
Exception
{
String
[]
expectedRowData
=
new
String
[]{
"|0|1|10"
,
"|1|2|11"
,
"|2|3|12"
,
"|3|4|13"
};
String
[]
expectedColumnTypes
=
new
String
[]{
"INTEGER"
,
"INTEGER"
,
"INTEGER"
};
String
[]
expectedColumnNames
=
new
String
[]{
"K"
,
"N"
,
"N2"
};
String
SETUP_SQL
=
"-- do nothing"
;
String
WITH_QUERY
=
"with \n"
+
"r1(n,k) as ((select 1, 0) union all (select n+1,k+1 from r1 where n <= 3)),"
+
"r2(n,k) as ((select 10,0) union all (select n+1,k+1 from r2 where n <= 13))"
+
"select r1.k, r1.n, r2.n AS n2 from r1 inner join r2 ON r1.k= r2.k "
;
int
maxRetries
=
3
;
int
expectedNumberOfRows
=
expectedRowData
.
length
;
testRepeatedQueryWithSetup
(
maxRetries
,
expectedRowData
,
expectedColumnNames
,
expectedNumberOfRows
,
SETUP_SQL
,
WITH_QUERY
,
maxRetries
-
1
,
expectedColumnTypes
);
}
}
h2/src/test/org/h2/test/scripts/TestScript.java
浏览文件 @
75f5b528
...
...
@@ -133,6 +133,9 @@ public class TestScript extends TestBase {
"parsedatetime"
,
"quarter"
,
"second"
,
"week"
,
"year"
})
{
testScript
(
"functions/timeanddate/"
+
s
+
".sql"
);
}
for
(
String
s
:
new
String
[]
{
"with"
,
"mergeUsing"
})
{
testScript
(
"dml/"
+
s
+
".sql"
);
}
deleteDb
(
"script"
);
System
.
out
.
flush
();
}
...
...
h2/src/test/org/h2/test/scripts/dml/mergeUsing.sql
0 → 100755
浏览文件 @
75f5b528
-- Copyright 2004-2014 H2 Group. Multiple-Licensed under the MPL 2.0,
-- and the EPL 1.0 (http://h2database.com/html/license.html).
-- Initial Developer: H2 Group
--
CREATE
TABLE
PARENT
(
ID
INT
,
NAME
VARCHAR
,
PRIMARY
KEY
(
ID
)
);
>
ok
MERGE
INTO
PARENT
AS
P
USING
(
SELECT
X
AS
ID
,
'Coco'
||
X
AS
NAME
FROM
SYSTEM_RANGE
(
1
,
2
)
)
AS
S
ON
(
P
.
ID
=
S
.
ID
AND
1
=
1
AND
S
.
ID
=
P
.
ID
)
WHEN
MATCHED
THEN
UPDATE
SET
P
.
NAME
=
S
.
NAME
WHERE
2
=
2
WHEN
NOT
MATCHED
THEN
INSERT
(
ID
,
NAME
)
VALUES
(
S
.
ID
,
S
.
NAME
);
>
update
count
:
2
SELECT
*
FROM
PARENT
;
>
ID
NAME
>
-- -----
>
1
Coco1
>
2
Coco2
EXPLAIN
PLAN
MERGE
INTO
PARENT
AS
P
USING
(
SELECT
X
AS
ID
,
'Coco'
||
X
AS
NAME
FROM
SYSTEM_RANGE
(
1
,
2
)
)
AS
S
ON
(
P
.
ID
=
S
.
ID
AND
1
=
1
AND
S
.
ID
=
P
.
ID
)
WHEN
MATCHED
THEN
UPDATE
SET
P
.
NAME
=
S
.
NAME
WHERE
2
=
2
WHEN
NOT
MATCHED
THEN
INSERT
(
ID
,
NAME
)
VALUES
(
S
.
ID
,
S
.
NAME
);
>
PLAN
>
---------------------------------------------------------------------------------------------------------------------------------
>
MERGE
INTO
PUBLIC
.
PARENT
(
ID
,
NAME
)
KEY
(
ID
)
SELECT
X
AS
ID
,
(
'Coco'
||
X
)
AS
NAME
FROM
SYSTEM_RANGE
(
1
,
2
)
/* PUBLIC.RANGE_INDEX */
\ No newline at end of file
h2/src/test/org/h2/test/scripts/dml/with.sql
0 → 100755
浏览文件 @
75f5b528
-- Copyright 2004-2014 H2 Group. Multiple-Licensed under the MPL 2.0,
-- and the EPL 1.0 (http://h2database.com/html/license.html).
-- Initial Developer: H2 Group
--
explain
with
recursive
r
(
n
)
as
(
(
select
1
)
union
all
(
select
n
+
1
from
r
where
n
<
3
)
)
select
n
from
r
;
>
PLAN
>
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
WITH
RECURSIVE
R
(
N
)
AS
(
(
SELECT
1
FROM
SYSTEM_RANGE
(
1
,
1
)
/* PUBLIC.RANGE_INDEX */
)
UNION
ALL
(
SELECT
(
N
+
1
)
FROM
PUBLIC
.
R
/* PUBLIC.R.tableScan */
WHERE
N
<
3
)
)
SELECT
N
FROM
R
R
/* null */
>
rows
:
1
select
sum
(
n
)
from
(
with
recursive
r
(
n
)
as
(
(
select
1
)
union
all
(
select
n
+
1
from
r
where
n
<
3
)
)
select
n
from
r
);
>
SUM
(
N
)
>
------
>
6
>
rows
:
1
select
sum
(
n
)
from
(
select
0
)
join
(
with
recursive
r
(
n
)
as
(
(
select
1
)
union
all
(
select
n
+
1
from
r
where
n
<
3
)
)
select
n
from
r
)
on
1
=
1
;
>
SUM
(
N
)
>
------
>
6
>
rows
:
1
select
0
from
(
select
0
where
0
in
(
with
recursive
r
(
n
)
as
(
(
select
1
)
union
all
(
select
n
+
1
from
r
where
n
<
3
)
)
select
n
from
r
)
);
>
0
>
-
>
rows
:
0
with
r0
(
n
,
k
)
as
(
select
-
1
,
0
),
r1
(
n
,
k
)
as
((
select
1
,
0
)
union
all
(
select
n
+
1
,
k
+
1
from
r1
where
n
<=
3
)),
r2
(
n
,
k
)
as
((
select
10
,
0
)
union
all
(
select
n
+
1
,
k
+
1
from
r2
where
n
<=
13
))
select
r1
.
k
,
r0
.
n
as
N0
,
r1
.
n
AS
N1
,
r2
.
n
AS
n2
from
r0
inner
join
r1
ON
r1
.
k
=
r0
.
k
inner
join
r2
ON
r1
.
k
=
r2
.
k
;
>
K
N0
N1
N2
>
-
-- -- --
>
0
-
1
1
10
>
rows
:
1
\ No newline at end of file
h2/src/test/org/h2/test/scripts/testScript.sql
浏览文件 @
75f5b528
...
...
@@ -9398,49 +9398,6 @@ select 0 from ((
}
;
>
update
count
:
0
explain
with
recursive
r
(
n
)
as
(
(
select
1
)
union
all
(
select
n
+
1
from
r
where
n
<
3
)
)
select
n
from
r
;
>
PLAN
>
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
WITH
RECURSIVE
R
(
N
)
AS
(
(
SELECT
1
FROM
SYSTEM_RANGE
(
1
,
1
)
/* PUBLIC.RANGE_INDEX */
)
UNION
ALL
(
SELECT
(
N
+
1
)
FROM
PUBLIC
.
R
/* PUBLIC.R.tableScan */
WHERE
N
<
3
)
)
SELECT
N
FROM
R
R
/* null */
>
rows
:
1
select
sum
(
n
)
from
(
with
recursive
r
(
n
)
as
(
(
select
1
)
union
all
(
select
n
+
1
from
r
where
n
<
3
)
)
select
n
from
r
);
>
SUM
(
N
)
>
------
>
6
>
rows
:
1
select
sum
(
n
)
from
(
select
0
)
join
(
with
recursive
r
(
n
)
as
(
(
select
1
)
union
all
(
select
n
+
1
from
r
where
n
<
3
)
)
select
n
from
r
)
on
1
=
1
;
>
SUM
(
N
)
>
------
>
6
>
rows
:
1
select
0
from
(
select
0
where
0
in
(
with
recursive
r
(
n
)
as
(
(
select
1
)
union
all
(
select
n
+
1
from
r
where
n
<
3
)
)
select
n
from
r
)
);
>
0
>
-
>
rows
:
0
create
table
x
(
id
int
not
null
);
>
ok
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论