Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
78bf5f04
提交
78bf5f04
authored
7 年前
作者:
Owner
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Clean up code style, add tests for DROP ALL OBJECTS with CTEs
上级
f0efc5d3
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
115 行增加
和
4 行删除
+115
-4
TestGeneralCommonTableQueries.java
...rc/test/org/h2/test/db/TestGeneralCommonTableQueries.java
+25
-1
TestMergeUsing.java
h2/src/test/org/h2/test/db/TestMergeUsing.java
+3
-3
TestPersistentCommonTableExpressions.java
.../org/h2/test/db/TestPersistentCommonTableExpressions.java
+87
-0
没有找到文件。
h2/src/test/org/h2/test/db/TestGeneralCommonTableQueries.java
浏览文件 @
78bf5f04
...
...
@@ -45,6 +45,7 @@ public class TestGeneralCommonTableQueries extends AbstractBaseForCommonTableExp
testSimple4RowRecursiveQuery
();
testSimple2By4RowRecursiveQuery
();
testSimple3RowRecursiveQueryWithLazyEval
();
testSimple3RowRecursiveQueryDropAllObjects
();
}
private
void
testSimpleSelect
()
throws
Exception
{
...
...
@@ -552,6 +553,29 @@ public class TestGeneralCommonTableQueries extends AbstractBaseForCommonTableExp
}
finally
{
config
=
backupConfig
;
}
}
private
void
testSimple3RowRecursiveQueryDropAllObjects
()
throws
Exception
{
String
[]
expectedRowData
=
new
String
[]{
"|6"
};
String
[]
expectedColumnTypes
=
new
String
[]{
"BIGINT"
};
String
[]
expectedColumnNames
=
new
String
[]{
"SUM(N)"
};
String
setupSQL
=
"DROP ALL OBJECTS;"
;
String
withQuery
=
"select sum(n) from ("
+
" with recursive r(n) as ("
+
" (select 1) union all (select n+1 from r where n < 3)"
+
" ),"
+
" dummyUnsedCte(n) as ("
+
" select 1 "
+
" )"
+
" select n from r"
+
")"
;
int
maxRetries
=
10
;
int
expectedNumberOfRows
=
expectedRowData
.
length
;
testRepeatedQueryWithSetup
(
maxRetries
,
expectedRowData
,
expectedColumnNames
,
expectedNumberOfRows
,
setupSQL
,
withQuery
,
maxRetries
-
1
,
expectedColumnTypes
);
}
}
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/db/TestMergeUsing.java
浏览文件 @
78bf5f04
...
...
@@ -19,7 +19,9 @@ import org.h2.test.TestBase;
public
class
TestMergeUsing
extends
TestBase
implements
Trigger
{
private
static
final
String
GATHER_ORDERED_RESULTS_SQL
=
"SELECT ID, NAME FROM PARENT ORDER BY ID ASC"
;
private
static
int
triggerTestingUpdateCount
=
0
;
private
static
int
triggerTestingUpdateCount
;
private
String
triggerName
;
/**
* Run just this test.
...
...
@@ -30,8 +32,6 @@ public class TestMergeUsing extends TestBase implements Trigger {
TestBase
.
createCaller
().
init
().
test
();
}
private
String
triggerName
;
@Override
public
void
test
()
throws
Exception
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/db/TestPersistentCommonTableExpressions.java
浏览文件 @
78bf5f04
...
...
@@ -27,6 +27,8 @@ public class TestPersistentCommonTableExpressions extends AbstractBaseForCommonT
testRecursiveTable
();
testPersistentNonRecursiveTableInCreateView
();
testPersistentRecursiveTableInCreateView
();
testPersistentNonRecursiveTableInCreateViewDropAllObjects
();
testPersistentRecursiveTableInCreateViewDropAllObjects
();
}
private
void
testRecursiveTable
()
throws
Exception
{
...
...
@@ -179,4 +181,89 @@ public class TestPersistentCommonTableExpressions extends AbstractBaseForCommonT
testRepeatedQueryWithSetup
(
maxRetries
,
expectedRowData
,
expectedColumnNames
,
expectedNumberOfRows
,
setupSQL
,
withQuery
,
maxRetries
-
1
,
expectedColumnTypes
);
}
private
void
testPersistentNonRecursiveTableInCreateViewDropAllObjects
()
throws
Exception
{
String
setupSQL
=
""
+
"DROP ALL OBJECTS; \n"
+
"CREATE TABLE my_table ( \n"
+
" id INTEGER, \n"
+
" parent_fk INTEGER \n"
+
"); \n"
+
" \n"
+
"INSERT INTO my_table ( id, parent_fk) VALUES ( 1, NULL ); \n"
+
"INSERT INTO my_table ( id, parent_fk) VALUES ( 11, 1 ); \n"
+
"INSERT INTO my_table ( id, parent_fk) VALUES ( 111, 11 ); \n"
+
"INSERT INTO my_table ( id, parent_fk) VALUES ( 12, 1 ); \n"
+
"INSERT INTO my_table ( id, parent_fk) VALUES ( 121, 12 ); \n"
+
" \n"
+
"CREATE OR REPLACE VIEW v_my_nr_tree AS \n"
+
"WITH tree_cte_nr (sub_tree_root_id, tree_level, parent_fk, child_fk) AS ( \n"
+
" SELECT mt.ID AS sub_tree_root_id, CAST(0 AS INT) AS tree_level, mt.parent_fk, mt.id \n"
+
" FROM my_table mt \n"
+
"), \n"
+
"unused_cte AS ( SELECT 1 AS unUsedColumn ) \n"
+
"SELECT sub_tree_root_id, tree_level, parent_fk, child_fk FROM tree_cte_nr; \n"
;
String
withQuery
=
"SELECT * FROM v_my_nr_tree"
;
int
maxRetries
=
6
;
String
[]
expectedRowData
=
new
String
[]{
"|1|0|null|1"
,
"|11|0|1|11"
,
"|111|0|11|111"
,
"|12|0|1|12"
,
"|121|0|12|121"
,
};
String
[]
expectedColumnNames
=
new
String
[]{
"SUB_TREE_ROOT_ID"
,
"TREE_LEVEL"
,
"PARENT_FK"
,
"CHILD_FK"
};
String
[]
expectedColumnTypes
=
new
String
[]{
"INTEGER"
,
"INTEGER"
,
"INTEGER"
,
"INTEGER"
};
int
expectedNumberOfRows
=
5
;
testRepeatedQueryWithSetup
(
maxRetries
,
expectedRowData
,
expectedColumnNames
,
expectedNumberOfRows
,
setupSQL
,
withQuery
,
maxRetries
-
1
,
expectedColumnTypes
);
}
private
void
testPersistentRecursiveTableInCreateViewDropAllObjects
()
throws
Exception
{
String
setuoSQL
=
"--SET TRACE_LEVEL_SYSTEM_OUT 3;\n"
+
"DROP ALL OBJECTS; \n"
+
"CREATE TABLE my_tree ( \n"
+
" id INTEGER, \n"
+
" parent_fk INTEGER \n"
+
"); \n"
+
" \n"
+
"INSERT INTO my_tree ( id, parent_fk) VALUES ( 1, NULL ); \n"
+
"INSERT INTO my_tree ( id, parent_fk) VALUES ( 11, 1 ); \n"
+
"INSERT INTO my_tree ( id, parent_fk) VALUES ( 111, 11 ); \n"
+
"INSERT INTO my_tree ( id, parent_fk) VALUES ( 12, 1 ); \n"
+
"INSERT INTO my_tree ( id, parent_fk) VALUES ( 121, 12 ); \n"
+
" \n"
+
"CREATE OR REPLACE VIEW v_my_tree AS \n"
+
"WITH RECURSIVE tree_cte (sub_tree_root_id, tree_level, parent_fk, child_fk) AS ( \n"
+
" SELECT mt.ID AS sub_tree_root_id, CAST(0 AS INT) AS tree_level, mt.parent_fk, mt.id \n"
+
" FROM my_tree mt \n"
+
" UNION ALL \n"
+
" SELECT sub_tree_root_id, mtc.tree_level + 1 AS tree_level, mtc.parent_fk, mt.id \n"
+
" FROM my_tree mt \n"
+
"INNER JOIN tree_cte mtc ON mtc.child_fk = mt.parent_fk \n"
+
"), \n"
+
"unused_cte AS ( SELECT 1 AS unUsedColumn ) \n"
+
"SELECT sub_tree_root_id, tree_level, parent_fk, child_fk FROM tree_cte; \n"
;
String
withQuery
=
"SELECT * FROM v_my_tree"
;
int
maxRetries
=
4
;
String
[]
expectedRowData
=
new
String
[]{
"|1|0|null|1"
,
"|11|0|1|11"
,
"|111|0|11|111"
,
"|12|0|1|12"
,
"|121|0|12|121"
,
"|1|1|null|11"
,
"|11|1|1|111"
,
"|1|1|null|12"
,
"|12|1|1|121"
,
"|1|2|null|111"
,
"|1|2|null|121"
};
String
[]
expectedColumnNames
=
new
String
[]{
"SUB_TREE_ROOT_ID"
,
"TREE_LEVEL"
,
"PARENT_FK"
,
"CHILD_FK"
};
String
[]
expectedColumnTypes
=
new
String
[]{
"INTEGER"
,
"INTEGER"
,
"INTEGER"
,
"INTEGER"
};
int
expectedNumberOfRows
=
11
;
testRepeatedQueryWithSetup
(
maxRetries
,
expectedRowData
,
expectedColumnNames
,
expectedNumberOfRows
,
setuoSQL
,
withQuery
,
maxRetries
-
1
,
expectedColumnTypes
);
}
}
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论