Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
68f0dfec
提交
68f0dfec
authored
7 年前
作者:
Owner
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added extra test case and help.csv syntax doc
上级
9146ede1
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
50 行增加
和
13 行删除
+50
-13
help.csv
h2/src/docsrc/help/help.csv
+16
-4
Parser.java
h2/src/main/org/h2/command/Parser.java
+7
-7
RecursiveQuery.java
h2/src/main/org/h2/command/dml/RecursiveQuery.java
+1
-1
TestGeneralCommonTableQueries.java
...rc/test/org/h2/test/db/TestGeneralCommonTableQueries.java
+26
-1
没有找到文件。
h2/src/docsrc/help/help.csv
浏览文件 @
68f0dfec
...
@@ -193,12 +193,16 @@ SHOW TABLES
...
@@ -193,12 +193,16 @@ SHOW TABLES
"
"
"Commands (DML)","WITH","
"Commands (DML)","WITH","
WITH [ RECURSIVE ]
name ( columnName [,...] )
WITH [ RECURSIVE ]
{ name [( columnName [,...] )]
AS ( select )
AS ( select )
[,...] }
select
select
","
","
Can be used to create a recursive query. The first select has to be a UNION.
Can be used to create a recursive query.
Currently only one result set can be referred to by name.
For recursive queries the first select has to be a UNION.
Non-recursive queries are also supported,
One or more common table entries can be use referred to by name.
Column name declarations are now optional - the column names will be gleaned from the named select queries.
Positional parameters are not currently correctly supported.
","
","
WITH RECURSIVE t(n) AS (
WITH RECURSIVE t(n) AS (
SELECT 1
SELECT 1
...
@@ -208,6 +212,14 @@ WITH RECURSIVE t(n) AS (
...
@@ -208,6 +212,14 @@ WITH RECURSIVE t(n) AS (
WHERE n < 100
WHERE n < 100
)
)
SELECT sum(n) FROM t;
SELECT sum(n) FROM t;
","
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;
"
"
"Commands (DDL)","ALTER INDEX RENAME","
"Commands (DDL)","ALTER INDEX RENAME","
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/command/Parser.java
浏览文件 @
68f0dfec
...
@@ -4907,9 +4907,9 @@ public class Parser {
...
@@ -4907,9 +4907,9 @@ public class Parser {
querySQL
=
StringUtils
.
cache
(
withQuery
.
getPlanSQL
());
querySQL
=
StringUtils
.
cache
(
withQuery
.
getPlanSQL
());
ArrayList
<
Expression
>
withExpressions
=
withQuery
.
getExpressions
();
ArrayList
<
Expression
>
withExpressions
=
withQuery
.
getExpressions
();
for
(
int
i
=
0
;
i
<
withExpressions
.
size
();
++
i
)
{
for
(
int
i
=
0
;
i
<
withExpressions
.
size
();
++
i
)
{
System
.
out
.
println
(
"columnName="
+
withExpressions
.
get
(
i
).
getColumnName
());
//
System.out.println("columnName="+withExpressions.get(i).getColumnName());
System
.
out
.
println
(
"alias="
+
withExpressions
.
get
(
i
).
getAlias
());
//
System.out.println("alias="+withExpressions.get(i).getAlias());
System
.
out
.
println
(
"nonAliasExpression="
+
withExpressions
.
get
(
i
).
getNonAliasExpression
());
//
System.out.println("nonAliasExpression="+withExpressions.get(i).getNonAliasExpression());
String
columnName
=
cols
!=
null
?
cols
[
i
]
:
withExpressions
.
get
(
i
).
getColumnName
();
String
columnName
=
cols
!=
null
?
cols
[
i
]
:
withExpressions
.
get
(
i
).
getColumnName
();
columnTemplateList
.
add
(
new
Column
(
columnName
,
withExpressions
.
get
(
i
).
getType
()));
columnTemplateList
.
add
(
new
Column
(
columnName
,
withExpressions
.
get
(
i
).
getType
()));
}
}
...
@@ -4918,10 +4918,10 @@ public class Parser {
...
@@ -4918,10 +4918,10 @@ public class Parser {
}
}
int
id
=
database
.
allocateObjectId
();
int
id
=
database
.
allocateObjectId
();
boolean
isRecursive
=
RecursiveQuery
.
isRecursive
(
tempViewName
,
querySQL
);
boolean
isRecursive
=
RecursiveQuery
.
isRecursive
(
tempViewName
,
querySQL
);
System
.
out
.
println
(
"tempViewName=>"
+
tempViewName
+
"<"
);
//
System.out.println("tempViewName=>"+tempViewName+"<");
System
.
out
.
println
(
"columnTemplateList="
+
columnTemplateList
.
stream
().
map
(
Column:
:
toStringWithType
).
collect
(
Collectors
.
toList
()));
//
System.out.println("columnTemplateList="+columnTemplateList.stream().map(Column::toStringWithType).collect(Collectors.toList()));
System
.
out
.
println
(
"isRecursive="
+
isRecursive
);
//
System.out.println("isRecursive="+isRecursive);
System
.
out
.
println
(
"querySQL="
+
querySQL
);
//
System.out.println("querySQL="+querySQL);
TableView
view
=
new
TableView
(
schema
,
id
,
tempViewName
,
querySQL
,
TableView
view
=
new
TableView
(
schema
,
id
,
tempViewName
,
querySQL
,
parameters
,
columnTemplateList
.
toArray
(
new
Column
[
0
]),
session
,
parameters
,
columnTemplateList
.
toArray
(
new
Column
[
0
]),
session
,
isRecursive
);
isRecursive
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/command/dml/RecursiveQuery.java
浏览文件 @
68f0dfec
...
@@ -8,7 +8,7 @@ public class RecursiveQuery {
...
@@ -8,7 +8,7 @@ public class RecursiveQuery {
// A query is recursive if it references it's own name in its definition
// A query is recursive if it references it's own name in its definition
public
static
boolean
isRecursive
(
String
tempViewName
,
String
querySQL
)
{
public
static
boolean
isRecursive
(
String
tempViewName
,
String
querySQL
)
{
boolean
foundAny
=
RecursiveQuery
.
foundAny
(
tempViewName
,
querySQL
);
boolean
foundAny
=
RecursiveQuery
.
foundAny
(
tempViewName
,
querySQL
);
System
.
out
.
println
(
"foundAny="
+
foundAny
);
//
System.out.println("foundAny="+foundAny);
return
foundAny
;
return
foundAny
;
}
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/db/TestGeneralCommonTableQueries.java
浏览文件 @
68f0dfec
...
@@ -37,6 +37,14 @@ public class TestGeneralCommonTableQueries extends TestBase {
...
@@ -37,6 +37,14 @@ public class TestGeneralCommonTableQueries extends TestBase {
",t2 as (select first_col+1 from t1) "
+
",t2 as (select first_col+1 from t1) "
+
",t3 as (select 4 as first_col) "
+
",t3 as (select 4 as first_col) "
+
"select * from t1 union all select * from t2 union all select * from t3 where 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.
*
*
...
@@ -44,13 +52,14 @@ public class TestGeneralCommonTableQueries extends TestBase {
...
@@ -44,13 +52,14 @@ public class TestGeneralCommonTableQueries extends TestBase {
*/
*/
public
static
void
main
(
String
...
a
)
throws
Exception
{
public
static
void
main
(
String
...
a
)
throws
Exception
{
TestBase
.
createCaller
().
init
().
test
();
TestBase
.
createCaller
().
init
().
test
();
System
.
out
.
println
(
"Testing done"
);
//
System.out.println("Testing done");
}
}
@Override
@Override
public
void
test
()
throws
Exception
{
public
void
test
()
throws
Exception
{
testSimple
();
testSimple
();
testImpliedColumnNames
();
testImpliedColumnNames
();
testChainedQuery
();
}
}
private
void
testSimple
()
throws
Exception
{
private
void
testSimple
()
throws
Exception
{
...
@@ -118,4 +127,20 @@ public class TestGeneralCommonTableQueries extends TestBase {
...
@@ -118,4 +127,20 @@ public class TestGeneralCommonTableQueries extends TestBase {
conn
.
close
();
conn
.
close
();
deleteDb
(
"commonTableExpressionQueries"
);
deleteDb
(
"commonTableExpressionQueries"
);
}
}
private
void
testChainedQuery
()
throws
Exception
{
deleteDb
(
"commonTableExpressionQueries"
);
Connection
conn
=
getConnection
(
"commonTableExpressionQueries"
);
PreparedStatement
prep
;
ResultSet
rs
;
prep
=
conn
.
prepareStatement
(
PARAMETERIZED_CHAINED_QUERY
);
rs
=
prep
.
executeQuery
();
assertTrue
(
rs
.
next
());
assertEquals
(
2
,
rs
.
getInt
(
1
));
assertFalse
(
rs
.
next
());
conn
.
close
();
deleteDb
(
"commonTableExpressionQueries"
);
}
}
}
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论