提交 57106638 authored 作者: Thomas Mueller's avatar Thomas Mueller

More tests

上级 a662ec86
...@@ -16,6 +16,7 @@ import java.io.Writer; ...@@ -16,6 +16,7 @@ import java.io.Writer;
import java.sql.Blob; import java.sql.Blob;
import java.sql.Clob; import java.sql.Clob;
import java.sql.Connection; import java.sql.Connection;
import java.sql.NClob;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.Statement; import java.sql.Statement;
...@@ -23,6 +24,7 @@ import java.util.Random; ...@@ -23,6 +24,7 @@ import java.util.Random;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.jdbc.JdbcConnection; import org.h2.jdbc.JdbcConnection;
import org.h2.test.TestBase; import org.h2.test.TestBase;
import org.h2.upgrade.v1_1.util.IOUtils;
/** /**
* Test the Blob, Clob, and NClob implementations. * Test the Blob, Clob, and NClob implementations.
...@@ -74,6 +76,8 @@ public class TestLobApi extends TestBase { ...@@ -74,6 +76,8 @@ public class TestLobApi extends TestBase {
ResultSet rs = stat.executeQuery("select * from test order by id"); ResultSet rs = stat.executeQuery("select * from test order by id");
rs.next(); rs.next();
Clob clob = rs.getClob(2); Clob clob = rs.getClob(2);
byte[] data = IOUtils.readBytesAndClose(clob.getAsciiStream(), -1);
assertEquals("x", new String(data, "UTF-8"));
assertTrue(clob.toString().endsWith("'x'")); assertTrue(clob.toString().endsWith("'x'"));
clob.free(); clob.free();
assertTrue(clob.toString().endsWith("null")); assertTrue(clob.toString().endsWith("null"));
...@@ -213,15 +217,26 @@ public class TestLobApi extends TestBase { ...@@ -213,15 +217,26 @@ public class TestLobApi extends TestBase {
out.write(data, 0, data.length); out.write(data, 0, data.length);
out.close(); out.close();
stat.execute("delete from test"); stat.execute("delete from test");
PreparedStatement prep = conn.prepareStatement("insert into test values(?, ?)"); PreparedStatement prep = conn.prepareStatement("insert into test values(?, ?)");
prep.setInt(1, 1); prep.setInt(1, 1);
prep.setBlob(2, b); prep.setBlob(2, b);
prep.execute(); prep.execute();
prep.setInt(1, 2); prep.setInt(1, 2);
b = conn.createBlob(); b = conn.createBlob();
b.setBytes(1, data); b.setBytes(1, data);
prep.setBlob(2, b); prep.setBlob(2, b);
prep.execute(); prep.execute();
prep.setInt(1, 3);
prep.setBlob(2, new ByteArrayInputStream(data));
prep.execute();
prep.setInt(1, 4);
prep.setBlob(2, new ByteArrayInputStream(data), -1);
prep.execute();
ResultSet rs; ResultSet rs;
rs = stat.executeQuery("select * from test"); rs = stat.executeQuery("select * from test");
rs.next(); rs.next();
...@@ -235,6 +250,10 @@ public class TestLobApi extends TestBase { ...@@ -235,6 +250,10 @@ public class TestLobApi extends TestBase {
assertEquals(length, b2.length()); assertEquals(length, b2.length());
bytes2 = b2.getBytes(1, length); bytes2 = b2.getBytes(1, length);
assertEquals(bytes, bytes2); assertEquals(bytes, bytes2);
while (rs.next()) {
bytes2 = rs.getBytes(2);
assertEquals(bytes, bytes2);
}
} }
private void testClob(int length) throws Exception { private void testClob(int length) throws Exception {
...@@ -259,14 +278,44 @@ public class TestLobApi extends TestBase { ...@@ -259,14 +278,44 @@ public class TestLobApi extends TestBase {
out.close(); out.close();
stat.execute("delete from test"); stat.execute("delete from test");
PreparedStatement prep = conn.prepareStatement("insert into test values(?, ?)"); PreparedStatement prep = conn.prepareStatement("insert into test values(?, ?)");
prep.setInt(1, 1); prep.setInt(1, 1);
prep.setClob(2, c); prep.setClob(2, c);
prep.execute(); prep.execute();
c = conn.createClob(); c = conn.createClob();
c.setString(1, new String(data)); c.setString(1, new String(data));
prep.setInt(1, 2); prep.setInt(1, 2);
prep.setClob(2, c); prep.setClob(2, c);
prep.execute(); prep.execute();
prep.setInt(1, 3);
prep.setCharacterStream(2, new StringReader(new String(data)));
prep.execute();
prep.setInt(1, 4);
prep.setCharacterStream(2, new StringReader(new String(data)), -1);
prep.execute();
NClob nc;
nc = conn.createNClob();
nc.setString(1, new String(data));
prep.setInt(1, 5);
prep.setNClob(2, nc);
prep.execute();
prep.setInt(1, 5);
prep.setNClob(2, new StringReader(new String(data)));
prep.execute();
prep.setInt(1, 6);
prep.setNClob(2, new StringReader(new String(data)), -1);
prep.execute();
prep.setInt(1, 7);
prep.setNString(2, new String(data));
prep.execute();
ResultSet rs; ResultSet rs;
rs = stat.executeQuery("select * from test"); rs = stat.executeQuery("select * from test");
rs.next(); rs.next();
...@@ -274,11 +323,12 @@ public class TestLobApi extends TestBase { ...@@ -274,11 +323,12 @@ public class TestLobApi extends TestBase {
assertEquals(length, c2.length()); assertEquals(length, c2.length());
String s = c.getSubString(1, length); String s = c.getSubString(1, length);
String s2 = c2.getSubString(1, length); String s2 = c2.getSubString(1, length);
rs.next(); while (rs.next()) {
c2 = rs.getClob(2); c2 = rs.getClob(2);
assertEquals(length, c2.length()); assertEquals(length, c2.length());
s2 = c2.getSubString(1, length); s2 = c2.getSubString(1, length);
assertEquals(s, s2); assertEquals(s, s2);
} }
}
} }
...@@ -121,6 +121,9 @@ public class TestPreparedStatement extends TestBase { ...@@ -121,6 +121,9 @@ public class TestPreparedStatement extends TestBase {
assertThrows(ErrorCode.METHOD_NOT_ALLOWED_FOR_PREPARED_STATEMENT, prep). assertThrows(ErrorCode.METHOD_NOT_ALLOWED_FOR_PREPARED_STATEMENT, prep).
execute("create table test(id int)", Statement.RETURN_GENERATED_KEYS); execute("create table test(id int)", Statement.RETURN_GENERATED_KEYS);
assertThrows(ErrorCode.METHOD_NOT_ALLOWED_FOR_PREPARED_STATEMENT, prep).
executeQuery("select * from dual");
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, prep). assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, prep).
setURL(1, new URL("http://www.acme.com")); setURL(1, new URL("http://www.acme.com"));
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, prep). assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, prep).
...@@ -841,6 +844,7 @@ public class TestPreparedStatement extends TestBase { ...@@ -841,6 +844,7 @@ public class TestPreparedStatement extends TestBase {
prep.setInt(2, 3); prep.setInt(2, 3);
prep.executeUpdate(); prep.executeUpdate();
prep.setInt(1, 4); prep.setInt(1, 4);
prep.setNull(2, Types.INTEGER, "INTEGER");
prep.setNull(2, Types.INTEGER); prep.setNull(2, Types.INTEGER);
prep.executeUpdate(); prep.executeUpdate();
prep.setInt(1, 5); prep.setInt(1, 5);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论