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

More tests

上级 9934cd5d
...@@ -82,7 +82,7 @@ public class TestCallableStatement extends TestBase { ...@@ -82,7 +82,7 @@ public class TestCallableStatement extends TestBase {
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, call).getObject("a", Collections.<String, Class<?>>emptyMap()); assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, call).getObject("a", Collections.<String, Class<?>>emptyMap());
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, call).getRef("a"); assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, call).getRef("a");
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, call).getRowId("a"); assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, call).getRowId("a");
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, call).getSQLXML(1); assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, call).getSQLXML("a");
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, call).setURL(1, (URL) null); assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, call).setURL(1, (URL) null);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, call).setRef(1, (Ref) null); assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, call).setRef(1, (Ref) null);
...@@ -312,4 +312,5 @@ public class TestCallableStatement extends TestBase { ...@@ -312,4 +312,5 @@ public class TestCallableStatement extends TestBase {
return TestCallableStatement.class; return TestCallableStatement.class;
} }
} }
} }
...@@ -45,6 +45,7 @@ public class TestLobApi extends TestBase { ...@@ -45,6 +45,7 @@ public class TestLobApi extends TestBase {
@Override @Override
public void test() throws Exception { public void test() throws Exception {
deleteDb("lob"); deleteDb("lob");
testUnsupportedOperations();
testLobStaysOpenUntilCommitted(); testLobStaysOpenUntilCommitted();
testInputStreamThrowsException(true); testInputStreamThrowsException(true);
testInputStreamThrowsException(false); testInputStreamThrowsException(false);
...@@ -64,6 +65,39 @@ public class TestLobApi extends TestBase { ...@@ -64,6 +65,39 @@ public class TestLobApi extends TestBase {
stat.execute("drop table test"); stat.execute("drop table test");
conn.close(); conn.close();
} }
private void testUnsupportedOperations() throws Exception {
Connection conn = getConnection("lob");
stat = conn.createStatement();
stat.execute("create table test(id int, c clob, b blob)");
stat.execute("insert into test values(1, 'x', x'00')");
ResultSet rs = stat.executeQuery("select * from test order by id");
rs.next();
Clob clob = rs.getClob(2);
assertTrue(clob.toString().endsWith("'x'"));
clob.free();
assertTrue(clob.toString().endsWith("null"));
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, clob).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).position((Clob) null, 0);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, clob).getCharacterStream(1, 1);
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).position((Blob) null, 0);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, blob).getBinaryStream(1, 1);
assertTrue(blob.toString().endsWith("X'00'"));
blob.free();
assertTrue(blob.toString().endsWith("null"));
stat.execute("drop table test");
conn.close();
}
/** /**
* According to the JDBC spec, BLOB and CLOB objects must stay open even if * According to the JDBC spec, BLOB and CLOB objects must stay open even if
......
...@@ -8,9 +8,11 @@ package org.h2.test.jdbc; ...@@ -8,9 +8,11 @@ package org.h2.test.jdbc;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader; import java.io.StringReader;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.net.URL; import java.net.URL;
import java.sql.Array;
import java.sql.Connection; import java.sql.Connection;
import java.sql.Date; import java.sql.Date;
import java.sql.ParameterMetaData; import java.sql.ParameterMetaData;
...@@ -95,6 +97,7 @@ public class TestPreparedStatement extends TestBase { ...@@ -95,6 +97,7 @@ public class TestPreparedStatement extends TestBase {
deleteDb("preparedStatement"); deleteDb("preparedStatement");
} }
@SuppressWarnings("deprecation")
private void testUnsupportedOperations(Connection conn) throws Exception { private void testUnsupportedOperations(Connection conn) throws Exception {
PreparedStatement prep = conn.prepareStatement("select ? from dual"); PreparedStatement prep = conn.prepareStatement("select ? from dual");
assertThrows(ErrorCode.METHOD_NOT_ALLOWED_FOR_PREPARED_STATEMENT, prep). assertThrows(ErrorCode.METHOD_NOT_ALLOWED_FOR_PREPARED_STATEMENT, prep).
...@@ -122,6 +125,10 @@ public class TestPreparedStatement extends TestBase { ...@@ -122,6 +125,10 @@ public class TestPreparedStatement extends TestBase {
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).
setRowId(1, (RowId) null); setRowId(1, (RowId) null);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, prep).
setUnicodeStream(1, (InputStream) null, 0);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, prep).
setArray(1, (Array) null);
} }
private static void testChangeType(Connection conn) throws SQLException { private static void testChangeType(Connection conn) throws SQLException {
......
...@@ -16,10 +16,14 @@ import java.sql.Array; ...@@ -16,10 +16,14 @@ import java.sql.Array;
import java.sql.Connection; import java.sql.Connection;
import java.sql.DatabaseMetaData; import java.sql.DatabaseMetaData;
import java.sql.Date; import java.sql.Date;
import java.sql.NClob;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.Ref;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.ResultSetMetaData; import java.sql.ResultSetMetaData;
import java.sql.RowId;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.SQLXML;
import java.sql.Statement; import java.sql.Statement;
import java.sql.Time; import java.sql.Time;
import java.sql.Timestamp; import java.sql.Timestamp;
...@@ -55,6 +59,7 @@ public class TestResultSet extends TestBase { ...@@ -55,6 +59,7 @@ public class TestResultSet extends TestBase {
stat = conn.createStatement(); stat = conn.createStatement();
testUnsupportedOperations();
testAmbiguousColumnNames(); testAmbiguousColumnNames();
testInsertRowWithUpdatableResultSetDefault(); testInsertRowWithUpdatableResultSetDefault();
testBeforeFirstAfterLast(); testBeforeFirstAfterLast();
...@@ -91,6 +96,39 @@ public class TestResultSet extends TestBase { ...@@ -91,6 +96,39 @@ public class TestResultSet extends TestBase {
deleteDb("resultSet"); deleteDb("resultSet");
} }
@SuppressWarnings("deprecation")
private void testUnsupportedOperations() throws SQLException {
ResultSet rs = stat.executeQuery("select 1 as x from dual");
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, rs).getUnicodeStream(1);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, rs).getUnicodeStream("x");
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, rs).
getObject(1, Collections.<String, Class<?>>emptyMap());
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, rs).
getObject("x", Collections.<String, Class<?>>emptyMap());
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, rs).getRef(1);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, rs).getRef("x");
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, rs).getURL(1);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, rs).getURL("x");
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, rs).getRowId(1);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, rs).getRowId("x");
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, rs).getSQLXML(1);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, rs).getSQLXML("x");
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, rs).updateRef(1, (Ref) null);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, rs).updateRef("x", (Ref) null);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, rs).updateArray(1, (Array) null);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, rs).updateArray("x", (Array) null);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, rs).updateRowId(1, (RowId) null);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, rs).updateRowId("x", (RowId) null);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, rs).updateNClob(1, (NClob) null);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, rs).updateNClob("x", (NClob) null);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, rs).updateSQLXML(1, (SQLXML) null);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, rs).updateSQLXML("x", (SQLXML) null);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, rs).getCursorName();
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, rs).setFetchDirection(ResultSet.FETCH_FORWARD);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, rs).unwrap(Object.class);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, rs).isWrapperFor(Object.class);
}
private void testAmbiguousColumnNames() throws SQLException { private void testAmbiguousColumnNames() throws SQLException {
stat.execute("create table test(id int)"); stat.execute("create table test(id int)");
...@@ -664,6 +702,7 @@ public class TestResultSet extends TestBase { ...@@ -664,6 +702,7 @@ public class TestResultSet extends TestBase {
assertResultSetMeta(rs, 2, new String[] { "ID", "VALUE" }, new int[] { Types.INTEGER, Types.DECIMAL }, new int[] { assertResultSetMeta(rs, 2, new String[] { "ID", "VALUE" }, new int[] { Types.INTEGER, Types.DECIMAL }, new int[] {
10, 10 }, new int[] { 0, 2 }); 10, 10 }, new int[] { 0, 2 });
BigDecimal bd; BigDecimal bd;
rs.next(); rs.next();
assertTrue(rs.getInt(1) == 1); assertTrue(rs.getInt(1) == 1);
assertTrue(!rs.wasNull()); assertTrue(!rs.wasNull());
...@@ -676,6 +715,7 @@ public class TestResultSet extends TestBase { ...@@ -676,6 +715,7 @@ public class TestResultSet extends TestBase {
trace(o.getClass().getName()); trace(o.getClass().getName());
assertTrue(o instanceof BigDecimal); assertTrue(o instanceof BigDecimal);
assertTrue(((BigDecimal) o).compareTo(new BigDecimal("-1.00")) == 0); assertTrue(((BigDecimal) o).compareTo(new BigDecimal("-1.00")) == 0);
rs.next(); rs.next();
assertTrue(rs.getInt(1) == 2); assertTrue(rs.getInt(1) == 2);
assertTrue(!rs.wasNull()); assertTrue(!rs.wasNull());
...@@ -684,16 +724,22 @@ public class TestResultSet extends TestBase { ...@@ -684,16 +724,22 @@ public class TestResultSet extends TestBase {
bd = rs.getBigDecimal(2); bd = rs.getBigDecimal(2);
assertTrue(bd.compareTo(new BigDecimal("0.00")) == 0); assertTrue(bd.compareTo(new BigDecimal("0.00")) == 0);
assertTrue(!rs.wasNull()); assertTrue(!rs.wasNull());
rs.next(); rs.next();
checkColumnBigDecimal(rs, 2, 1, "1.00"); checkColumnBigDecimal(rs, 2, 1, "1.00");
rs.next(); rs.next();
checkColumnBigDecimal(rs, 2, 12345679, "12345678.89"); checkColumnBigDecimal(rs, 2, 12345679, "12345678.89");
rs.next(); rs.next();
checkColumnBigDecimal(rs, 2, 99999999, "99999998.99"); checkColumnBigDecimal(rs, 2, 99999999, "99999998.99");
rs.next(); rs.next();
checkColumnBigDecimal(rs, 2, -99999999, "-99999998.99"); checkColumnBigDecimal(rs, 2, -99999999, "-99999998.99");
rs.next(); rs.next();
checkColumnBigDecimal(rs, 2, 0, null); checkColumnBigDecimal(rs, 2, 0, null);
assertTrue(!rs.next()); assertTrue(!rs.next());
stat.execute("DROP TABLE TEST"); stat.execute("DROP TABLE TEST");
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论