Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
f75c1e88
提交
f75c1e88
authored
6 年前
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Do not use SimpleResultSet in JdbcArray and remove incorrect bound check
上级
18a3975b
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
37 行增加
和
26 行删除
+37
-26
JdbcArray.java
h2/src/main/org/h2/jdbc/JdbcArray.java
+36
-25
TestFunctions.java
h2/src/test/org/h2/test/db/TestFunctions.java
+1
-1
没有找到文件。
h2/src/main/org/h2/jdbc/JdbcArray.java
浏览文件 @
f75c1e88
...
...
@@ -9,21 +9,22 @@ import java.sql.Array;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
import
java.sql.Types
;
import
java.util.Arrays
;
import
java.util.Map
;
import
org.h2.api.ErrorCode
;
import
org.h2.message.DbException
;
import
org.h2.message.TraceObject
;
import
org.h2.
tools.SimpleResultSe
t
;
import
org.h2.
result.SimpleResul
t
;
import
org.h2.value.Value
;
import
org.h2.value.ValueArray
;
import
org.h2.value.ValueLong
;
/**
* Represents an ARRAY value.
*/
public
class
JdbcArray
extends
TraceObject
implements
Array
{
private
Value
value
;
private
Value
Array
value
;
private
final
JdbcConnection
conn
;
/**
...
...
@@ -32,7 +33,7 @@ public class JdbcArray extends TraceObject implements Array {
public
JdbcArray
(
JdbcConnection
conn
,
Value
value
,
int
id
)
{
setTrace
(
conn
.
getSession
().
getTrace
(),
TraceObject
.
ARRAY
,
id
);
this
.
conn
=
conn
;
this
.
value
=
value
;
this
.
value
=
(
ValueArray
)
value
.
convertTo
(
Value
.
ARRAY
)
;
}
/**
...
...
@@ -166,7 +167,7 @@ public class JdbcArray extends TraceObject implements Array {
try
{
debugCodeCall
(
"getResultSet"
);
checkClosed
();
return
getResultSet
(
get
(),
0
);
return
getResultSet
Impl
(
1L
,
Integer
.
MAX_VALUE
);
}
catch
(
Exception
e
)
{
throw
logAndConvert
(
e
);
}
...
...
@@ -187,7 +188,7 @@ public class JdbcArray extends TraceObject implements Array {
}
checkClosed
();
JdbcConnection
.
checkMap
(
map
);
return
getResultSet
(
get
(),
0
);
return
getResultSet
Impl
(
1L
,
Integer
.
MAX_VALUE
);
}
catch
(
Exception
e
)
{
throw
logAndConvert
(
e
);
}
...
...
@@ -210,7 +211,7 @@ public class JdbcArray extends TraceObject implements Array {
debugCode
(
"getResultSet("
+
index
+
", "
+
count
+
");"
);
}
checkClosed
();
return
getResultSet
(
get
(
index
,
count
),
index
-
1
);
return
getResultSet
Impl
(
index
,
count
);
}
catch
(
Exception
e
)
{
throw
logAndConvert
(
e
);
}
...
...
@@ -237,7 +238,7 @@ public class JdbcArray extends TraceObject implements Array {
}
checkClosed
();
JdbcConnection
.
checkMap
(
map
);
return
getResultSet
(
get
(
index
,
count
),
index
-
1
);
return
getResultSet
Impl
(
index
,
count
);
}
catch
(
Exception
e
)
{
throw
logAndConvert
(
e
);
}
...
...
@@ -252,15 +253,18 @@ public class JdbcArray extends TraceObject implements Array {
value
=
null
;
}
private
static
ResultSet
getResultSet
(
Object
[]
array
,
long
offset
)
{
SimpleResultSet
rs
=
new
SimpleResultSet
();
rs
.
addColumn
(
"INDEX"
,
Types
.
BIGINT
,
0
,
0
);
private
ResultSet
getResultSetImpl
(
long
index
,
int
count
)
{
int
id
=
getNextId
(
TraceObject
.
RESULT_SET
);
SimpleResult
rs
=
new
SimpleResult
();
rs
.
addColumn
(
"INDEX"
,
"INDEX"
,
Value
.
LONG
,
0
,
0
,
ValueLong
.
DISPLAY_SIZE
);
// TODO array result set: there are multiple data types possible
rs
.
addColumn
(
"VALUE"
,
Types
.
NULL
,
0
,
0
);
for
(
int
i
=
0
;
i
<
array
.
length
;
i
++)
{
rs
.
addRow
(
offset
+
i
+
1
,
array
[
i
]);
rs
.
addColumn
(
"VALUE"
,
"VALUE"
,
Value
.
NULL
,
0
,
0
,
15
);
Value
[]
values
=
value
.
getList
();
count
=
checkRange
(
index
,
count
,
values
.
length
);
for
(
int
i
=
(
int
)
index
;
i
<
index
+
count
;
i
++)
{
rs
.
addRow
(
ValueLong
.
get
(
i
),
values
[
i
-
1
]);
}
return
rs
;
return
new
JdbcResultSet
(
conn
,
null
,
null
,
rs
,
id
,
false
,
true
,
false
)
;
}
private
void
checkClosed
()
{
...
...
@@ -271,21 +275,28 @@ public class JdbcArray extends TraceObject implements Array {
}
private
Object
[]
get
()
{
return
(
Object
[])
value
.
convertTo
(
Value
.
ARRAY
).
getObject
();
return
(
Object
[])
value
.
getObject
();
}
private
Object
[]
get
(
long
index
,
int
count
)
{
Object
[]
array
=
get
();
if
(
count
<
0
||
count
>
array
.
length
)
{
throw
DbException
.
getInvalidValueException
(
"count (1.."
+
array
.
length
+
")"
,
count
);
Value
[]
values
=
value
.
getList
();
count
=
checkRange
(
index
,
count
,
values
.
length
);
Object
[]
a
=
new
Object
[
count
];
for
(
int
i
=
0
,
j
=
(
int
)
index
-
1
;
i
<
count
;
i
++,
j
++)
{
a
[
i
]
=
values
[
j
].
getObject
();
}
if
(
index
<
1
||
index
>
array
.
length
)
{
throw
DbException
.
getInvalidValueException
(
"index (1.."
+
array
.
length
+
")"
,
index
);
return
a
;
}
int
offset
=
(
int
)
(
index
-
1
);
return
Arrays
.
copyOfRange
(
array
,
offset
,
offset
+
count
);
private
static
int
checkRange
(
long
index
,
int
count
,
int
len
)
{
if
(
index
<
1
||
index
>
len
)
{
throw
DbException
.
getInvalidValueException
(
"index (1.."
+
len
+
')'
,
index
);
}
int
rem
=
len
-
(
int
)
index
+
1
;
if
(
count
<
0
)
{
throw
DbException
.
getInvalidValueException
(
"count (0.."
+
rem
+
')'
,
count
);
}
return
Math
.
min
(
rem
,
count
);
}
/**
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/db/TestFunctions.java
浏览文件 @
f75c1e88
...
...
@@ -963,7 +963,7 @@ public class TestFunctions extends TestDb implements AggregateFunction {
assertEquals
(
0
,
((
Integer
)
array
[
0
]).
intValue
());
assertEquals
(
"Hello"
,
(
String
)
array
[
1
]);
assertThrows
(
ErrorCode
.
INVALID_VALUE_2
,
a
).
getArray
(
1
,
-
1
);
assert
Throws
(
ErrorCode
.
INVALID_VALUE_2
,
a
).
getArray
(
1
,
3
);
assert
Equals
(
2
,
((
Object
[])
a
.
getArray
(
1
,
3
)).
length
);
assertEquals
(
0
,
((
Object
[])
a
.
getArray
(
1
,
0
)).
length
);
assertEquals
(
0
,
((
Object
[])
a
.
getArray
(
2
,
0
)).
length
);
assertThrows
(
ErrorCode
.
INVALID_VALUE_2
,
a
).
getArray
(
0
,
0
);
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论