提交 13ce9951 authored 作者: Thomas Mueller's avatar Thomas Mueller

Trying to convert a very small CLOB to a BLOB or a very small CLOB to a BLOB…

Trying to convert a very small CLOB to a BLOB or a very small CLOB to a BLOB threw a NullPointerException.
上级 de332566
......@@ -139,6 +139,10 @@ public class ValueLob extends Value {
*/
public static ValueLob createClob(Reader in, long length, DataHandler handler) {
try {
if (handler == null) {
String s = IOUtils.readStringAndClose(in, (int) length);
return createSmallLob(Value.CLOB, StringUtils.utf8Encode(s));
}
boolean compress = handler.getLobCompressionAlgorithm(Value.CLOB) != null;
long remaining = Long.MAX_VALUE;
if (length >= 0 && length < remaining) {
......@@ -336,6 +340,10 @@ public class ValueLob extends Value {
*/
public static ValueLob createBlob(InputStream in, long length, DataHandler handler) {
try {
if (handler == null) {
byte[] data = IOUtils.readBytesAndClose(in, (int) length);
return createSmallLob(Value.BLOB, data);
}
long remaining = Long.MAX_VALUE;
boolean compress = handler.getLobCompressionAlgorithm(Value.BLOB) != null;
if (length >= 0 && length < remaining) {
......@@ -600,7 +608,7 @@ public class ValueLob extends Value {
}
public Reader getReader() {
return IOUtils.getReader(getInputStream());
return IOUtils.getBufferedReader(getInputStream());
}
public InputStream getInputStream() {
......
......@@ -779,11 +779,11 @@ public class TestCases extends TestBase {
int len = getSize(1000, 66000);
char[] buff = new char[len];
// Unicode problem:
// The UCS code values 0xd800-0xdfff (UTF-16 surrogates)
// as well as 0xfffe and 0xffff (UCS non-characters)
// should not appear in conforming UTF-8 streams.
// (String.getBytes("UTF-8") only returns 1 byte for 0xd800-0xdfff)
Random random = new Random();
random.setSeed(1);
for (int i = 0; i < len; i++) {
......
......@@ -49,6 +49,7 @@ public class TestLob extends TestBase {
}
public void test() throws Exception {
testConvert();
testCreateAsSelect();
testDropAllObjects();
testDelete();
......@@ -84,6 +85,29 @@ public class TestLob extends TestBase {
FileSystem.getInstance(TEMP_DIR).deleteRecursive(TEMP_DIR, true);
}
private void testConvert() throws Exception {
deleteDb("lob");
Connection conn;
Statement stat;
conn = getConnection("lob");
stat = conn.createStatement();
stat.execute("create table test(id int, data blob)");
stat.execute("insert into test values(1, '')");
ResultSet rs;
rs = stat.executeQuery("select cast(data as clob) from test");
rs.next();
assertEquals("", rs.getString(1));
stat.execute("drop table test");
stat.execute("create table test(id int, data clob)");
stat.execute("insert into test values(1, '')");
rs = stat.executeQuery("select cast(data as blob) from test");
rs.next();
assertEquals("", rs.getString(1));
conn.close();
}
private void testCreateAsSelect() throws Exception {
deleteDb("lob");
Connection conn;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论