Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
26bcb6df
提交
26bcb6df
authored
6月 01, 2017
作者:
Owner
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Issue#479 Made column names optional
上级
b28ee4f9
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
39 行增加
和
12 行删除
+39
-12
Parser.java
h2/src/main/org/h2/command/Parser.java
+6
-2
RecursiveQuery.java
h2/src/main/org/h2/command/dml/RecursiveQuery.java
+4
-10
Column.java
h2/src/main/org/h2/table/Column.java
+3
-0
TestGeneralCommonTableQueries.java
...rc/test/org/h2/test/db/TestGeneralCommonTableQueries.java
+26
-0
没有找到文件。
h2/src/main/org/h2/command/Parser.java
浏览文件 @
26bcb6df
...
@@ -18,6 +18,7 @@ import java.util.Comparator;
...
@@ -18,6 +18,7 @@ import java.util.Comparator;
import
java.util.HashSet
;
import
java.util.HashSet
;
import
java.util.LinkedHashSet
;
import
java.util.LinkedHashSet
;
import
java.util.List
;
import
java.util.List
;
import
java.util.stream.Collectors
;
import
org.h2.api.ErrorCode
;
import
org.h2.api.ErrorCode
;
import
org.h2.api.Trigger
;
import
org.h2.api.Trigger
;
...
@@ -4906,7 +4907,10 @@ public class Parser {
...
@@ -4906,7 +4907,10 @@ 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
)
{
String
columnName
=
cols
!=
null
?
cols
[
i
]
:
withExpressions
.
get
(
i
).
getColumnName
();
System
.
out
.
println
(
"columnName="
+
withExpressions
.
get
(
i
).
getColumnName
());
System
.
out
.
println
(
"alias="
+
withExpressions
.
get
(
i
).
getAlias
());
System
.
out
.
println
(
"nonAliasExpression="
+
withExpressions
.
get
(
i
).
getNonAliasExpression
());
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
()));
}
}
}
finally
{
}
finally
{
...
@@ -4915,7 +4919,7 @@ public class Parser {
...
@@ -4915,7 +4919,7 @@ 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
);
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
,
...
...
h2/src/main/org/h2/command/dml/RecursiveQuery.java
浏览文件 @
26bcb6df
...
@@ -7,21 +7,15 @@ public class RecursiveQuery {
...
@@ -7,21 +7,15 @@ 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
)
{
// ?i is case insensitive
// ?m is multi-line search
// ?d is Unix line endings
String
pattern
=
"(?i)(?m)(?d).*\\b("
+
tempViewName
+
")\\b"
;
System
.
out
.
println
(
"pattern="
+
pattern
);
boolean
stringContains
=
querySQL
.
contains
(
tempViewName
);
System
.
out
.
println
(
"stringContains="
+
stringContains
);
boolean
foundAny
=
RecursiveQuery
.
foundAny
(
tempViewName
,
querySQL
);
boolean
foundAny
=
RecursiveQuery
.
foundAny
(
tempViewName
,
querySQL
);
System
.
out
.
println
(
"foundAny="
+
foundAny
);
System
.
out
.
println
(
"foundAny="
+
foundAny
);
boolean
patternMatch
=
Pattern
.
matches
(
pattern
,
querySQL
);
return
foundAny
;
System
.
out
.
println
(
"patternMatch="
+
patternMatch
);
return
patternMatch
||
stringContains
||
foundAny
;
}
}
private
static
boolean
foundAny
(
String
tempViewName
,
String
querySQL
){
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"
);
Pattern
p
=
Pattern
.
compile
(
"(?i)(?m)(?d)\\b("
+
tempViewName
+
")\\b"
);
Matcher
m
=
p
.
matcher
(
querySQL
);
Matcher
m
=
p
.
matcher
(
querySQL
);
while
(
m
.
find
())
{
while
(
m
.
find
())
{
...
...
h2/src/main/org/h2/table/Column.java
浏览文件 @
26bcb6df
...
@@ -738,6 +738,9 @@ public class Column {
...
@@ -738,6 +738,9 @@ public class Column {
public
String
toString
()
{
public
String
toString
()
{
return
name
;
return
name
;
}
}
public
String
toStringWithType
()
{
return
DataType
.
getTypeClassName
(
type
)+
":"
+
name
;
}
/**
/**
* Check whether the new column is of the same type and not more restricted
* Check whether the new column is of the same type and not more restricted
...
...
h2/src/test/org/h2/test/db/TestGeneralCommonTableQueries.java
浏览文件 @
26bcb6df
...
@@ -32,6 +32,11 @@ public class TestGeneralCommonTableQueries extends TestBase {
...
@@ -32,6 +32,11 @@ public class TestGeneralCommonTableQueries extends TestBase {
",t3(n) as (select 4 as first) "
+
",t3(n) as (select 4 as first) "
+
"select * from t1 union all select * from t2 union all select * from t3 where n<>?"
;
"select * from t1 union all select * from t2 union all select * from t3 where n<>?"
;
private
static
final
String
PARAMETERIZED_THREE_COMMON_QUERY_IMPLIED_COLUMN_NAMES
=
"with "
+
"t1 as (select 2 as first_col) "
+
",t2 as (select first_col+1 from t1) "
+
",t3 as (select 4 as first_col) "
+
"select * from t1 union all select * from t2 union all select * from t3 where first_col<>?"
;
/**
/**
* Run just this test.
* Run just this test.
*
*
...
@@ -45,6 +50,7 @@ public class TestGeneralCommonTableQueries extends TestBase {
...
@@ -45,6 +50,7 @@ public class TestGeneralCommonTableQueries extends TestBase {
@Override
@Override
public
void
test
()
throws
Exception
{
public
void
test
()
throws
Exception
{
testSimple
();
testSimple
();
testImpliedColumnNames
();
}
}
private
void
testSimple
()
throws
Exception
{
private
void
testSimple
()
throws
Exception
{
...
@@ -92,4 +98,24 @@ public class TestGeneralCommonTableQueries extends TestBase {
...
@@ -92,4 +98,24 @@ public class TestGeneralCommonTableQueries extends TestBase {
deleteDb
(
"commonTableExpressionQueries"
);
deleteDb
(
"commonTableExpressionQueries"
);
}
}
private
void
testImpliedColumnNames
()
throws
Exception
{
deleteDb
(
"commonTableExpressionQueries"
);
Connection
conn
=
getConnection
(
"commonTableExpressionQueries"
);
PreparedStatement
prep
;
ResultSet
rs
;
prep
=
conn
.
prepareStatement
(
PARAMETERIZED_THREE_COMMON_QUERY_IMPLIED_COLUMN_NAMES
);
prep
.
setInt
(
1
,
4
);
// omit 4 line (last)
rs
=
prep
.
executeQuery
();
assertTrue
(
rs
.
next
());
assertEquals
(
2
,
rs
.
getInt
(
1
));
assertTrue
(
rs
.
next
());
assertEquals
(
3
,
rs
.
getInt
(
"FIRST_COL"
));
assertFalse
(
rs
.
next
());
assertEquals
(
"rsMeta0: columns=1"
,
rs
.
getMetaData
().
toString
());
assertEquals
(
"FIRST_COL"
,
rs
.
getMetaData
().
getColumnLabel
(
1
));
conn
.
close
();
deleteDb
(
"commonTableExpressionQueries"
);
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论