提交 1ab44d6d authored 作者: Thomas Mueller's avatar Thomas Mueller

More tests

上级 5d8aee63
...@@ -1232,7 +1232,7 @@ public class Database implements DataHandler { ...@@ -1232,7 +1232,7 @@ public class Database implements DataHandler {
*/ */
private synchronized void closeOpenFilesAndUnlock(boolean flush) { private synchronized void closeOpenFilesAndUnlock(boolean flush) {
stopWriter(); stopWriter();
if (pageStore != null) { if (pageStore != null && mvStore == null) {
if (flush) { if (flush) {
try { try {
pageStore.checkpoint(); pageStore.checkpoint();
......
...@@ -7,13 +7,18 @@ ...@@ -7,13 +7,18 @@
package org.h2.test.jdbc; package org.h2.test.jdbc;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.net.URL;
import java.sql.CallableStatement; import java.sql.CallableStatement;
import java.sql.Connection; import java.sql.Connection;
import java.sql.Ref;
import java.sql.ResultSet; import java.sql.ResultSet;
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.Timestamp; import java.sql.Timestamp;
import java.sql.Types; import java.sql.Types;
import java.util.Collections;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.test.TestBase; import org.h2.test.TestBase;
...@@ -38,6 +43,7 @@ public class TestCallableStatement extends TestBase { ...@@ -38,6 +43,7 @@ public class TestCallableStatement extends TestBase {
public void test() throws SQLException { public void test() throws SQLException {
deleteDb("callableStatement"); deleteDb("callableStatement");
Connection conn = getConnection("callableStatement"); Connection conn = getConnection("callableStatement");
testUnsupportedOperations(conn);
testGetters(conn); testGetters(conn);
testCallWithResultSet(conn); testCallWithResultSet(conn);
testCallWithResult(conn); testCallWithResult(conn);
...@@ -47,6 +53,32 @@ public class TestCallableStatement extends TestBase { ...@@ -47,6 +53,32 @@ public class TestCallableStatement extends TestBase {
deleteDb("callableStatement"); deleteDb("callableStatement");
} }
private void testUnsupportedOperations(Connection conn) throws SQLException {
CallableStatement call;
call = conn.prepareCall("select 10 as a");
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, call).getURL(1);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, call).getObject(1, Collections.<String, Class<?>>emptyMap());
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, call).getRef(1);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, call).getRowId(1);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, call).getSQLXML(1);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, call).getURL("a");
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).setURL(1, (URL) null);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, call).setRef(1, (Ref) null);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, call).setRowId(1, (RowId) null);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, call).setSQLXML(1, (SQLXML) null);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, call).setURL("a", (URL) null);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, call).setRowId("a", (RowId) null);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, call).setSQLXML("a", (SQLXML) null);
}
private void testCallWithResultSet(Connection conn) throws SQLException { private void testCallWithResultSet(Connection conn) throws SQLException {
CallableStatement call; CallableStatement call;
ResultSet rs; ResultSet rs;
......
...@@ -15,6 +15,8 @@ import java.sql.SQLClientInfoException; ...@@ -15,6 +15,8 @@ import java.sql.SQLClientInfoException;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Statement; import java.sql.Statement;
import java.sql.Types; import java.sql.Types;
import org.h2.constant.ErrorCode;
import org.h2.engine.Constants; import org.h2.engine.Constants;
import org.h2.test.TestBase; import org.h2.test.TestBase;
import org.h2.value.DataType; import org.h2.value.DataType;
...@@ -38,7 +40,7 @@ public class TestMetaData extends TestBase { ...@@ -38,7 +40,7 @@ public class TestMetaData extends TestBase {
@Override @Override
public void test() throws SQLException { public void test() throws SQLException {
deleteDb("metaData"); deleteDb("metaData");
testUnsupportedOperations();
testTempTable(); testTempTable();
testColumnResultSetMeta(); testColumnResultSetMeta();
testColumnLobMeta(); testColumnLobMeta();
...@@ -56,6 +58,36 @@ public class TestMetaData extends TestBase { ...@@ -56,6 +58,36 @@ public class TestMetaData extends TestBase {
testQueryStatistics(); testQueryStatistics();
} }
private void testUnsupportedOperations() throws SQLException {
Connection conn = getConnection("metaData");
Statement stat = conn.createStatement();
ResultSet rs = stat.executeQuery("select 1 as x from dual");
ResultSetMetaData meta = rs.getMetaData();
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, meta).isWrapperFor(Object.class);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, meta).unwrap(Object.class);
assertThrows(ErrorCode.INVALID_VALUE_2, meta).getColumnLabel(0);
assertThrows(ErrorCode.INVALID_VALUE_2, meta).getColumnName(0);
assertThrows(ErrorCode.INVALID_VALUE_2, meta).getColumnType(0);
assertThrows(ErrorCode.INVALID_VALUE_2, meta).getColumnTypeName(0);
assertThrows(ErrorCode.INVALID_VALUE_2, meta).getSchemaName(0);
assertThrows(ErrorCode.INVALID_VALUE_2, meta).getTableName(0);
assertThrows(ErrorCode.INVALID_VALUE_2, meta).getCatalogName(0);
assertThrows(ErrorCode.INVALID_VALUE_2, meta).isAutoIncrement(0);
assertThrows(ErrorCode.INVALID_VALUE_2, meta).isCaseSensitive(0);
assertThrows(ErrorCode.INVALID_VALUE_2, meta).isSearchable(0);
assertThrows(ErrorCode.INVALID_VALUE_2, meta).isCurrency(0);
assertThrows(ErrorCode.INVALID_VALUE_2, meta).isNullable(0);
assertThrows(ErrorCode.INVALID_VALUE_2, meta).isSigned(0);
assertThrows(ErrorCode.INVALID_VALUE_2, meta).isReadOnly(0);
assertThrows(ErrorCode.INVALID_VALUE_2, meta).isWritable(0);
assertThrows(ErrorCode.INVALID_VALUE_2, meta).isDefinitelyWritable(0);
assertThrows(ErrorCode.INVALID_VALUE_2, meta).getColumnClassName(0);
assertThrows(ErrorCode.INVALID_VALUE_2, meta).getPrecision(0);
assertThrows(ErrorCode.INVALID_VALUE_2, meta).getScale(0);
assertThrows(ErrorCode.INVALID_VALUE_2, meta).getColumnDisplaySize(0);
conn.close();
}
private void testColumnResultSetMeta() throws SQLException { private void testColumnResultSetMeta() throws SQLException {
Connection conn = getConnection("metaData"); Connection conn = getConnection("metaData");
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
...@@ -66,6 +98,7 @@ public class TestMetaData extends TestBase { ...@@ -66,6 +98,7 @@ public class TestMetaData extends TestBase {
stat.execute("insert into test values(select x('select x from system_range(1, 2)'))"); stat.execute("insert into test values(select x('select x from system_range(1, 2)'))");
ResultSet rs = stat.executeQuery("select * from test"); ResultSet rs = stat.executeQuery("select * from test");
ResultSetMetaData rsMeta = rs.getMetaData(); ResultSetMetaData rsMeta = rs.getMetaData();
assertTrue(rsMeta.toString().endsWith(": columns=1"));
assertEquals("java.sql.ResultSet", rsMeta.getColumnClassName(1)); assertEquals("java.sql.ResultSet", rsMeta.getColumnClassName(1));
assertEquals(DataType.TYPE_RESULT_SET, rsMeta.getColumnType(1)); assertEquals(DataType.TYPE_RESULT_SET, rsMeta.getColumnType(1));
rs.next(); rs.next();
......
...@@ -1113,8 +1113,12 @@ public class TestResultSet extends TestBase { ...@@ -1113,8 +1113,12 @@ public class TestResultSet extends TestBase {
assertTrue(array.toString().endsWith(": (11, 12)")); assertTrue(array.toString().endsWith(": (11, 12)"));
// free
array.free(); array.free();
assertEquals("null", array.toString()); assertEquals("null", array.toString());
assertThrows(ErrorCode.OBJECT_CLOSED, array).getBaseType();
assertThrows(ErrorCode.OBJECT_CLOSED, array).getBaseTypeName();
assertThrows(ErrorCode.OBJECT_CLOSED, array).getResultSet();
assertFalse(rs.next()); assertFalse(rs.next());
stat.execute("DROP TABLE TEST"); stat.execute("DROP TABLE TEST");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论