Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
c4fb1dbf
提交
c4fb1dbf
authored
6月 04, 2017
作者:
Owner
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Issue#479 Refactored testCTE
上级
94e79df5
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
27 行增加
和
35 行删除
+27
-35
TestGeneralCommonTableQueries.java
...rc/test/org/h2/test/db/TestGeneralCommonTableQueries.java
+27
-35
没有找到文件。
h2/src/test/org/h2/test/db/TestGeneralCommonTableQueries.java
浏览文件 @
c4fb1dbf
...
@@ -16,35 +16,6 @@ import org.h2.test.TestBase;
...
@@ -16,35 +16,6 @@ import org.h2.test.TestBase;
*/
*/
public
class
TestGeneralCommonTableQueries
extends
TestBase
{
public
class
TestGeneralCommonTableQueries
extends
TestBase
{
private
static
final
String
SIMPLE_TWO_COMMON_QUERY
=
"with "
+
"t1(n) as (select 1 as first) "
+
",t2(n) as (select 2 as first) "
+
"select * from t1 union all select * from t2"
;
private
static
final
String
PARAMETERIZED_TWO_COMMON_QUERY
=
"with "
+
"t1(n) as (select 2 as first) "
+
",t2(n) as (select 3 as first) "
+
"select * from t1 union all select * from t2 where n<>?"
;
private
static
final
String
PARAMETERIZED_THREE_COMMON_QUERY
=
"with "
+
"t1(n) as (select 2 as first) "
+
",t2(n) as (select 3 as first) "
+
",t3(n) as (select 4 as first) "
+
"select * from t1 union all select * from t2 union all select * from t3 where n<>?"
;
private
static
final
String
PARAMETERIZED_THREE_COMMON_QUERY_IMPLIED_COLUMN_NAMES
=
"with "
+
"t1 as (select 2 as first_col) "
+
",t2 as (select first_col+1 from t1) "
+
",t3 as (select 4 as first_col) "
+
"select * from t1 union all select * from t2 union all select * from t3 where first_col<>?"
;
private
static
final
String
PARAMETERIZED_CHAINED_QUERY
=
" WITH t1 AS ("
+
" SELECT 1 AS FIRST_COLUMN"
+
"),"
+
" t2 AS ("
+
" SELECT FIRST_COLUMN+1 AS FIRST_COLUMN FROM t1 "
+
") "
+
"SELECT sum(FIRST_COLUMN) FROM t2"
;
/**
/**
* Run just this test.
* Run just this test.
*
*
...
@@ -69,14 +40,18 @@ public class TestGeneralCommonTableQueries extends TestBase {
...
@@ -69,14 +40,18 @@ public class TestGeneralCommonTableQueries extends TestBase {
ResultSet
rs
;
ResultSet
rs
;
stat
=
conn
.
createStatement
();
stat
=
conn
.
createStatement
();
rs
=
stat
.
executeQuery
(
SIMPLE_TWO_COMMON_QUERY
);
final
String
simple_two_column_query
=
"with "
+
"t1(n) as (select 1 as first) "
+
",t2(n) as (select 2 as first) "
+
"select * from t1 union all select * from t2"
;
rs
=
stat
.
executeQuery
(
simple_two_column_query
);
assertTrue
(
rs
.
next
());
assertTrue
(
rs
.
next
());
assertEquals
(
1
,
rs
.
getInt
(
1
));
assertEquals
(
1
,
rs
.
getInt
(
1
));
assertTrue
(
rs
.
next
());
assertTrue
(
rs
.
next
());
assertEquals
(
2
,
rs
.
getInt
(
1
));
assertEquals
(
2
,
rs
.
getInt
(
1
));
assertFalse
(
rs
.
next
());
assertFalse
(
rs
.
next
());
prep
=
conn
.
prepareStatement
(
SIMPLE_TWO_COMMON_QUERY
);
prep
=
conn
.
prepareStatement
(
simple_two_column_query
);
rs
=
prep
.
executeQuery
();
rs
=
prep
.
executeQuery
();
assertTrue
(
rs
.
next
());
assertTrue
(
rs
.
next
());
assertEquals
(
1
,
rs
.
getInt
(
1
));
assertEquals
(
1
,
rs
.
getInt
(
1
));
...
@@ -84,7 +59,10 @@ public class TestGeneralCommonTableQueries extends TestBase {
...
@@ -84,7 +59,10 @@ public class TestGeneralCommonTableQueries extends TestBase {
assertEquals
(
2
,
rs
.
getInt
(
1
));
assertEquals
(
2
,
rs
.
getInt
(
1
));
assertFalse
(
rs
.
next
());
assertFalse
(
rs
.
next
());
prep
=
conn
.
prepareStatement
(
PARAMETERIZED_TWO_COMMON_QUERY
);
prep
=
conn
.
prepareStatement
(
"with "
+
"t1(n) as (select 2 as first) "
+
",t2(n) as (select 3 as first) "
+
"select * from t1 union all select * from t2 where n<>?"
);
prep
.
setInt
(
1
,
0
);
// omit no lines since zero is not in list
prep
.
setInt
(
1
,
0
);
// omit no lines since zero is not in list
rs
=
prep
.
executeQuery
();
rs
=
prep
.
executeQuery
();
assertTrue
(
rs
.
next
());
assertTrue
(
rs
.
next
());
...
@@ -93,7 +71,11 @@ public class TestGeneralCommonTableQueries extends TestBase {
...
@@ -93,7 +71,11 @@ public class TestGeneralCommonTableQueries extends TestBase {
assertEquals
(
3
,
rs
.
getInt
(
1
));
assertEquals
(
3
,
rs
.
getInt
(
1
));
assertFalse
(
rs
.
next
());
assertFalse
(
rs
.
next
());
prep
=
conn
.
prepareStatement
(
PARAMETERIZED_THREE_COMMON_QUERY
);
prep
=
conn
.
prepareStatement
(
"with "
+
"t1(n) as (select 2 as first) "
+
",t2(n) as (select 3 as first) "
+
",t3(n) as (select 4 as first) "
+
"select * from t1 union all select * from t2 union all select * from t3 where n<>?"
);
prep
.
setInt
(
1
,
4
);
// omit 4 line (last)
prep
.
setInt
(
1
,
4
);
// omit 4 line (last)
rs
=
prep
.
executeQuery
();
rs
=
prep
.
executeQuery
();
assertTrue
(
rs
.
next
());
assertTrue
(
rs
.
next
());
...
@@ -112,7 +94,11 @@ public class TestGeneralCommonTableQueries extends TestBase {
...
@@ -112,7 +94,11 @@ public class TestGeneralCommonTableQueries extends TestBase {
PreparedStatement
prep
;
PreparedStatement
prep
;
ResultSet
rs
;
ResultSet
rs
;
prep
=
conn
.
prepareStatement
(
PARAMETERIZED_THREE_COMMON_QUERY_IMPLIED_COLUMN_NAMES
);
prep
=
conn
.
prepareStatement
(
"with "
+
"t1 as (select 2 as first_col) "
+
",t2 as (select first_col+1 from t1) "
+
",t3 as (select 4 as first_col) "
+
"select * from t1 union all select * from t2 union all select * from t3 where first_col<>?"
);
prep
.
setInt
(
1
,
4
);
// omit 4 line (last)
prep
.
setInt
(
1
,
4
);
// omit 4 line (last)
rs
=
prep
.
executeQuery
();
rs
=
prep
.
executeQuery
();
assertTrue
(
rs
.
next
());
assertTrue
(
rs
.
next
());
...
@@ -133,7 +119,13 @@ public class TestGeneralCommonTableQueries extends TestBase {
...
@@ -133,7 +119,13 @@ public class TestGeneralCommonTableQueries extends TestBase {
PreparedStatement
prep
;
PreparedStatement
prep
;
ResultSet
rs
;
ResultSet
rs
;
prep
=
conn
.
prepareStatement
(
PARAMETERIZED_CHAINED_QUERY
);
prep
=
conn
.
prepareStatement
(
" WITH t1 AS ("
+
" SELECT 1 AS FIRST_COLUMN"
+
"),"
+
" t2 AS ("
+
" SELECT FIRST_COLUMN+1 AS FIRST_COLUMN FROM t1 "
+
") "
+
"SELECT sum(FIRST_COLUMN) FROM t2"
);
rs
=
prep
.
executeQuery
();
rs
=
prep
.
executeQuery
();
assertTrue
(
rs
.
next
());
assertTrue
(
rs
.
next
());
assertEquals
(
2
,
rs
.
getInt
(
1
));
assertEquals
(
2
,
rs
.
getInt
(
1
));
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论