Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
3e77d2fb
提交
3e77d2fb
authored
8 年前
作者:
Noel Grandin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
couple of cleanups to the CTE merge
上级
5a428e25
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
114 行增加
和
114 行删除
+114
-114
changelog.html
h2/src/docsrc/html/changelog.html
+2
-0
Parser.java
h2/src/main/org/h2/command/Parser.java
+88
-87
TableView.java
h2/src/main/org/h2/table/TableView.java
+24
-27
没有找到文件。
h2/src/docsrc/html/changelog.html
浏览文件 @
3e77d2fb
...
...
@@ -21,6 +21,8 @@ Change Log
<h2>
Next Version (unreleased)
</h2>
<ul>
<li>
Issue#479 Allow non-recursive CTEs (WITH statements), patch from stumc
</li>
<li>
Fix startup issue when using "CHECK" as a column name.
</li>
<li>
Issue #423: ANALYZE performed multiple times on one table during execution of the same statement.
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/command/Parser.java
浏览文件 @
3e77d2fb
...
...
@@ -18,7 +18,6 @@ import java.util.Comparator;
import
java.util.HashSet
;
import
java.util.LinkedHashSet
;
import
java.util.List
;
import
org.h2.api.ErrorCode
;
import
org.h2.api.Trigger
;
import
org.h2.command.ddl.AlterIndexRename
;
...
...
@@ -4859,9 +4858,9 @@ public class Parser {
private
Query
parseWith
()
{
List
<
TableView
>
viewsCreated
=
new
ArrayList
<
TableView
>();
readIf
(
"RECURSIVE"
);
do
{
do
{
viewsCreated
.
add
(
parseSingleCommonTableExpression
());
}
while
(
readIf
(
","
));
}
while
(
readIf
(
","
));
Query
q
=
parseSelectUnion
();
q
.
setPrepareAlways
(
true
);
...
...
@@ -4877,10 +4876,11 @@ public class Parser {
// column names are now optional - they can be inferred from the named
// query if not supplied
if
(
readIf
(
"("
))
{
if
(
readIf
(
"("
))
{
cols
=
parseColumnList
();
for
(
String
c
:
cols
)
{
// we dont really know the type of the column, so string will have to do
// we dont really know the type of the column, so string will
// have to do
columns
.
add
(
new
Column
(
c
,
Value
.
STRING
));
}
}
...
...
@@ -4898,7 +4898,8 @@ public class Parser {
session
.
removeLocalTempTable
(
old
);
}
// this table is created as a work around because recursive
// table expressions need to reference something that look like themselves
// table expressions need to reference something that look like
// themselves
// to work (its removed after creation in this method)
CreateTableData
data
=
new
CreateTableData
();
data
.
id
=
database
.
allocateObjectId
();
...
...
@@ -4922,26 +4923,26 @@ public class Parser {
querySQL
=
StringUtils
.
cache
(
withQuery
.
getPlanSQL
());
ArrayList
<
Expression
>
withExpressions
=
withQuery
.
getExpressions
();
for
(
int
i
=
0
;
i
<
withExpressions
.
size
();
++
i
)
{
String
columnName
=
cols
!=
null
?
cols
[
i
]
:
withExpressions
.
get
(
i
).
getColumnName
();
columnTemplateList
.
add
(
new
Column
(
columnName
,
withExpressions
.
get
(
i
).
getType
()));
String
columnName
=
cols
!=
null
?
cols
[
i
]
:
withExpressions
.
get
(
i
).
getColumnName
();
columnTemplateList
.
add
(
new
Column
(
columnName
,
withExpressions
.
get
(
i
).
getType
()));
}
}
finally
{
session
.
removeLocalTempTable
(
recursiveTable
);
}
int
id
=
database
.
allocateObjectId
();
boolean
isRecursive
=
true
;
TableView
view
=
null
;
do
{
view
=
new
TableView
(
schema
,
id
,
tempViewName
,
querySQL
,
// No easy way to determine if this is a recursive query up front, so we just compile
// it twice - once without the flag set, and if we didn't see a recursive term,
// then we just compile it again.
TableView
view
=
new
TableView
(
schema
,
id
,
tempViewName
,
querySQL
,
parameters
,
columnTemplateList
.
toArray
(
new
Column
[
0
]),
session
,
isRecursive
);
if
(
view
.
isRecursiveQueryDetected
()!=
isRecursive
)
{
isRecursive
=
view
.
isRecursiveQueryDetected
();
view
=
null
;
continue
;
true
/* recursive */
);
if
(!
view
.
isRecursiveQueryDetected
())
{
view
=
new
TableView
(
schema
,
id
,
tempViewName
,
querySQL
,
parameters
,
columnTemplateList
.
toArray
(
new
Column
[
0
]),
session
,
false
/* recursive */
)
;
}
}
while
(
view
==
null
);
view
.
setTableExpression
(
true
);
view
.
setTemporary
(
true
);
session
.
addLocalTempTable
(
view
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/table/TableView.java
浏览文件 @
3e77d2fb
...
...
@@ -205,12 +205,11 @@ public class TableView extends Table {
}
catch
(
DbException
e
)
{
e
.
addSQL
(
getCreateSQL
());
createException
=
e
;
//
i
f it can't be compiled, then it's a 'zero column table'
//
I
f 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
(
isRecursiveQueryExceptionDetected
(
createException
)){
// database.
// If it can not be compiled - it could also be a recursive common table expression query.
if
(
isRecursiveQueryExceptionDetected
(
createException
))
{
this
.
isRecursiveQueryDetected
=
true
;
}
tables
=
New
.
arrayList
();
...
...
@@ -674,25 +673,23 @@ public class TableView extends Table {
}
/**
* If query recursion is detected (for recursion detection)
* @return is Recursive Query Flag Set
* Was query recursion detected during compiling.
*/
public
boolean
isRecursiveQueryDetected
(){
public
boolean
isRecursiveQueryDetected
()
{
return
isRecursiveQueryDetected
;
}
/**
* If query an exception indicates query recursion
* @return is Recursive Query Exception Detected
* Does exception indicate query recursion?
*/
private
boolean
isRecursiveQueryExceptionDetected
(
DbException
exception
){
if
(
exception
==
null
)
{
private
boolean
isRecursiveQueryExceptionDetected
(
DbException
exception
)
{
if
(
exception
==
null
)
{
return
false
;
}
if
(
exception
.
getErrorCode
()!=
ErrorCode
.
TABLE_OR_VIEW_NOT_FOUND_1
)
{
if
(
exception
.
getErrorCode
()
!=
ErrorCode
.
TABLE_OR_VIEW_NOT_FOUND_1
)
{
return
false
;
}
if
(!
exception
.
getMessage
().
contains
(
"\""
+
this
.
getName
()+
"\""
))
{
if
(!
exception
.
getMessage
().
contains
(
"\""
+
this
.
getName
()
+
"\""
))
{
return
false
;
}
return
true
;
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论