Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
7844e2b0
提交
7844e2b0
authored
3月 15, 2016
作者:
Vakhurin Sergey
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix recursive queries: infer column data types
上级
076e7531
显示空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
48 行增加
和
21 行删除
+48
-21
Parser.java
h2/src/main/org/h2/command/Parser.java
+6
-1
CreateView.java
h2/src/main/org/h2/command/ddl/CreateView.java
+10
-1
Column.java
h2/src/main/org/h2/table/Column.java
+1
-1
TableView.java
h2/src/main/org/h2/table/TableView.java
+22
-18
TestRecursiveQueries.java
h2/src/test/org/h2/test/db/TestRecursiveQueries.java
+9
-0
没有找到文件。
h2/src/main/org/h2/command/Parser.java
浏览文件 @
7844e2b0
...
@@ -4746,6 +4746,7 @@ public class Parser {
...
@@ -4746,6 +4746,7 @@ public class Parser {
recursiveTable
=
schema
.
createTable
(
data
);
recursiveTable
=
schema
.
createTable
(
data
);
session
.
addLocalTempTable
(
recursiveTable
);
session
.
addLocalTempTable
(
recursiveTable
);
String
querySQL
;
String
querySQL
;
Column
[]
columnTemplates
=
new
Column
[
cols
.
length
];
try
{
try
{
read
(
"AS"
);
read
(
"AS"
);
read
(
"("
);
read
(
"("
);
...
@@ -4753,12 +4754,16 @@ public class Parser {
...
@@ -4753,12 +4754,16 @@ public class Parser {
read
(
")"
);
read
(
")"
);
withQuery
.
prepare
();
withQuery
.
prepare
();
querySQL
=
StringUtils
.
fromCacheOrNew
(
withQuery
.
getPlanSQL
());
querySQL
=
StringUtils
.
fromCacheOrNew
(
withQuery
.
getPlanSQL
());
ArrayList
<
Expression
>
withExpressions
=
withQuery
.
getExpressions
();
for
(
int
i
=
0
;
i
<
cols
.
length
;
++
i
)
{
columnTemplates
[
i
]
=
new
Column
(
cols
[
i
],
withExpressions
.
get
(
i
).
getType
());
}
}
finally
{
}
finally
{
session
.
removeLocalTempTable
(
recursiveTable
);
session
.
removeLocalTempTable
(
recursiveTable
);
}
}
int
id
=
database
.
allocateObjectId
();
int
id
=
database
.
allocateObjectId
();
TableView
view
=
new
TableView
(
schema
,
id
,
tempViewName
,
querySQL
,
TableView
view
=
new
TableView
(
schema
,
id
,
tempViewName
,
querySQL
,
parameters
,
cols
,
session
,
true
);
parameters
,
col
umnTemplate
s
,
session
,
true
);
view
.
setTableExpression
(
true
);
view
.
setTableExpression
(
true
);
view
.
setTemporary
(
true
);
view
.
setTemporary
(
true
);
session
.
addLocalTempTable
(
view
);
session
.
addLocalTempTable
(
view
);
...
...
h2/src/main/org/h2/command/ddl/CreateView.java
浏览文件 @
7844e2b0
...
@@ -16,8 +16,10 @@ import org.h2.engine.Session;
...
@@ -16,8 +16,10 @@ import org.h2.engine.Session;
import
org.h2.expression.Parameter
;
import
org.h2.expression.Parameter
;
import
org.h2.message.DbException
;
import
org.h2.message.DbException
;
import
org.h2.schema.Schema
;
import
org.h2.schema.Schema
;
import
org.h2.table.Column
;
import
org.h2.table.Table
;
import
org.h2.table.Table
;
import
org.h2.table.TableView
;
import
org.h2.table.TableView
;
import
org.h2.value.Value
;
/**
/**
* This class represents the statement
* This class represents the statement
...
@@ -104,8 +106,15 @@ public class CreateView extends SchemaCommand {
...
@@ -104,8 +106,15 @@ public class CreateView extends SchemaCommand {
if
(
view
==
null
)
{
if
(
view
==
null
)
{
Schema
schema
=
session
.
getDatabase
().
getSchema
(
session
.
getCurrentSchemaName
());
Schema
schema
=
session
.
getDatabase
().
getSchema
(
session
.
getCurrentSchemaName
());
sysSession
.
setCurrentSchema
(
schema
);
sysSession
.
setCurrentSchema
(
schema
);
Column
[]
columnTemplates
=
null
;
if
(
columnNames
!=
null
)
{
columnTemplates
=
new
Column
[
columnNames
.
length
];
for
(
int
i
=
0
;
i
<
columnNames
.
length
;
++
i
)
{
columnTemplates
[
i
]
=
new
Column
(
columnNames
[
i
],
Value
.
UNKNOWN
);
}
}
view
=
new
TableView
(
getSchema
(),
id
,
viewName
,
querySQL
,
null
,
view
=
new
TableView
(
getSchema
(),
id
,
viewName
,
querySQL
,
null
,
column
Nam
es
,
sysSession
,
false
);
column
Templat
es
,
sysSession
,
false
);
}
else
{
}
else
{
view
.
replace
(
querySQL
,
columnNames
,
sysSession
,
false
,
force
);
view
.
replace
(
querySQL
,
columnNames
,
sysSession
,
false
,
force
);
view
.
setModified
();
view
.
setModified
();
...
...
h2/src/main/org/h2/table/Column.java
浏览文件 @
7844e2b0
...
@@ -95,7 +95,7 @@ public class Column {
...
@@ -95,7 +95,7 @@ public class Column {
int
displaySize
)
{
int
displaySize
)
{
this
.
name
=
name
;
this
.
name
=
name
;
this
.
type
=
type
;
this
.
type
=
type
;
if
(
precision
==
-
1
&&
scale
==
-
1
&&
displaySize
==
-
1
)
{
if
(
precision
==
-
1
&&
scale
==
-
1
&&
displaySize
==
-
1
&&
type
!=
Value
.
UNKNOWN
)
{
DataType
dt
=
DataType
.
getDataType
(
type
);
DataType
dt
=
DataType
.
getDataType
(
type
);
precision
=
dt
.
defaultPrecision
;
precision
=
dt
.
defaultPrecision
;
scale
=
dt
.
defaultScale
;
scale
=
dt
.
defaultScale
;
...
...
h2/src/main/org/h2/table/TableView.java
浏览文件 @
7844e2b0
...
@@ -46,7 +46,7 @@ public class TableView extends Table {
...
@@ -46,7 +46,7 @@ public class TableView extends Table {
private
String
querySQL
;
private
String
querySQL
;
private
ArrayList
<
Table
>
tables
;
private
ArrayList
<
Table
>
tables
;
private
String
[]
columnNam
es
;
private
Column
[]
columnTemplat
es
;
private
Query
viewQuery
;
private
Query
viewQuery
;
private
ViewIndex
index
;
private
ViewIndex
index
;
private
boolean
recursive
;
private
boolean
recursive
;
...
@@ -59,10 +59,10 @@ public class TableView extends Table {
...
@@ -59,10 +59,10 @@ public class TableView extends Table {
private
boolean
tableExpression
;
private
boolean
tableExpression
;
public
TableView
(
Schema
schema
,
int
id
,
String
name
,
String
querySQL
,
public
TableView
(
Schema
schema
,
int
id
,
String
name
,
String
querySQL
,
ArrayList
<
Parameter
>
params
,
String
[]
columnNam
es
,
Session
session
,
ArrayList
<
Parameter
>
params
,
Column
[]
columnTemplat
es
,
Session
session
,
boolean
recursive
)
{
boolean
recursive
)
{
super
(
schema
,
id
,
name
,
false
,
true
);
super
(
schema
,
id
,
name
,
false
,
true
);
init
(
querySQL
,
params
,
column
Nam
es
,
session
,
recursive
);
init
(
querySQL
,
params
,
column
Templat
es
,
session
,
recursive
);
}
}
/**
/**
...
@@ -78,21 +78,21 @@ public class TableView extends Table {
...
@@ -78,21 +78,21 @@ public class TableView extends Table {
public
void
replace
(
String
querySQL
,
String
[]
columnNames
,
Session
session
,
public
void
replace
(
String
querySQL
,
String
[]
columnNames
,
Session
session
,
boolean
recursive
,
boolean
force
)
{
boolean
recursive
,
boolean
force
)
{
String
oldQuerySQL
=
this
.
querySQL
;
String
oldQuerySQL
=
this
.
querySQL
;
String
[]
oldColumnNames
=
this
.
columnNam
es
;
Column
[]
oldColumnTemplates
=
this
.
columnTemplat
es
;
boolean
oldRecursive
=
this
.
recursive
;
boolean
oldRecursive
=
this
.
recursive
;
init
(
querySQL
,
null
,
column
Nam
es
,
session
,
recursive
);
init
(
querySQL
,
null
,
column
Templat
es
,
session
,
recursive
);
DbException
e
=
recompile
(
session
,
force
,
true
);
DbException
e
=
recompile
(
session
,
force
,
true
);
if
(
e
!=
null
)
{
if
(
e
!=
null
)
{
init
(
oldQuerySQL
,
null
,
oldColumn
Nam
es
,
session
,
oldRecursive
);
init
(
oldQuerySQL
,
null
,
oldColumn
Templat
es
,
session
,
oldRecursive
);
recompile
(
session
,
true
,
false
);
recompile
(
session
,
true
,
false
);
throw
e
;
throw
e
;
}
}
}
}
private
synchronized
void
init
(
String
querySQL
,
ArrayList
<
Parameter
>
params
,
private
synchronized
void
init
(
String
querySQL
,
ArrayList
<
Parameter
>
params
,
String
[]
columnNam
es
,
Session
session
,
boolean
recursive
)
{
Column
[]
columnTemplat
es
,
Session
session
,
boolean
recursive
)
{
this
.
querySQL
=
querySQL
;
this
.
querySQL
=
querySQL
;
this
.
column
Names
=
columnNam
es
;
this
.
column
Templates
=
columnTemplat
es
;
this
.
recursive
=
recursive
;
this
.
recursive
=
recursive
;
index
=
new
ViewIndex
(
this
,
querySQL
,
params
,
recursive
);
index
=
new
ViewIndex
(
this
,
querySQL
,
params
,
recursive
);
initColumnsAndTables
(
session
);
initColumnsAndTables
(
session
);
...
@@ -161,13 +161,17 @@ public class TableView extends Table {
...
@@ -161,13 +161,17 @@ public class TableView extends Table {
for
(
int
i
=
0
,
count
=
query
.
getColumnCount
();
i
<
count
;
i
++)
{
for
(
int
i
=
0
,
count
=
query
.
getColumnCount
();
i
<
count
;
i
++)
{
Expression
expr
=
expressions
.
get
(
i
);
Expression
expr
=
expressions
.
get
(
i
);
String
name
=
null
;
String
name
=
null
;
if
(
columnNames
!=
null
&&
columnNames
.
length
>
i
)
{
int
type
=
Value
.
UNKNOWN
;
name
=
columnNames
[
i
];
if
(
columnTemplates
!=
null
&&
columnTemplates
.
length
>
i
)
{
name
=
columnTemplates
[
i
].
getName
();
type
=
columnTemplates
[
i
].
getType
();
}
}
if
(
name
==
null
)
{
if
(
name
==
null
)
{
name
=
expr
.
getAlias
();
name
=
expr
.
getAlias
();
}
}
int
type
=
expr
.
getType
();
if
(
type
==
Value
.
UNKNOWN
)
{
type
=
expr
.
getType
();
}
long
precision
=
expr
.
getPrecision
();
long
precision
=
expr
.
getPrecision
();
int
scale
=
expr
.
getScale
();
int
scale
=
expr
.
getScale
();
int
displaySize
=
expr
.
getDisplaySize
();
int
displaySize
=
expr
.
getDisplaySize
();
...
@@ -204,10 +208,10 @@ public class TableView extends Table {
...
@@ -204,10 +208,10 @@ public class TableView extends Table {
// database
// database
tables
=
New
.
arrayList
();
tables
=
New
.
arrayList
();
cols
=
new
Column
[
0
];
cols
=
new
Column
[
0
];
if
(
recursive
&&
column
Nam
es
!=
null
)
{
if
(
recursive
&&
column
Templat
es
!=
null
)
{
cols
=
new
Column
[
column
Nam
es
.
length
];
cols
=
new
Column
[
column
Templat
es
.
length
];
for
(
int
i
=
0
;
i
<
column
Nam
es
.
length
;
i
++)
{
for
(
int
i
=
0
;
i
<
column
Templat
es
.
length
;
i
++)
{
cols
[
i
]
=
new
Column
(
columnNames
[
i
],
Value
.
STRING
);
cols
[
i
]
=
columnTemplates
[
i
].
getClone
(
);
}
}
index
.
setRecursive
(
true
);
index
.
setRecursive
(
true
);
createException
=
null
;
createException
=
null
;
...
@@ -319,11 +323,11 @@ public class TableView extends Table {
...
@@ -319,11 +323,11 @@ public class TableView extends Table {
buff
.
append
(
c
.
getSQL
());
buff
.
append
(
c
.
getSQL
());
}
}
buff
.
append
(
')'
);
buff
.
append
(
')'
);
}
else
if
(
column
Nam
es
!=
null
)
{
}
else
if
(
column
Templat
es
!=
null
)
{
buff
.
append
(
'('
);
buff
.
append
(
'('
);
for
(
String
n
:
columnNam
es
)
{
for
(
Column
c
:
columnTemplat
es
)
{
buff
.
appendExceptFirst
(
", "
);
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
n
);
buff
.
append
(
c
.
getName
()
);
}
}
buff
.
append
(
')'
);
buff
.
append
(
')'
);
}
}
...
...
h2/src/test/org/h2/test/db/TestRecursiveQueries.java
浏览文件 @
7844e2b0
...
@@ -9,6 +9,7 @@ import java.sql.Connection;
...
@@ -9,6 +9,7 @@ import java.sql.Connection;
import
java.sql.PreparedStatement
;
import
java.sql.PreparedStatement
;
import
java.sql.ResultSet
;
import
java.sql.ResultSet
;
import
java.sql.Statement
;
import
java.sql.Statement
;
import
java.sql.Types
;
import
org.h2.test.TestBase
;
import
org.h2.test.TestBase
;
/**
/**
...
@@ -138,6 +139,14 @@ public class TestRecursiveQueries extends TestBase {
...
@@ -138,6 +139,14 @@ public class TestRecursiveQueries extends TestBase {
rs
=
prep
.
executeQuery
();
rs
=
prep
.
executeQuery
();
assertResultSetOrdered
(
rs
,
new
String
[][]{{
"100"
},
{
"103"
}});
assertResultSetOrdered
(
rs
,
new
String
[][]{{
"100"
},
{
"103"
}});
rs
=
stat
.
executeQuery
(
"with recursive t(i, s, d) as "
+
"(select 1, '.', now() union all"
+
" select i+1, s||'.', d from t where i<3)"
+
" select * from t"
);
assertResultSetMeta
(
rs
,
3
,
new
String
[]{
"I"
,
"S"
,
"D"
},
new
int
[]{
Types
.
INTEGER
,
Types
.
VARCHAR
,
Types
.
TIMESTAMP
},
null
,
null
);
conn
.
close
();
conn
.
close
();
deleteDb
(
"recursiveQueries"
);
deleteDb
(
"recursiveQueries"
);
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论