提交 527757ce authored 作者: Thomas Mueller's avatar Thomas Mueller

More tests

上级 428f1f59
......@@ -285,6 +285,6 @@ public class JdbcArray extends TraceObject implements Array {
*/
@Override
public String toString() {
return getTraceObjectName() + ": " + value.getTraceSQL();
return value == null ? "null" : (getTraceObjectName() + ": " + value.getTraceSQL());
}
}
......@@ -6,6 +6,7 @@
*/
package org.h2.test.jdbc;
import java.math.BigDecimal;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
......@@ -110,7 +111,11 @@ public class TestCallableStatement extends TestBase {
call.registerOutParameter(1, Types.SMALLINT);
call.execute();
assertEquals(123, call.getShort(1));
call.setBigDecimal(2, BigDecimal.TEN);
call.registerOutParameter(1, Types.DECIMAL);
call.execute();
assertEquals("10", call.getBigDecimal(1).toString());
}
private void testCallWithResult(Connection conn) throws SQLException {
......@@ -222,6 +227,7 @@ public class TestCallableStatement extends TestBase {
public static Boolean testClassF(Boolean b) {
return !b;
}
/**
* This method is called via reflection from the database.
*
......
......@@ -10,12 +10,14 @@ import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.StringReader;
import java.math.BigDecimal;
import java.net.URL;
import java.sql.Connection;
import java.sql.Date;
import java.sql.ParameterMetaData;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.RowId;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Time;
......@@ -26,6 +28,7 @@ import java.util.GregorianCalendar;
import java.util.SimpleTimeZone;
import java.util.TimeZone;
import java.util.UUID;
import org.h2.api.Trigger;
import org.h2.constant.ErrorCode;
import org.h2.test.TestBase;
......@@ -52,6 +55,7 @@ public class TestPreparedStatement extends TestBase {
public void test() throws Exception {
deleteDb("preparedStatement");
Connection conn = getConnection("preparedStatement");
testUnsupportedOperations(conn);
testChangeType(conn);
testDateTimeTimestampWithCalendar(conn);
testCallTablePrepared(conn);
......@@ -90,6 +94,35 @@ public class TestPreparedStatement extends TestBase {
testPreparedStatementWithLiteralsNone();
deleteDb("preparedStatement");
}
private void testUnsupportedOperations(Connection conn) throws Exception {
PreparedStatement prep = conn.prepareStatement("select ? from dual");
assertThrows(ErrorCode.METHOD_NOT_ALLOWED_FOR_PREPARED_STATEMENT, prep).
addBatch("select 1");
assertThrows(ErrorCode.METHOD_NOT_ALLOWED_FOR_PREPARED_STATEMENT, prep).
executeUpdate("create table test(id int)");
assertThrows(ErrorCode.METHOD_NOT_ALLOWED_FOR_PREPARED_STATEMENT, prep).
executeUpdate("create table test(id int)", new int[0]);
assertThrows(ErrorCode.METHOD_NOT_ALLOWED_FOR_PREPARED_STATEMENT, prep).
executeUpdate("create table test(id int)", new String[0]);
assertThrows(ErrorCode.METHOD_NOT_ALLOWED_FOR_PREPARED_STATEMENT, prep).
executeUpdate("create table test(id int)", Statement.RETURN_GENERATED_KEYS);
assertThrows(ErrorCode.METHOD_NOT_ALLOWED_FOR_PREPARED_STATEMENT, prep).
execute("create table test(id int)");
assertThrows(ErrorCode.METHOD_NOT_ALLOWED_FOR_PREPARED_STATEMENT, prep).
execute("create table test(id int)", new int[0]);
assertThrows(ErrorCode.METHOD_NOT_ALLOWED_FOR_PREPARED_STATEMENT, prep).
execute("create table test(id int)", new String[0]);
assertThrows(ErrorCode.METHOD_NOT_ALLOWED_FOR_PREPARED_STATEMENT, prep).
execute("create table test(id int)", Statement.RETURN_GENERATED_KEYS);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, prep).
setURL(1, new URL("http://www.acme.com"));
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, prep).
setRowId(1, (RowId) null);
}
private static void testChangeType(Connection conn) throws SQLException {
PreparedStatement prep = conn.prepareStatement("select (? || ? || ?) from dual");
......
......@@ -25,6 +25,7 @@ import java.sql.Time;
import java.sql.Timestamp;
import java.sql.Types;
import java.util.Calendar;
import java.util.Collections;
import java.util.Locale;
import java.util.TimeZone;
import org.h2.constant.ErrorCode;
......@@ -1084,6 +1085,7 @@ public class TestResultSet extends TestBase {
Object[] list = (Object[]) rs.getObject(2);
assertEquals(1, ((Integer) list[0]).intValue());
assertEquals(2, ((Integer) list[1]).intValue());
Array array = rs.getArray(2);
Object[] list2 = (Object[]) array.getArray();
assertEquals(1, ((Integer) list2[0]).intValue());
......@@ -1095,12 +1097,25 @@ public class TestResultSet extends TestBase {
list = (Object[]) rs.getObject(2);
assertEquals(11, ((Integer) list[0]).intValue());
assertEquals(12, ((Integer) list[1]).intValue());
array = rs.getArray(2);
array = rs.getArray("VALUE");
list2 = (Object[]) array.getArray();
assertEquals(11, ((Integer) list2[0]).intValue());
assertEquals(12, ((Integer) list2[1]).intValue());
list2 = (Object[]) array.getArray(2, 1);
assertEquals(12, ((Integer) list2[0]).intValue());
list2 = (Object[]) array.getArray(Collections.<String, Class<?>>emptyMap());
assertEquals(11, ((Integer) list2[0]).intValue());
assertEquals(Types.NULL, array.getBaseType());
assertEquals("NULL", array.getBaseTypeName());
assertEquals("ar1: (11, 12)", array.toString());
array.free();
assertEquals("null", array.toString());
assertFalse(rs.next());
stat.execute("DROP TABLE TEST");
}
......
......@@ -155,7 +155,11 @@ public class TestUpdatableResultSet extends TestBase {
rs.updateInt(1, 10);
rs.updateRow();
rs.next();
rs.updateString(2, "Welt");
rs.cancelRowUpdates();
rs.updateString(2, "Welt");
rs.updateRow();
rs.beforeFirst();
rs.next();
......@@ -164,6 +168,11 @@ public class TestUpdatableResultSet extends TestBase {
rs.next();
assertEquals(2, rs.getInt(1));
assertEquals("Welt", rs.getString(2));
assertFalse(rs.isClosed());
rs.close();
assertTrue(rs.isClosed());
conn.close();
}
......@@ -294,6 +303,7 @@ public class TestUpdatableResultSet extends TestBase {
rs.updateNull(2);
rs.updateNull("DEC");
// 'not set' values are set to null
assertThrows(ErrorCode.NO_DATA_AVAILABLE, rs).cancelRowUpdates();
rs.insertRow();
rs.moveToInsertRow();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论