Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
f97ba1cb
提交
f97ba1cb
authored
14 年前
作者:
Sergi Vladykin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
PreparedStatement.getMetaData() was not always consistent with resulting ResultSet.getMetaData().
上级
93a6e550
隐藏空白字符变更
内嵌
并排
正在显示
9 个修改的文件
包含
142 行增加
和
37 行删除
+142
-37
changelog.html
h2/src/docsrc/html/changelog.html
+2
-1
Call.java
h2/src/main/org/h2/command/dml/Call.java
+16
-12
Expression.java
h2/src/main/org/h2/expression/Expression.java
+60
-0
ExpressionList.java
h2/src/main/org/h2/expression/ExpressionList.java
+12
-0
JavaFunction.java
h2/src/main/org/h2/expression/JavaFunction.java
+17
-0
Subquery.java
h2/src/main/org/h2/expression/Subquery.java
+19
-1
TableFunction.java
h2/src/main/org/h2/expression/TableFunction.java
+8
-0
ValueExpression.java
h2/src/main/org/h2/expression/ValueExpression.java
+7
-0
LocalResult.java
h2/src/main/org/h2/result/LocalResult.java
+1
-23
没有找到文件。
h2/src/docsrc/html/changelog.html
浏览文件 @
f97ba1cb
...
@@ -18,7 +18,8 @@ Change Log
...
@@ -18,7 +18,8 @@ Change Log
<h1>
Change Log
</h1>
<h1>
Change Log
</h1>
<h2>
Next Version (unreleased)
</h2>
<h2>
Next Version (unreleased)
</h2>
<ul><li>
The build tool now uses JAVA_HOME for javac as well. Issue 233.
<ul><li>
PreparedStatement.getMetaData() was not always consistent with resulting ResultSet.getMetaData().
</li><li>
The build tool now uses JAVA_HOME for javac as well. Issue 233.
</li><li>
Opening and closing encrypted databases is now much faster.
</li><li>
Opening and closing encrypted databases is now much faster.
</li><li>
H2 Console: new experimental feature to support file download and upload,
</li><li>
H2 Console: new experimental feature to support file download and upload,
but only if there is a directory called "transfer" in the current working directory.
but only if there is a directory called "transfer" in the current working directory.
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/command/dml/Call.java
浏览文件 @
f97ba1cb
...
@@ -11,11 +11,10 @@ import org.h2.command.CommandInterface;
...
@@ -11,11 +11,10 @@ import org.h2.command.CommandInterface;
import
org.h2.command.Prepared
;
import
org.h2.command.Prepared
;
import
org.h2.engine.Session
;
import
org.h2.engine.Session
;
import
org.h2.expression.Expression
;
import
org.h2.expression.Expression
;
import
org.h2.expression.ExpressionColumn
;
import
org.h2.expression.ExpressionVisitor
;
import
org.h2.expression.ExpressionVisitor
;
import
org.h2.message.DbException
;
import
org.h2.result.LocalResult
;
import
org.h2.result.LocalResult
;
import
org.h2.result.ResultInterface
;
import
org.h2.result.ResultInterface
;
import
org.h2.table.Column
;
import
org.h2.value.Value
;
import
org.h2.value.Value
;
import
org.h2.value.ValueArray
;
import
org.h2.value.ValueArray
;
import
org.h2.value.ValueResultSet
;
import
org.h2.value.ValueResultSet
;
...
@@ -26,7 +25,6 @@ import org.h2.value.ValueResultSet;
...
@@ -26,7 +25,6 @@ import org.h2.value.ValueResultSet;
*/
*/
public
class
Call
extends
Prepared
{
public
class
Call
extends
Prepared
{
private
Expression
expression
;
private
Expression
expression
;
private
Expression
[]
expressions
;
private
Expression
[]
expressions
;
...
@@ -35,7 +33,14 @@ public class Call extends Prepared {
...
@@ -35,7 +33,14 @@ public class Call extends Prepared {
}
}
public
ResultInterface
queryMeta
()
{
public
ResultInterface
queryMeta
()
{
LocalResult
result
=
new
LocalResult
(
session
,
expressions
,
1
);
int
expressionType
=
expression
.
getType
();
LocalResult
result
;
if
(
expressionType
==
Value
.
RESULT_SET
||
expressionType
==
Value
.
ARRAY
)
{
Expression
[]
expr
=
expression
.
getExpressionColumns
(
session
);
result
=
new
LocalResult
(
session
,
expr
,
expr
.
length
);
}
else
{
result
=
new
LocalResult
(
session
,
expressions
,
1
);
}
result
.
done
();
result
.
done
();
return
result
;
return
result
;
}
}
...
@@ -60,18 +65,17 @@ public class Call extends Prepared {
...
@@ -60,18 +65,17 @@ public class Call extends Prepared {
public
ResultInterface
query
(
int
maxrows
)
{
public
ResultInterface
query
(
int
maxrows
)
{
setCurrentRowNumber
(
1
);
setCurrentRowNumber
(
1
);
Value
v
=
expression
.
getValue
(
session
);
Value
v
=
expression
.
getValue
(
session
);
if
(
v
.
getType
()
==
Value
.
RESULT_SET
)
{
switch
(
expression
.
getType
())
{
case
Value
.
RESULT_SET
:
ResultSet
rs
=
((
ValueResultSet
)
v
).
getResultSet
();
ResultSet
rs
=
((
ValueResultSet
)
v
).
getResultSet
();
return
LocalResult
.
read
(
session
,
rs
,
maxrows
);
return
LocalResult
.
read
(
session
,
rs
,
maxrows
);
}
else
if
(
v
.
getType
()
==
Value
.
ARRAY
)
{
case
Value
.
ARRAY
:
Value
[]
list
=
((
ValueArray
)
v
).
getList
();
Value
[]
list
=
((
ValueArray
)
v
).
getList
();
Expression
[]
expr
=
new
Expression
[
list
.
length
];
Expression
[]
expr
=
expression
.
getExpressionColumns
(
session
);
for
(
int
i
=
0
;
i
<
list
.
length
;
i
++)
{
if
(
expr
.
length
!=
list
.
length
)
{
Value
e
=
list
[
i
];
throw
DbException
.
throwInternalError
();
Column
col
=
new
Column
(
"C"
+
(
i
+
1
),
e
.
getType
(),
e
.
getPrecision
(),
e
.
getScale
(),
e
.
getDisplaySize
());
expr
[
i
]
=
new
ExpressionColumn
(
session
.
getDatabase
(),
col
);
}
}
LocalResult
result
=
new
LocalResult
(
session
,
expr
,
list
.
length
);
LocalResult
result
=
new
LocalResult
(
session
,
expr
,
expr
.
length
);
result
.
addRow
(
list
);
result
.
addRow
(
list
);
result
.
done
();
result
.
done
();
return
result
;
return
result
;
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/expression/Expression.java
浏览文件 @
f97ba1cb
...
@@ -6,12 +6,18 @@
...
@@ -6,12 +6,18 @@
*/
*/
package
org
.
h2
.
expression
;
package
org
.
h2
.
expression
;
import
java.sql.ResultSet
;
import
java.sql.ResultSetMetaData
;
import
java.sql.SQLException
;
import
org.h2.engine.Database
;
import
org.h2.engine.Session
;
import
org.h2.engine.Session
;
import
org.h2.table.Column
;
import
org.h2.table.Column
;
import
org.h2.table.ColumnResolver
;
import
org.h2.table.ColumnResolver
;
import
org.h2.table.TableFilter
;
import
org.h2.table.TableFilter
;
import
org.h2.util.StringUtils
;
import
org.h2.util.StringUtils
;
import
org.h2.value.DataType
;
import
org.h2.value.Value
;
import
org.h2.value.Value
;
import
org.h2.value.ValueArray
;
/**
/**
* An expression is a operation, a value, or a function in a query.
* An expression is a operation, a value, or a function in a query.
...
@@ -292,4 +298,58 @@ public abstract class Expression {
...
@@ -292,4 +298,58 @@ public abstract class Expression {
return
getSQL
();
return
getSQL
();
}
}
/**
* If this expression consists of column expressions it should return them.
*
* @return array of expression columns if applicable, null otherwise
*/
public
Expression
[]
getExpressionColumns
(
Session
session
)
{
return
null
;
}
/**
* Extracts expression columns from ValueArray
*
* @param session the current session
* @param value the value to extract columns from
* @return array of expression columns
*/
public
static
Expression
[]
getExpressionColumns
(
Session
session
,
ValueArray
value
)
{
Value
[]
list
=
value
.
getList
();
ExpressionColumn
[]
expr
=
new
ExpressionColumn
[
list
.
length
];
for
(
int
i
=
0
;
i
<
list
.
length
;
i
++)
{
Value
v
=
list
[
i
];
Column
col
=
new
Column
(
"C"
+
(
i
+
1
),
v
.
getType
(),
v
.
getPrecision
(),
v
.
getScale
(),
v
.
getDisplaySize
());
expr
[
i
]
=
new
ExpressionColumn
(
session
.
getDatabase
(),
col
);
}
return
expr
;
}
/**
* Extracts expression columns from the given result set.
*
* @param session the session
* @param rs the result set
* @return an array of expression columns
* @throws SQLException
*/
public
static
Expression
[]
getExpressionColumns
(
Session
session
,
ResultSet
rs
)
throws
SQLException
{
ResultSetMetaData
meta
=
rs
.
getMetaData
();
int
columnCount
=
meta
.
getColumnCount
();
Expression
[]
expressions
=
new
Expression
[
columnCount
];
Database
db
=
session
==
null
?
null
:
session
.
getDatabase
();
for
(
int
i
=
0
;
i
<
columnCount
;
i
++)
{
String
name
=
meta
.
getColumnLabel
(
i
+
1
);
int
type
=
DataType
.
convertSQLTypeToValueType
(
meta
.
getColumnType
(
i
+
1
));
int
precision
=
meta
.
getPrecision
(
i
+
1
);
int
scale
=
meta
.
getScale
(
i
+
1
);
int
displaySize
=
meta
.
getColumnDisplaySize
(
i
+
1
);
Column
col
=
new
Column
(
name
,
type
,
precision
,
scale
,
displaySize
);
Expression
expr
=
new
ExpressionColumn
(
db
,
col
);
expressions
[
i
]
=
expr
;
}
return
expressions
;
}
}
}
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/expression/ExpressionList.java
浏览文件 @
f97ba1cb
...
@@ -7,6 +7,7 @@
...
@@ -7,6 +7,7 @@
package
org
.
h2
.
expression
;
package
org
.
h2
.
expression
;
import
org.h2.engine.Session
;
import
org.h2.engine.Session
;
import
org.h2.table.Column
;
import
org.h2.table.ColumnResolver
;
import
org.h2.table.ColumnResolver
;
import
org.h2.table.TableFilter
;
import
org.h2.table.TableFilter
;
import
org.h2.util.StatementBuilder
;
import
org.h2.util.StatementBuilder
;
...
@@ -108,4 +109,15 @@ public class ExpressionList extends Expression {
...
@@ -108,4 +109,15 @@ public class ExpressionList extends Expression {
return
cost
;
return
cost
;
}
}
public
Expression
[]
getExpressionColumns
(
Session
session
)
{
ExpressionColumn
[]
expr
=
new
ExpressionColumn
[
list
.
length
];
for
(
int
i
=
0
;
i
<
list
.
length
;
i
++)
{
Expression
e
=
list
[
i
];
Column
col
=
new
Column
(
"C"
+
(
i
+
1
),
e
.
getType
(),
e
.
getPrecision
(),
e
.
getScale
(),
e
.
getDisplaySize
());
expr
[
i
]
=
new
ExpressionColumn
(
session
.
getDatabase
(),
col
);
}
return
expr
;
}
}
}
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/expression/JavaFunction.java
浏览文件 @
f97ba1cb
...
@@ -6,16 +6,19 @@
...
@@ -6,16 +6,19 @@
*/
*/
package
org
.
h2
.
expression
;
package
org
.
h2
.
expression
;
import
java.sql.SQLException
;
import
org.h2.command.Parser
;
import
org.h2.command.Parser
;
import
org.h2.constant.SysProperties
;
import
org.h2.constant.SysProperties
;
import
org.h2.engine.Constants
;
import
org.h2.engine.Constants
;
import
org.h2.engine.FunctionAlias
;
import
org.h2.engine.FunctionAlias
;
import
org.h2.engine.Session
;
import
org.h2.engine.Session
;
import
org.h2.message.DbException
;
import
org.h2.table.ColumnResolver
;
import
org.h2.table.ColumnResolver
;
import
org.h2.table.TableFilter
;
import
org.h2.table.TableFilter
;
import
org.h2.util.StatementBuilder
;
import
org.h2.util.StatementBuilder
;
import
org.h2.value.DataType
;
import
org.h2.value.DataType
;
import
org.h2.value.Value
;
import
org.h2.value.Value
;
import
org.h2.value.ValueArray
;
import
org.h2.value.ValueNull
;
import
org.h2.value.ValueNull
;
import
org.h2.value.ValueResultSet
;
import
org.h2.value.ValueResultSet
;
...
@@ -154,4 +157,18 @@ public class JavaFunction extends Expression implements FunctionCall {
...
@@ -154,4 +157,18 @@ public class JavaFunction extends Expression implements FunctionCall {
return
functionAlias
.
isDeterministic
();
return
functionAlias
.
isDeterministic
();
}
}
public
Expression
[]
getExpressionColumns
(
Session
session
)
{
switch
(
getType
())
{
case
Value
.
RESULT_SET
:
ValueResultSet
vrs
=
getValueForColumnList
(
session
,
getArgs
());
try
{
return
getExpressionColumns
(
session
,
vrs
.
getResultSet
());
}
catch
(
SQLException
e
)
{
throw
DbException
.
convert
(
e
);
}
case
Value
.
ARRAY
:
return
getExpressionColumns
(
session
,
(
ValueArray
)
getValue
(
session
));
}
return
super
.
getExpressionColumns
(
session
);
}
}
}
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/expression/Subquery.java
浏览文件 @
f97ba1cb
...
@@ -6,6 +6,7 @@
...
@@ -6,6 +6,7 @@
*/
*/
package
org
.
h2
.
expression
;
package
org
.
h2
.
expression
;
import
java.util.ArrayList
;
import
org.h2.command.dml.Query
;
import
org.h2.command.dml.Query
;
import
org.h2.constant.ErrorCode
;
import
org.h2.constant.ErrorCode
;
import
org.h2.engine.Session
;
import
org.h2.engine.Session
;
...
@@ -24,6 +25,7 @@ import org.h2.value.ValueNull;
...
@@ -24,6 +25,7 @@ import org.h2.value.ValueNull;
public
class
Subquery
extends
Expression
{
public
class
Subquery
extends
Expression
{
private
Query
query
;
private
Query
query
;
private
Expression
expression
;
public
Subquery
(
Query
query
)
{
public
Subquery
(
Query
query
)
{
this
.
query
=
query
;
this
.
query
=
query
;
...
@@ -93,7 +95,20 @@ public class Subquery extends Expression {
...
@@ -93,7 +95,20 @@ public class Subquery extends Expression {
}
}
private
Expression
getExpression
()
{
private
Expression
getExpression
()
{
return
query
.
getExpressions
().
get
(
0
);
if
(
expression
==
null
)
{
ArrayList
<
Expression
>
exprs
=
query
.
getExpressions
();
int
columnCount
=
query
.
getColumnCount
();
if
(
columnCount
==
1
)
{
expression
=
exprs
.
get
(
0
);
}
else
{
Expression
[]
list
=
new
Expression
[
columnCount
];
for
(
int
i
=
0
;
i
<
columnCount
;
i
++)
{
list
[
i
]
=
exprs
.
get
(
i
);
}
expression
=
new
ExpressionList
(
list
);
}
}
return
expression
;
}
}
public
boolean
isEverything
(
ExpressionVisitor
visitor
)
{
public
boolean
isEverything
(
ExpressionVisitor
visitor
)
{
...
@@ -108,4 +123,7 @@ public class Subquery extends Expression {
...
@@ -108,4 +123,7 @@ public class Subquery extends Expression {
return
10
+
(
int
)
(
10
*
query
.
getCost
());
return
10
+
(
int
)
(
10
*
query
.
getCost
());
}
}
public
Expression
[]
getExpressionColumns
(
Session
session
)
{
return
getExpression
().
getExpressionColumns
(
session
);
}
}
}
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/expression/TableFunction.java
浏览文件 @
f97ba1cb
...
@@ -6,6 +6,7 @@
...
@@ -6,6 +6,7 @@
*/
*/
package
org
.
h2
.
expression
;
package
org
.
h2
.
expression
;
import
java.sql.SQLException
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
org.h2.constant.ErrorCode
;
import
org.h2.constant.ErrorCode
;
import
org.h2.engine.Database
;
import
org.h2.engine.Database
;
...
@@ -148,4 +149,11 @@ public class TableFunction extends Function {
...
@@ -148,4 +149,11 @@ public class TableFunction extends Function {
return
rowCount
;
return
rowCount
;
}
}
public
Expression
[]
getExpressionColumns
(
Session
session
)
{
try
{
return
getExpressionColumns
(
session
,
getTable
(
session
,
getArgs
(),
true
,
false
).
getResultSet
());
}
catch
(
SQLException
e
)
{
throw
DbException
.
convert
(
e
);
}
}
}
}
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/expression/ValueExpression.java
浏览文件 @
f97ba1cb
...
@@ -12,6 +12,7 @@ import org.h2.message.DbException;
...
@@ -12,6 +12,7 @@ import org.h2.message.DbException;
import
org.h2.table.ColumnResolver
;
import
org.h2.table.ColumnResolver
;
import
org.h2.table.TableFilter
;
import
org.h2.table.TableFilter
;
import
org.h2.value.Value
;
import
org.h2.value.Value
;
import
org.h2.value.ValueArray
;
import
org.h2.value.ValueBoolean
;
import
org.h2.value.ValueBoolean
;
import
org.h2.value.ValueNull
;
import
org.h2.value.ValueNull
;
...
@@ -153,4 +154,10 @@ public class ValueExpression extends Expression {
...
@@ -153,4 +154,10 @@ public class ValueExpression extends Expression {
return
0
;
return
0
;
}
}
public
Expression
[]
getExpressionColumns
(
Session
session
)
{
if
(
getType
()
==
Value
.
ARRAY
)
{
return
getExpressionColumns
(
session
,
(
ValueArray
)
getValue
(
session
));
}
return
super
.
getExpressionColumns
(
session
);
}
}
}
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/result/LocalResult.java
浏览文件 @
f97ba1cb
...
@@ -7,16 +7,12 @@
...
@@ -7,16 +7,12 @@
package
org
.
h2
.
result
;
package
org
.
h2
.
result
;
import
java.sql.ResultSet
;
import
java.sql.ResultSet
;
import
java.sql.ResultSetMetaData
;
import
java.sql.SQLException
;
import
java.sql.SQLException
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
org.h2.constant.SysProperties
;
import
org.h2.constant.SysProperties
;
import
org.h2.engine.Database
;
import
org.h2.engine.Session
;
import
org.h2.engine.Session
;
import
org.h2.expression.Expression
;
import
org.h2.expression.Expression
;
import
org.h2.expression.ExpressionColumn
;
import
org.h2.message.DbException
;
import
org.h2.message.DbException
;
import
org.h2.table.Column
;
import
org.h2.util.New
;
import
org.h2.util.New
;
import
org.h2.util.ValueHashMap
;
import
org.h2.util.ValueHashMap
;
import
org.h2.value.DataType
;
import
org.h2.value.DataType
;
...
@@ -83,7 +79,7 @@ public class LocalResult implements ResultInterface {
...
@@ -83,7 +79,7 @@ public class LocalResult implements ResultInterface {
*/
*/
public
static
LocalResult
read
(
Session
session
,
ResultSet
rs
,
int
maxrows
)
{
public
static
LocalResult
read
(
Session
session
,
ResultSet
rs
,
int
maxrows
)
{
try
{
try
{
Expression
[]
cols
=
getExpressionColumns
(
session
,
rs
);
Expression
[]
cols
=
Expression
.
getExpressionColumns
(
session
,
rs
);
int
columnCount
=
cols
.
length
;
int
columnCount
=
cols
.
length
;
LocalResult
result
=
new
LocalResult
(
session
,
cols
,
columnCount
);
LocalResult
result
=
new
LocalResult
(
session
,
cols
,
columnCount
);
for
(
int
i
=
0
;
(
maxrows
==
0
||
i
<
maxrows
)
&&
rs
.
next
();
i
++)
{
for
(
int
i
=
0
;
(
maxrows
==
0
||
i
<
maxrows
)
&&
rs
.
next
();
i
++)
{
...
@@ -101,24 +97,6 @@ public class LocalResult implements ResultInterface {
...
@@ -101,24 +97,6 @@ public class LocalResult implements ResultInterface {
}
}
}
}
private
static
Expression
[]
getExpressionColumns
(
Session
session
,
ResultSet
rs
)
throws
SQLException
{
ResultSetMetaData
meta
=
rs
.
getMetaData
();
int
columnCount
=
meta
.
getColumnCount
();
Expression
[]
expressions
=
new
Expression
[
columnCount
];
Database
db
=
session
==
null
?
null
:
session
.
getDatabase
();
for
(
int
i
=
0
;
i
<
columnCount
;
i
++)
{
String
name
=
meta
.
getColumnLabel
(
i
+
1
);
int
type
=
DataType
.
convertSQLTypeToValueType
(
meta
.
getColumnType
(
i
+
1
));
int
precision
=
meta
.
getPrecision
(
i
+
1
);
int
scale
=
meta
.
getScale
(
i
+
1
);
int
displaySize
=
meta
.
getColumnDisplaySize
(
i
+
1
);
Column
col
=
new
Column
(
name
,
type
,
precision
,
scale
,
displaySize
);
Expression
expr
=
new
ExpressionColumn
(
db
,
col
);
expressions
[
i
]
=
expr
;
}
return
expressions
;
}
/**
/**
* Create a shallow copy of the result set. The data and a temporary table
* Create a shallow copy of the result set. The data and a temporary table
* (if there is any) is not copied.
* (if there is any) is not copied.
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论