Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
94e79df5
提交
94e79df5
authored
6月 04, 2017
作者:
Owner
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Issue#479 Ready for final fix to testCTE
上级
8ca2feb0
显示空白字符变更
内嵌
并排
正在显示
9 个修改的文件
包含
19 行增加
和
113 行删除
+19
-113
Parser.java
h2/src/main/org/h2/command/Parser.java
+3
-24
RecursiveQueryHeuristic.java
h2/src/main/org/h2/command/dml/RecursiveQueryHeuristic.java
+0
-26
ViewIndex.java
h2/src/main/org/h2/index/ViewIndex.java
+2
-3
DbException.java
h2/src/main/org/h2/message/DbException.java
+2
-2
DbNotRecursiveException.java
h2/src/main/org/h2/message/DbNotRecursiveException.java
+0
-28
RangeTable.java
h2/src/main/org/h2/table/RangeTable.java
+0
-1
Table.java
h2/src/main/org/h2/table/Table.java
+4
-17
TableView.java
h2/src/main/org/h2/table/TableView.java
+8
-10
TestGeneralCommonTableQueries.java
...rc/test/org/h2/test/db/TestGeneralCommonTableQueries.java
+0
-2
没有找到文件。
h2/src/main/org/h2/command/Parser.java
浏览文件 @
94e79df5
...
...
@@ -76,7 +76,6 @@ import org.h2.command.dml.Insert;
import
org.h2.command.dml.Merge
;
import
org.h2.command.dml.NoOperation
;
import
org.h2.command.dml.Query
;
import
org.h2.command.dml.RecursiveQueryHeuristic
;
import
org.h2.command.dml.Replace
;
import
org.h2.command.dml.RunScriptCommand
;
import
org.h2.command.dml.ScriptCommand
;
...
...
@@ -126,7 +125,6 @@ import org.h2.expression.Variable;
import
org.h2.expression.Wildcard
;
import
org.h2.index.Index
;
import
org.h2.message.DbException
;
import
org.h2.message.DbNotRecursiveException
;
import
org.h2.result.SortOrder
;
import
org.h2.schema.Schema
;
import
org.h2.schema.Sequence
;
...
...
@@ -4862,7 +4860,7 @@ public class Parser {
List
<
TableView
>
viewsCreated
=
new
ArrayList
<
TableView
>();
readIf
(
"RECURSIVE"
);
do
{
viewsCreated
.
add
(
parseSingleCommonTableExression
());
viewsCreated
.
add
(
parseSingleCommonTableEx
p
ression
());
}
while
(
readIf
(
","
));
Query
q
=
parseSelectUnion
();
...
...
@@ -4870,7 +4868,7 @@ public class Parser {
return
q
;
}
private
TableView
parseSingleCommonTableExression
()
{
private
TableView
parseSingleCommonTableEx
p
ression
()
{
String
tempViewName
=
readIdentifierWithSchema
();
Schema
schema
=
getSchema
();
Table
recursiveTable
;
...
...
@@ -4931,34 +4929,15 @@ public class Parser {
session
.
removeLocalTempTable
(
recursiveTable
);
}
int
id
=
database
.
allocateObjectId
();
boolean
isRecursive
=
true
;
//RecursiveQueryHeuristic.isRecursive(tempViewName,querySQL);
boolean
isRecursive
=
true
;
TableView
view
=
null
;
do
{
try
{
view
=
new
TableView
(
schema
,
id
,
tempViewName
,
querySQL
,
parameters
,
columnTemplateList
.
toArray
(
new
Column
[
0
]),
session
,
isRecursive
);
}
catch
(
DbNotRecursiveException
e
){
if
(
isRecursive
==
false
){
throw
e
;
}
isRecursive
=
false
;
view
=
null
;
System
.
out
.
println
(
"repeat new table by exeception"
);
continue
;
}
HashSet
<
DbObject
>
subDependencies
=
new
HashSet
<
DbObject
>();
view
.
addStrictSubDependencies
(
subDependencies
,
false
);
System
.
out
.
println
(
"tempViewName="
+
tempViewName
);
System
.
out
.
println
(
"subDependencies="
+
subDependencies
);
System
.
out
.
println
(
"isRecursiveQueryDetected="
+
view
.
isRecursiveQueryDetected
());
boolean
isRecursiveByDeepAnalysis
=
subDependencies
.
contains
(
recursiveTable
);
System
.
out
.
println
(
"isRecursiveByDeepAnalysis="
+
isRecursiveByDeepAnalysis
);
if
(
view
.
isRecursiveQueryDetected
()!=
isRecursive
){
isRecursive
=
view
.
isRecursiveQueryDetected
();
view
=
null
;
System
.
out
.
println
(
"repeat new table creation by view.isRecursiveQueryDetected()"
);
continue
;
}
...
...
h2/src/main/org/h2/command/dml/RecursiveQueryHeuristic.java
deleted
100755 → 0
浏览文件 @
8ca2feb0
package
org
.
h2
.
command
.
dml
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
public
class
RecursiveQueryHeuristic
{
// A query is recursive if it references it's own name in its definition
public
static
boolean
isRecursive
(
String
tempViewName
,
String
querySQL
)
{
boolean
foundAny
=
RecursiveQueryHeuristic
.
foundAny
(
tempViewName
,
querySQL
);
//System.out.println("foundAny="+foundAny);
return
foundAny
;
}
private
static
boolean
foundAny
(
String
tempViewName
,
String
querySQL
){
// ?i is case insensitive
// ?m is multi-line search
// ?d is Unix line endings
Pattern
p
=
Pattern
.
compile
(
"(?i)(?m)(?d)\\b("
+
tempViewName
+
")\\b"
);
Matcher
m
=
p
.
matcher
(
querySQL
);
while
(
m
.
find
())
{
return
true
;
}
return
false
;
}
}
h2/src/main/org/h2/index/ViewIndex.java
浏览文件 @
94e79df5
...
...
@@ -19,7 +19,6 @@ import org.h2.engine.Session;
import
org.h2.expression.Comparison
;
import
org.h2.expression.Parameter
;
import
org.h2.message.DbException
;
import
org.h2.message.DbNotRecursiveException
;
import
org.h2.result.LocalResult
;
import
org.h2.result.ResultInterface
;
import
org.h2.result.Row
;
...
...
@@ -196,12 +195,12 @@ public class ViewIndex extends BaseIndex implements SpatialIndex {
query
.
setNeverLazy
(
true
);
}
if
(!
query
.
isUnion
())
{
throw
Db
NotRecursive
Exception
.
get
(
ErrorCode
.
SYNTAX_ERROR_2
,
throw
DbException
.
get
(
ErrorCode
.
SYNTAX_ERROR_2
,
"recursive queries without UNION ALL"
);
}
SelectUnion
union
=
(
SelectUnion
)
query
;
if
(
union
.
getUnionType
()
!=
SelectUnion
.
UNION_ALL
)
{
throw
Db
NotRecursive
Exception
.
get
(
ErrorCode
.
SYNTAX_ERROR_2
,
throw
DbException
.
get
(
ErrorCode
.
SYNTAX_ERROR_2
,
"recursive queries without UNION ALL"
);
}
Query
left
=
union
.
getLeft
();
...
...
h2/src/main/org/h2/message/DbException.java
浏览文件 @
94e79df5
...
...
@@ -70,11 +70,11 @@ public class DbException extends RuntimeException {
}
}
pr
otected
DbException
(
SQLException
e
)
{
pr
ivate
DbException
(
SQLException
e
)
{
super
(
e
.
getMessage
(),
e
);
}
pr
otected
static
String
translate
(
String
key
,
String
...
params
)
{
pr
ivate
static
String
translate
(
String
key
,
String
...
params
)
{
String
message
=
null
;
if
(
MESSAGES
!=
null
)
{
// Tomcat sets final static fields to null sometimes
...
...
h2/src/main/org/h2/message/DbNotRecursiveException.java
deleted
100755 → 0
浏览文件 @
8ca2feb0
package
org
.
h2
.
message
;
import
java.sql.SQLException
;
import
org.h2.api.ErrorCode
;
import
org.h2.jdbc.JdbcSQLException
;
public
class
DbNotRecursiveException
extends
DbException
{
private
static
final
long
serialVersionUID
=
-
5941745175474148318L
;
public
static
DbNotRecursiveException
get
(
int
errorCode
,
String
p1
)
{
return
get
(
errorCode
,
new
String
[]
{
p1
});
}
public
static
DbNotRecursiveException
get
(
int
errorCode
,
String
...
params
)
{
return
new
DbNotRecursiveException
(
getJdbcSQLException
(
errorCode
,
null
,
params
));
}
private
static
JdbcSQLException
getJdbcSQLException
(
int
errorCode
,
Throwable
cause
,
String
...
params
)
{
String
sqlstate
=
ErrorCode
.
getState
(
errorCode
);
String
message
=
translate
(
sqlstate
,
params
);
return
new
JdbcSQLException
(
message
,
null
,
sqlstate
,
errorCode
,
cause
,
null
);
}
private
DbNotRecursiveException
(
SQLException
e
)
{
super
(
e
);
}
}
h2/src/main/org/h2/table/RangeTable.java
浏览文件 @
94e79df5
...
...
@@ -145,7 +145,6 @@ public class RangeTable extends Table {
@Override
public
TableType
getTableType
()
{
return
TableType
.
SYSTEM_TABLE
;
//throw DbException.throwInternalError(toString());
}
@Override
...
...
h2/src/main/org/h2/table/Table.java
浏览文件 @
94e79df5
...
...
@@ -352,22 +352,11 @@ public abstract class Table extends SchemaObjectBase {
}
/**
* Add all objects that this table depends on to the hash set
, including this object
.
* Add all objects that this table depends on to the hash set.
*
* @param dependencies the current set of dependencies
*/
public
void
addDependencies
(
HashSet
<
DbObject
>
dependencies
)
{
addStrictSubDependencies
(
dependencies
,
false
);
dependencies
.
add
(
this
);
}
/**
* Add all objects that this table depends on to the hash set, excluding
* this object (unless it is has recursive references).
*
* @param dependencies the current set of dependencies
*/
public
void
addStrictSubDependencies
(
HashSet
<
DbObject
>
dependencies
,
boolean
visitColumnTables
)
{
if
(
dependencies
.
contains
(
this
))
{
// avoid endless recursion
return
;
...
...
@@ -381,15 +370,13 @@ public abstract class Table extends SchemaObjectBase {
dependencies
);
for
(
Column
col
:
columns
)
{
col
.
isEverything
(
visitor
);
if
(
visitColumnTables
&&
col
.
getTable
()!=
null
){
dependencies
.
add
(
col
.
getTable
());
}
}
if
(
constraints
!=
null
)
{
for
(
Constraint
c
:
constraints
)
{
c
.
isEverything
(
visitor
);
}
}
dependencies
.
add
(
this
);
}
@Override
...
...
h2/src/main/org/h2/table/TableView.java
浏览文件 @
94e79df5
...
...
@@ -8,9 +8,7 @@ package org.h2.table;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Map
;
import
org.h2.api.ErrorCode
;
import
org.h2.command.Prepared
;
import
org.h2.command.dml.Query
;
...
...
@@ -210,6 +208,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
(
isRecursiveQueryExceptionDetected
(
createException
)){
this
.
isRecursiveQueryDetected
=
true
;
}
...
...
@@ -674,19 +674,17 @@ public class TableView extends Table {
}
/**
*
Get a list of the tables used by this query
(for recursion detection)
* @return
*
If query recursion is detected
(for recursion detection)
* @return
is Recursive Query Flag Set
*/
public
List
<
Table
>
getTables
(){
return
tables
;
}
public
boolean
isRecursiveQueryDetected
(){
return
isRecursiveQueryDetected
;
}
/**
* If query an exception indicates query recursion
* @return is Recursive Query Exception Detected
*/
private
boolean
isRecursiveQueryExceptionDetected
(
DbException
exception
){
if
(
exception
==
null
){
return
false
;
...
...
h2/src/test/org/h2/test/db/TestGeneralCommonTableQueries.java
浏览文件 @
94e79df5
...
...
@@ -51,9 +51,7 @@ public class TestGeneralCommonTableQueries extends TestBase {
* @param a ignored
*/
public
static
void
main
(
String
...
a
)
throws
Exception
{
System
.
out
.
println
(
"Testing starting"
);
TestBase
.
createCaller
().
init
().
test
();
System
.
out
.
println
(
"Testing done"
);
}
@Override
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论