Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
f974e8b5
提交
f974e8b5
authored
6月 08, 2017
作者:
thomasmueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Formatting, javadocs
上级
de02c023
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
72 行增加
和
67 行删除
+72
-67
help.csv
h2/src/docsrc/help/help.csv
+2
-3
help.csv
h2/src/main/org/h2/res/help.csv
+1
-1
RangeTable.java
h2/src/main/org/h2/table/RangeTable.java
+1
-1
TableView.java
h2/src/main/org/h2/table/TableView.java
+4
-1
TestGeneralCommonTableQueries.java
...rc/test/org/h2/test/db/TestGeneralCommonTableQueries.java
+63
-61
dictionary.txt
h2/src/tools/org/h2/build/doc/dictionary.txt
+1
-0
没有找到文件。
h2/src/docsrc/help/help.csv
浏览文件 @
f974e8b5
...
...
@@ -197,7 +197,7 @@ WITH [ RECURSIVE ] { name [( columnName [,...] )]
AS ( select ) [,...] }
select
","
Can be used to create a recursive or non-recursive query (common table expression).
Can be used to create a recursive or non-recursive query (common table expression).
For recursive queries the first select has to be a UNION.
One or more common table entries can be referred to by name.
Column name declarations are now optional - the column names will be inferred from the named select queries.
...
...
@@ -213,8 +213,7 @@ SELECT sum(n) FROM t;
","
WITH t1 AS (
SELECT 1 AS FIRST_COLUMN
),
t2 AS (
), t2 AS (
SELECT FIRST_COLUMN+1 AS FIRST_COLUMN FROM t1
)
SELECT sum(FIRST_COLUMN) FROM t2;
...
...
h2/src/main/org/h2/res/help.csv
浏览文件 @
f974e8b5
...
...
@@ -71,7 +71,7 @@ WITH [ RECURSIVE ] { name [( columnName [,...] )]
AS ( select ) [,...] }
select
","
Can be used to create a recursive
query
."
Can be used to create a recursive
or non-recursive query (common table expression)
."
"Commands (DDL)","ALTER INDEX RENAME","
ALTER INDEX [ IF EXISTS ] indexName RENAME TO newIndexName
","
...
...
h2/src/main/org/h2/table/RangeTable.java
浏览文件 @
f974e8b5
...
...
@@ -144,7 +144,7 @@ public class RangeTable extends Table {
@Override
public
TableType
getTableType
()
{
return
TableType
.
SYSTEM_TABLE
;
return
TableType
.
SYSTEM_TABLE
;
}
@Override
...
...
h2/src/main/org/h2/table/TableView.java
浏览文件 @
f974e8b5
...
...
@@ -207,7 +207,8 @@ public class TableView extends Table {
// If it can't be compiled, then it's a 'zero column table'
// this avoids problems when creating the view when opening the
// database.
// If it can not be compiled - it could also be a recursive common table expression query.
// If it can not be compiled - it could also be a recursive common
// table expression query.
if
(
isRecursiveQueryExceptionDetected
(
createException
))
{
this
.
isRecursiveQueryDetected
=
true
;
}
...
...
@@ -673,6 +674,8 @@ public class TableView extends Table {
/**
* Was query recursion detected during compiling.
*
* @return true if yes
*/
public
boolean
isRecursiveQueryDetected
()
{
return
isRecursiveQueryDetected
;
...
...
h2/src/test/org/h2/test/db/TestGeneralCommonTableQueries.java
浏览文件 @
f974e8b5
...
...
@@ -16,7 +16,7 @@ import org.h2.test.TestBase;
*/
public
class
TestGeneralCommonTableQueries
extends
TestBase
{
/**
/**
* Run just this test.
*
* @param a ignored
...
...
@@ -45,14 +45,14 @@ public class TestGeneralCommonTableQueries extends TestBase {
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"
;
"select * from t1 union all select * from t2"
;
rs
=
stat
.
executeQuery
(
simple_two_column_query
);
assertTrue
(
rs
.
next
());
assertEquals
(
1
,
rs
.
getInt
(
1
));
assertTrue
(
rs
.
next
());
assertEquals
(
2
,
rs
.
getInt
(
1
));
assertFalse
(
rs
.
next
());
prep
=
conn
.
prepareStatement
(
simple_two_column_query
);
rs
=
prep
.
executeQuery
();
assertTrue
(
rs
.
next
());
...
...
@@ -60,7 +60,7 @@ public class TestGeneralCommonTableQueries extends TestBase {
assertTrue
(
rs
.
next
());
assertEquals
(
2
,
rs
.
getInt
(
1
));
assertFalse
(
rs
.
next
());
prep
=
conn
.
prepareStatement
(
"with "
+
"t1(n) as (select 2 as first) "
+
",t2(n) as (select 3 as first) "
+
...
...
@@ -72,7 +72,7 @@ public class TestGeneralCommonTableQueries extends TestBase {
assertTrue
(
rs
.
next
());
assertEquals
(
3
,
rs
.
getInt
(
1
));
assertFalse
(
rs
.
next
());
prep
=
conn
.
prepareStatement
(
"with "
+
"t1(n) as (select 2 as first) "
+
",t2(n) as (select 3 as first) "
+
...
...
@@ -85,7 +85,7 @@ public class TestGeneralCommonTableQueries extends TestBase {
assertTrue
(
rs
.
next
());
assertEquals
(
3
,
rs
.
getInt
(
1
));
assertFalse
(
rs
.
next
());
conn
.
close
();
deleteDb
(
"commonTableExpressionQueries"
);
}
...
...
@@ -95,7 +95,7 @@ public class TestGeneralCommonTableQueries extends TestBase {
Connection
conn
=
getConnection
(
"commonTableExpressionQueries"
);
PreparedStatement
prep
;
ResultSet
rs
;
prep
=
conn
.
prepareStatement
(
"with "
+
"t1 as (select 2 as first_col) "
+
",t2 as (select first_col+1 from t1) "
+
...
...
@@ -110,98 +110,100 @@ public class TestGeneralCommonTableQueries extends TestBase {
assertFalse
(
rs
.
next
());
assertEquals
(
rs
.
getMetaData
().
getColumnCount
(),
1
);
assertEquals
(
"FIRST_COL"
,
rs
.
getMetaData
().
getColumnLabel
(
1
));
conn
.
close
();
deleteDb
(
"commonTableExpressionQueries"
);
}
private
void
testChainedQuery
()
throws
Exception
{
deleteDb
(
"commonTableExpressionQueries"
);
Connection
conn
=
getConnection
(
"commonTableExpressionQueries"
);
PreparedStatement
prep
;
ResultSet
rs
;
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"
);
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
();
assertTrue
(
rs
.
next
());
assertEquals
(
2
,
rs
.
getInt
(
1
));
assertFalse
(
rs
.
next
());
conn
.
close
();
deleteDb
(
"commonTableExpressionQueries"
);
}
}
private
void
testParameterizedQuery
()
throws
Exception
{
deleteDb
(
"commonTableExpressionQueries"
);
Connection
conn
=
getConnection
(
"commonTableExpressionQueries"
);
PreparedStatement
prep
;
ResultSet
rs
;
prep
=
conn
.
prepareStatement
(
"WITH t1 AS ("
+
" SELECT X, 'T1' FROM SYSTEM_RANGE(?,?)"
+
"),"
+
"t2 AS ("
+
" SELECT X, 'T2' FROM SYSTEM_RANGE(?,?)"
+
") "
+
"SELECT * FROM t1 UNION ALL SELECT * FROM t2 UNION ALL SELECT X, 'Q' FROM SYSTEM_RANGE(?,?)"
);
prep
.
setInt
(
1
,
1
);
prep
.
setInt
(
2
,
2
);
prep
.
setInt
(
3
,
3
);
prep
.
setInt
(
4
,
4
);
prep
.
setInt
(
5
,
5
);
prep
.
setInt
(
6
,
6
);
prep
=
conn
.
prepareStatement
(
"WITH t1 AS ("
+
" SELECT X, 'T1' FROM SYSTEM_RANGE(?,?)"
+
"),"
+
"t2 AS ("
+
" SELECT X, 'T2' FROM SYSTEM_RANGE(?,?)"
+
") "
+
"SELECT * FROM t1 UNION ALL SELECT * FROM t2 "
+
"UNION ALL SELECT X, 'Q' FROM SYSTEM_RANGE(?,?)"
);
prep
.
setInt
(
1
,
1
);
prep
.
setInt
(
2
,
2
);
prep
.
setInt
(
3
,
3
);
prep
.
setInt
(
4
,
4
);
prep
.
setInt
(
5
,
5
);
prep
.
setInt
(
6
,
6
);
rs
=
prep
.
executeQuery
();
for
(
int
n:
new
int
[]{
1
,
2
,
3
,
4
,
5
,
6
}
){
assertTrue
(
rs
.
next
());
assertEquals
(
n
,
rs
.
getInt
(
1
));
assertTrue
(
rs
.
next
());
assertEquals
(
n
,
rs
.
getInt
(
1
));
}
assertFalse
(
rs
.
next
());
// call it twice
rs
=
prep
.
executeQuery
();
for
(
int
n:
new
int
[]{
1
,
2
,
3
,
4
,
5
,
6
}
){
assertTrue
(
rs
.
next
());
assertEquals
(
n
,
rs
.
getInt
(
1
));
assertTrue
(
rs
.
next
());
assertEquals
(
n
,
rs
.
getInt
(
1
));
}
assertFalse
(
rs
.
next
());
conn
.
close
();
deleteDb
(
"commonTableExpressionQueries"
);
}
private
void
testNumberedParameterizedQuery
()
throws
Exception
{
deleteDb
(
"commonTableExpressionQueries"
);
Connection
conn
=
getConnection
(
"commonTableExpressionQueries"
);
PreparedStatement
prep
;
ResultSet
rs
;
prep
=
conn
.
prepareStatement
(
"WITH t1 AS ("
+
" SELECT R.X, 'T1' FROM SYSTEM_RANGE(?1,?2) R"
+
"),"
+
"t2 AS ("
+
" SELECT R.X, 'T2' FROM SYSTEM_RANGE(?3,?4) R"
+
") "
+
"SELECT * FROM t1 UNION ALL SELECT * FROM t2 UNION ALL SELECT X, 'Q' FROM SYSTEM_RANGE(?5,?6)"
);
prep
.
setInt
(
1
,
1
);
prep
.
setInt
(
2
,
2
);
prep
.
setInt
(
3
,
3
);
prep
.
setInt
(
4
,
4
);
prep
.
setInt
(
5
,
5
);
prep
.
setInt
(
6
,
6
);
+
" SELECT R.X, 'T1' FROM SYSTEM_RANGE(?1,?2) R"
+
"),"
+
"t2 AS ("
+
" SELECT R.X, 'T2' FROM SYSTEM_RANGE(?3,?4) R"
+
") "
+
"SELECT * FROM t1 UNION ALL SELECT * FROM t2 UNION ALL SELECT X, 'Q' FROM SYSTEM_RANGE(?5,?6)"
);
prep
.
setInt
(
1
,
1
);
prep
.
setInt
(
2
,
2
);
prep
.
setInt
(
3
,
3
);
prep
.
setInt
(
4
,
4
);
prep
.
setInt
(
5
,
5
);
prep
.
setInt
(
6
,
6
);
rs
=
prep
.
executeQuery
();
for
(
int
n:
new
int
[]{
1
,
2
,
3
,
4
,
5
,
6
}
)
{
assertTrue
(
rs
.
next
());
assertEquals
(
n
,
rs
.
getInt
(
1
));
for
(
int
n
:
new
int
[]
{
1
,
2
,
3
,
4
,
5
,
6
})
{
assertTrue
(
rs
.
next
());
assertEquals
(
n
,
rs
.
getInt
(
1
));
}
assertEquals
(
"X"
,
rs
.
getMetaData
().
getColumnLabel
(
1
));
assertEquals
(
"'T1'"
,
rs
.
getMetaData
().
getColumnLabel
(
2
));
...
...
@@ -210,5 +212,5 @@ public class TestGeneralCommonTableQueries extends TestBase {
conn
.
close
();
deleteDb
(
"commonTableExpressionQueries"
);
}
}
}
h2/src/tools/org/h2/build/doc/dictionary.txt
浏览文件 @
f974e8b5
...
...
@@ -736,3 +736,4 @@ arbonaut exposing obscure determined turkey buildings indexhints acct
choosing optimise arte preparator katzyn bla jenkins tot artes pgserver npe
suffers closeablem mni significance vise identiy vitalus aka ilike uppercasing reentrant
aff ignite warm upstream producing sfu jit smtm affinity stashed tbl
stumc numbered
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论