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

More tests

上级 9934cd5d
......@@ -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).getRef("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).setRef(1, (Ref) null);
......@@ -312,4 +312,5 @@ public class TestCallableStatement extends TestBase {
return TestCallableStatement.class;
}
}
}
......@@ -45,6 +45,7 @@ public class TestLobApi extends TestBase {
@Override
public void test() throws Exception {
deleteDb("lob");
testUnsupportedOperations();
testLobStaysOpenUntilCommitted();
testInputStreamThrowsException(true);
testInputStreamThrowsException(false);
......@@ -65,6 +66,39 @@ public class TestLobApi extends TestBase {
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
* the result set is closed (see ResultSet.close).
......
......@@ -8,9 +8,11 @@ package org.h2.test.jdbc;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
import java.math.BigDecimal;
import java.net.URL;
import java.sql.Array;
import java.sql.Connection;
import java.sql.Date;
import java.sql.ParameterMetaData;
......@@ -95,6 +97,7 @@ public class TestPreparedStatement extends TestBase {
deleteDb("preparedStatement");
}
@SuppressWarnings("deprecation")
private void testUnsupportedOperations(Connection conn) throws Exception {
PreparedStatement prep = conn.prepareStatement("select ? from dual");
assertThrows(ErrorCode.METHOD_NOT_ALLOWED_FOR_PREPARED_STATEMENT, prep).
......@@ -122,6 +125,10 @@ public class TestPreparedStatement extends TestBase {
setURL(1, new URL("http://www.acme.com"));
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, prep).
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 {
......
......@@ -16,10 +16,14 @@ import java.sql.Array;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.Date;
import java.sql.NClob;
import java.sql.PreparedStatement;
import java.sql.Ref;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.RowId;
import java.sql.SQLException;
import java.sql.SQLXML;
import java.sql.Statement;
import java.sql.Time;
import java.sql.Timestamp;
......@@ -55,6 +59,7 @@ public class TestResultSet extends TestBase {
stat = conn.createStatement();
testUnsupportedOperations();
testAmbiguousColumnNames();
testInsertRowWithUpdatableResultSetDefault();
testBeforeFirstAfterLast();
......@@ -92,6 +97,39 @@ public class TestResultSet extends TestBase {
}
@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 {
stat.execute("create table test(id int)");
stat.execute("insert into test values(1)");
......@@ -664,6 +702,7 @@ public class TestResultSet extends TestBase {
assertResultSetMeta(rs, 2, new String[] { "ID", "VALUE" }, new int[] { Types.INTEGER, Types.DECIMAL }, new int[] {
10, 10 }, new int[] { 0, 2 });
BigDecimal bd;
rs.next();
assertTrue(rs.getInt(1) == 1);
assertTrue(!rs.wasNull());
......@@ -676,6 +715,7 @@ public class TestResultSet extends TestBase {
trace(o.getClass().getName());
assertTrue(o instanceof BigDecimal);
assertTrue(((BigDecimal) o).compareTo(new BigDecimal("-1.00")) == 0);
rs.next();
assertTrue(rs.getInt(1) == 2);
assertTrue(!rs.wasNull());
......@@ -684,16 +724,22 @@ public class TestResultSet extends TestBase {
bd = rs.getBigDecimal(2);
assertTrue(bd.compareTo(new BigDecimal("0.00")) == 0);
assertTrue(!rs.wasNull());
rs.next();
checkColumnBigDecimal(rs, 2, 1, "1.00");
rs.next();
checkColumnBigDecimal(rs, 2, 12345679, "12345678.89");
rs.next();
checkColumnBigDecimal(rs, 2, 99999999, "99999998.99");
rs.next();
checkColumnBigDecimal(rs, 2, -99999999, "-99999998.99");
rs.next();
checkColumnBigDecimal(rs, 2, 0, null);
assertTrue(!rs.next());
stat.execute("DROP TABLE TEST");
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论