Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
24441340
提交
24441340
authored
1月 24, 2018
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Implement setBytes() and setString() with offset and len
上级
d0c4f550
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
72 行增加
和
20 行删除
+72
-20
JdbcBlob.java
h2/src/main/org/h2/jdbc/JdbcBlob.java
+14
-2
JdbcClob.java
h2/src/main/org/h2/jdbc/JdbcClob.java
+25
-2
TestLobApi.java
h2/src/test/org/h2/test/jdbc/TestLobApi.java
+33
-16
没有找到文件。
h2/src/main/org/h2/jdbc/JdbcBlob.java
浏览文件 @
24441340
...
...
@@ -125,7 +125,7 @@ public class JdbcBlob extends TraceObject implements Blob {
}
/**
*
[Not supported]
Sets some bytes of the object.
* Sets some bytes of the object.
*
* @param pos the write position
* @param bytes the bytes to set
...
...
@@ -136,7 +136,19 @@ public class JdbcBlob extends TraceObject implements Blob {
@Override
public
int
setBytes
(
long
pos
,
byte
[]
bytes
,
int
offset
,
int
len
)
throws
SQLException
{
throw
unsupported
(
"LOB update"
);
try
{
if
(
isDebugEnabled
())
{
debugCode
(
"setBytes("
+
pos
+
", "
+
quoteBytes
(
bytes
)
+
", "
+
offset
+
", "
+
len
+
");"
);
}
checkClosed
();
if
(
pos
!=
1
)
{
throw
DbException
.
getInvalidValueException
(
"pos"
,
pos
);
}
value
=
conn
.
createBlob
(
new
ByteArrayInputStream
(
bytes
,
offset
,
len
),
-
1
);
return
(
int
)
value
.
getPrecision
();
}
catch
(
Exception
e
)
{
throw
logAndConvert
(
e
);
}
}
/**
...
...
h2/src/main/org/h2/jdbc/JdbcClob.java
浏览文件 @
24441340
...
...
@@ -21,6 +21,7 @@ import org.h2.api.ErrorCode;
import
org.h2.engine.Constants
;
import
org.h2.message.DbException
;
import
org.h2.message.TraceObject
;
import
org.h2.store.RangeReader
;
import
org.h2.util.IOUtils
;
import
org.h2.util.Task
;
import
org.h2.value.Value
;
...
...
@@ -227,12 +228,34 @@ public class JdbcClob extends TraceObject implements NClob
}
/**
* [Not supported] Sets a substring.
* Fills the Clob. This is only supported for new, empty Clob objects that
* were created with Connection.createClob() or createNClob(). The position
* must be 1, meaning the whole Clob data is set.
*
* @param pos where to start writing (the first character is at position 1)
* @param str the string to add
* @param offset the string offset
* @param len the number of characters to read
* @return the length of the added text
*/
@Override
public
int
setString
(
long
pos
,
String
str
,
int
offset
,
int
len
)
throws
SQLException
{
throw
unsupported
(
"LOB update"
);
try
{
if
(
isDebugEnabled
())
{
debugCode
(
"setString("
+
pos
+
", "
+
quote
(
str
)
+
", "
+
offset
+
", "
+
len
+
");"
);
}
checkClosed
();
if
(
pos
!=
1
)
{
throw
DbException
.
getInvalidValueException
(
"pos"
,
pos
);
}
else
if
(
str
==
null
)
{
throw
DbException
.
getInvalidValueException
(
"str"
,
str
);
}
value
=
conn
.
createClob
(
new
RangeReader
(
new
StringReader
(
str
),
offset
,
len
),
-
1
);
return
(
int
)
value
.
getPrecision
();
}
catch
(
Exception
e
)
{
throw
logAndConvert
(
e
);
}
}
/**
...
...
h2/src/test/org/h2/test/jdbc/TestLobApi.java
浏览文件 @
24441340
...
...
@@ -86,8 +86,6 @@ public class TestLobApi extends TestBase {
truncate
(
0
);
assertThrows
(
ErrorCode
.
FEATURE_NOT_SUPPORTED_1
,
clob
).
setAsciiStream
(
1
);
assertThrows
(
ErrorCode
.
FEATURE_NOT_SUPPORTED_1
,
clob
).
setString
(
1
,
""
,
0
,
1
);
assertThrows
(
ErrorCode
.
FEATURE_NOT_SUPPORTED_1
,
clob
).
position
(
""
,
0
);
assertThrows
(
ErrorCode
.
FEATURE_NOT_SUPPORTED_1
,
clob
).
...
...
@@ -96,8 +94,6 @@ public class TestLobApi extends TestBase {
Blob
blob
=
rs
.
getBlob
(
3
);
assertThrows
(
ErrorCode
.
FEATURE_NOT_SUPPORTED_1
,
blob
).
truncate
(
0
);
assertThrows
(
ErrorCode
.
FEATURE_NOT_SUPPORTED_1
,
blob
).
setBytes
(
1
,
new
byte
[
0
],
0
,
0
);
assertThrows
(
ErrorCode
.
FEATURE_NOT_SUPPORTED_1
,
blob
).
position
(
new
byte
[
1
],
0
);
assertThrows
(
ErrorCode
.
FEATURE_NOT_SUPPORTED_1
,
blob
).
...
...
@@ -237,30 +233,43 @@ public class TestLobApi extends TestBase {
prep
.
setInt
(
1
,
2
);
b
=
conn
.
createBlob
();
b
.
setBytes
(
1
,
data
);
assertEquals
(
length
,
b
.
setBytes
(
1
,
data
)
);
prep
.
setBlob
(
2
,
b
);
prep
.
execute
();
prep
.
setInt
(
1
,
3
);
prep
.
setBlob
(
2
,
new
ByteArrayInputStream
(
data
));
Blob
b2
=
conn
.
createBlob
();
byte
[]
xdata
=
new
byte
[
length
+
2
];
System
.
arraycopy
(
data
,
0
,
xdata
,
1
,
length
);
assertEquals
(
length
,
b2
.
setBytes
(
1
,
xdata
,
1
,
length
));
prep
.
setBlob
(
2
,
b2
);
prep
.
execute
();
prep
.
setInt
(
1
,
4
);
prep
.
setBlob
(
2
,
new
ByteArrayInputStream
(
data
));
prep
.
execute
();
prep
.
setInt
(
1
,
5
);
prep
.
setBlob
(
2
,
new
ByteArrayInputStream
(
data
),
-
1
);
prep
.
execute
();
ResultSet
rs
;
rs
=
stat
.
executeQuery
(
"select * from test"
);
rs
.
next
();
Blob
b
2
=
rs
.
getBlob
(
2
);
assertEquals
(
length
,
b
2
.
length
());
Blob
b
3
=
rs
.
getBlob
(
2
);
assertEquals
(
length
,
b
3
.
length
());
byte
[]
bytes
=
b
.
getBytes
(
1
,
length
);
byte
[]
bytes2
=
b2
.
getBytes
(
1
,
length
);
byte
[]
bytes2
=
b3
.
getBytes
(
1
,
length
);
assertEquals
(
bytes
,
bytes2
);
rs
.
next
();
b3
=
rs
.
getBlob
(
2
);
assertEquals
(
length
,
b3
.
length
());
bytes2
=
b3
.
getBytes
(
1
,
length
);
assertEquals
(
bytes
,
bytes2
);
rs
.
next
();
b
2
=
rs
.
getBlob
(
2
);
assertEquals
(
length
,
b
2
.
length
());
bytes2
=
b
2
.
getBytes
(
1
,
length
);
b
3
=
rs
.
getBlob
(
2
);
assertEquals
(
length
,
b
3
.
length
());
bytes2
=
b
3
.
getBytes
(
1
,
length
);
assertEquals
(
bytes
,
bytes2
);
while
(
rs
.
next
())
{
bytes2
=
rs
.
getBytes
(
2
);
...
...
@@ -311,20 +320,28 @@ public class TestLobApi extends TestBase {
NClob
nc
;
nc
=
conn
.
createNClob
();
nc
.
setString
(
1
,
new
String
(
data
));
assertEquals
(
length
,
nc
.
setString
(
1
,
new
String
(
data
)
));
prep
.
setInt
(
1
,
5
);
prep
.
setNClob
(
2
,
nc
);
prep
.
execute
();
prep
.
setInt
(
1
,
5
);
nc
=
conn
.
createNClob
();
char
[]
xdata
=
new
char
[
length
+
2
];
System
.
arraycopy
(
data
,
0
,
xdata
,
1
,
length
);
assertEquals
(
length
,
nc
.
setString
(
1
,
new
String
(
xdata
),
1
,
length
));
prep
.
setInt
(
1
,
6
);
prep
.
setNClob
(
2
,
nc
);
prep
.
execute
();
prep
.
setInt
(
1
,
7
);
prep
.
setNClob
(
2
,
new
StringReader
(
new
String
(
data
)));
prep
.
execute
();
prep
.
setInt
(
1
,
6
);
prep
.
setInt
(
1
,
8
);
prep
.
setNClob
(
2
,
new
StringReader
(
new
String
(
data
)),
-
1
);
prep
.
execute
();
prep
.
setInt
(
1
,
7
);
prep
.
setInt
(
1
,
9
);
prep
.
setNString
(
2
,
new
String
(
data
));
prep
.
execute
();
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论