Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
ab0708a7
提交
ab0708a7
authored
11月 26, 2017
作者:
Owner
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Testing recursive persistent cte's
上级
ca5acf41
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
46 行增加
和
41 行删除
+46
-41
Select.java
h2/src/main/org/h2/command/dml/Select.java
+40
-39
Database.java
h2/src/main/org/h2/engine/Database.java
+3
-0
ViewIndex.java
h2/src/main/org/h2/index/ViewIndex.java
+1
-0
TestGeneralCommonTableQueries.java
...rc/test/org/h2/test/db/TestGeneralCommonTableQueries.java
+2
-2
没有找到文件。
h2/src/main/org/h2/command/dml/Select.java
浏览文件 @
ab0708a7
...
...
@@ -1086,46 +1086,47 @@ public class Select extends Query {
StatementBuilder
buff
=
new
StatementBuilder
();
for
(
TableFilter
f
:
topFilters
)
{
Table
t
=
f
.
getTable
();
boolean
isPersistent
=
!
t
.
isTemporary
();
if
(
t
.
isView
()
&&
((
TableView
)
t
).
isRecursive
())
{
// hmmm - how do you generate a plan sql which is recursive
// for a system which does not natively support recursive SQLs... ?
// answer: you can't
TableView
tv
=
((
TableView
)
t
);
buff
.
append
(
"WITH "
);
if
(
tv
.
isRecursive
()){
buff
.
append
(
"RECURSIVE "
);
}
if
(
isPersistent
){
buff
.
append
(
"PERSISTENT "
);
}
buff
.
append
(
t
.
getName
()).
append
(
'('
);
buff
.
resetCount
();
for
(
Column
c
:
t
.
getColumns
())
{
buff
.
appendExceptFirst
(
","
);
buff
.
append
(
c
.
getName
());
}
String
theSQL
=
t
.
getSQL
();
System
.
out
.
println
(
"getPlanSQL.theSQL="
+
theSQL
);
System
.
out
.
println
(
"getPlanSQL.sqlStatement="
+
sqlStatement
);
if
(!
sqlStatement
.
contains
(
"?"
)
&&
sqlStatement
.
toUpperCase
().
contains
(
"SELECT"
)
&&
session
.
isParsingView
()){
theSQL
=
extractNamedCTEQueryFromSQL
(
t
.
getName
(),
sqlStatement
);
if
(!(
theSQL
.
startsWith
(
"("
)&&
theSQL
.
endsWith
(
")"
))){
theSQL
=
"( "
+
theSQL
+
" )"
;
}
}
else
if
(!(
theSQL
.
startsWith
(
"("
)&&
theSQL
.
endsWith
(
")"
))){
StatementBuilder
buffSelect
=
new
StatementBuilder
();
buffSelect
.
append
(
"( SELECT "
);
buffSelect
.
resetCount
();
for
(
Column
c
:
t
.
getColumns
())
{
buffSelect
.
appendExceptFirst
(
","
);
buffSelect
.
append
(
c
.
getName
());
}
buffSelect
.
append
(
" FROM "
+
t
.
getSQL
()+
" ) "
);
theSQL
=
buffSelect
.
toString
();
}
buff
.
append
(
") AS "
).
append
(
theSQL
).
append
(
"\n"
);
continue
;
// boolean isPersistent = !t.isTemporary();
// // hmmm - how do you generate a plan sql which is recursive
// // for a system which does not natively support recursive SQLs... ?
// // answer: you can't
// TableView tv = ((TableView) t);
// buff.append("WITH ");
// if(tv.isRecursive()){
// buff.append("RECURSIVE ");
// }
// if(isPersistent){
// buff.append("PERSISTENT ");
// }
// buff.append(t.getName()).append('(');
// buff.resetCount();
// for (Column c : t.getColumns()) {
// buff.appendExceptFirst(",");
// buff.append(c.getName());
// }
// String theSQL = t.getSQL();
// System.out.println("getPlanSQL.theSQL="+theSQL);
// System.out.println("getPlanSQL.sqlStatement="+sqlStatement);
// if(!sqlStatement.contains("?") && sqlStatement.toUpperCase().contains("SELECT") && session.isParsingView()){
// theSQL = extractNamedCTEQueryFromSQL(t.getName(),sqlStatement);
// if(!(theSQL.startsWith("(")&&theSQL.endsWith(")"))){
// theSQL = "( "+theSQL+" )";
// }
// }
// else if(!(theSQL.startsWith("(")&&theSQL.endsWith(")"))){
// StatementBuilder buffSelect = new StatementBuilder();
// buffSelect.append("( SELECT ");
// buffSelect.resetCount();
// for (Column c : t.getColumns()) {
// buffSelect.appendExceptFirst(",");
// buffSelect.append(c.getName());
// }
// buffSelect.append(" FROM "+t.getSQL()+" ) ");
// theSQL = buffSelect.toString();
// }
// buff.append(") AS ").append(theSQL).append("\n");
}
}
buff
.
resetCount
();
...
...
h2/src/main/org/h2/engine/Database.java
浏览文件 @
ab0708a7
...
...
@@ -1955,6 +1955,9 @@ public class Database implements DataHandler {
}
System
.
out
.
println
(
"Removing db object id - also remove meta lock from session and session lock from meta, id="
+
id
+
",sessionId="
+
session
.
getId
()+
",name="
+
savedName
);
if
(
"TREE_CTE"
.
equals
(
savedName
)){
new
RuntimeException
(
"TREE_CTE distruction"
).
printStackTrace
();
}
removeMeta
(
session
,
id
);
flushDeferredRemoveSchemaObject
();
...
...
h2/src/main/org/h2/index/ViewIndex.java
浏览文件 @
ab0708a7
...
...
@@ -173,6 +173,7 @@ public class ViewIndex extends BaseIndex implements SpatialIndex {
Prepared
p
;
session
.
pushSubQueryInfo
(
masks
,
filters
,
filter
,
sortOrder
);
try
{
System
.
out
.
println
(
"ViewIndex.prepareSubQuery:"
+
sql
);
p
=
session
.
prepare
(
sql
,
true
,
true
);
}
finally
{
session
.
popSubQueryInfo
();
...
...
h2/src/test/org/h2/test/db/TestGeneralCommonTableQueries.java
浏览文件 @
ab0708a7
...
...
@@ -571,7 +571,7 @@ public class TestGeneralCommonTableQueries extends TestBase {
String
[]
expectedColumnNames
=
new
String
[]{
"SUB_TREE_ROOT_ID"
,
"TREE_LEVEL"
,
"PARENT_FK"
,
"CHILD_FK"
};
int
expectedNumberOfRows
=
11
;
testRepeatedQueryWithSetup
(
maxRetries
,
expectedRowData
,
expectedColumnNames
,
expectedNumberOfRows
,
SETUP_SQL
,
WITH_QUERY
,
0
/*maxRetries-1*/
);
WITH_QUERY
,
maxRetries
-
1
);
}
private
void
testPersistentNonRecursiveTableInCreateView
()
throws
Exception
{
String
SETUP_SQL
=
""
...
...
@@ -635,7 +635,7 @@ public class TestGeneralCommonTableQueries extends TestBase {
conn
=
getConnection
(
"commonTableExpressionQueries"
);
}
System
.
out
.
println
(
"=========== test with query"
);
prep
=
conn
.
prepareStatement
(
WITH_QUERY
);
rs
=
prep
.
executeQuery
();
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论