提交 18adb2b8 authored 作者: Thomas Mueller's avatar Thomas Mueller

More tests

上级 205b27ca
...@@ -98,18 +98,56 @@ public class TestCallableStatement extends TestBase { ...@@ -98,18 +98,56 @@ public class TestCallableStatement extends TestBase {
private void testCallWithResultSet(Connection conn) throws SQLException { private void testCallWithResultSet(Connection conn) throws SQLException {
CallableStatement call; CallableStatement call;
ResultSet rs; ResultSet rs;
call = conn.prepareCall("select 10"); call = conn.prepareCall("select 10 as a, 20 as b, null as c, timestamp '2001-01-01 01:01:01.0' d");
call.execute(); call.execute();
rs = call.getResultSet(); rs = call.getResultSet();
rs.next(); rs.next();
assertEquals(10, rs.getInt(1)); assertEquals(10, rs.getInt(1));
assertEquals(10, rs.getByte(1));
assertEquals("10", rs.getBigDecimal(1).toString());
assertEquals(10, ((Integer) rs.getObject(1)).intValue());
assertEquals(10, rs.getShort(1));
assertEquals(10, rs.getLong(1));
assertEquals(10, rs.getFloat(1));
assertEquals(10, rs.getDouble(1));
assertTrue(rs.getBoolean(1));
assertEquals(10, rs.getInt("a"));
assertEquals(10, rs.getByte("a"));
assertEquals("10", rs.getBigDecimal("a").toString());
assertEquals(10, ((Integer) rs.getObject("a")).intValue());
assertEquals(10, rs.getShort("a"));
assertEquals(10, rs.getLong("a"));
assertEquals(10, rs.getFloat("a"));
assertEquals(10, rs.getDouble("a"));
assertTrue(rs.getBoolean("a"));
assertFalse(rs.wasNull());
assertEquals(20, rs.getInt(2));
assertEquals(20, rs.getInt("b"));
assertFalse(rs.wasNull());
assertEquals(0, rs.getInt(3));
assertTrue(rs.wasNull());
assertEquals(0, rs.getInt("c"));
assertTrue(rs.wasNull());
assertEquals("2001-01-01", rs.getDate(4).toString());
assertEquals("2001-01-01", rs.getDate("d").toString());
assertEquals("01:01:01", rs.getTime(4).toString());
assertEquals("01:01:01", rs.getTime("d").toString());
assertEquals("2001-01-01 01:01:01.0", rs.getTimestamp(4).toString());
assertEquals("2001-01-01 01:01:01.0", rs.getTimestamp("d").toString());
// using a callable statement like a prepared statement
call = conn.prepareCall("create table test(id int)");
call.executeUpdate();
call = conn.prepareCall("insert into test values(1), (2)");
assertEquals(2, call.executeUpdate());
call = conn.prepareCall("drop table test");
call.executeUpdate(); call.executeUpdate();
rs = call.getResultSet();
rs.next();
assertEquals(10, rs.getInt(1));
} }
private void testGetters(Connection conn) throws SQLException { private void testGetters(Connection conn) throws SQLException {
......
...@@ -114,6 +114,8 @@ public class TestMetaData extends TestBase { ...@@ -114,6 +114,8 @@ public class TestMetaData extends TestBase {
assertEquals("1", rsMeta.getColumnName(1)); assertEquals("1", rsMeta.getColumnName(1));
assertEquals("", rsMeta.getSchemaName(1)); assertEquals("", rsMeta.getSchemaName(1));
assertEquals("", rsMeta.getTableName(1)); assertEquals("", rsMeta.getTableName(1));
assertEquals(ResultSet.HOLD_CURSORS_OVER_COMMIT, conn.getHoldability());
assertEquals(ResultSet.HOLD_CURSORS_OVER_COMMIT, rs.getHoldability());
stat.executeUpdate("drop table test"); stat.executeUpdate("drop table test");
conn.close(); conn.close();
} }
......
...@@ -6,13 +6,16 @@ ...@@ -6,13 +6,16 @@
*/ */
package org.h2.test.jdbc; package org.h2.test.jdbc;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.Writer;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.BigInteger; import java.math.BigInteger;
import java.sql.Array; import java.sql.Array;
import java.sql.Clob;
import java.sql.Connection; import java.sql.Connection;
import java.sql.DatabaseMetaData; import java.sql.DatabaseMetaData;
import java.sql.Date; import java.sql.Date;
...@@ -32,8 +35,10 @@ import java.util.Calendar; ...@@ -32,8 +35,10 @@ import java.util.Calendar;
import java.util.Collections; import java.util.Collections;
import java.util.Locale; import java.util.Locale;
import java.util.TimeZone; import java.util.TimeZone;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.test.TestBase; import org.h2.test.TestBase;
import org.h2.upgrade.v1_1.util.IOUtils;
/** /**
* Tests for the ResultSet implementation. * Tests for the ResultSet implementation.
...@@ -53,7 +58,7 @@ public class TestResultSet extends TestBase { ...@@ -53,7 +58,7 @@ public class TestResultSet extends TestBase {
} }
@Override @Override
public void test() throws SQLException { public void test() throws Exception {
deleteDb("resultSet"); deleteDb("resultSet");
conn = getConnection("resultSet"); conn = getConnection("resultSet");
...@@ -139,10 +144,10 @@ public class TestResultSet extends TestBase { ...@@ -139,10 +144,10 @@ public class TestResultSet extends TestBase {
stat.execute("drop table test"); stat.execute("drop table test");
} }
private void testInsertRowWithUpdatableResultSetDefault() throws SQLException { private void testInsertRowWithUpdatableResultSetDefault() throws Exception {
stat.execute("create table test(id int primary key, data varchar(255) default 'Hello')"); stat.execute("create table test(id int primary key, data varchar(255) default 'Hello')");
PreparedStatement prep = conn.prepareStatement("select * from test", PreparedStatement prep = conn.prepareStatement("select * from test",
ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
ResultSet rs = prep.executeQuery(); ResultSet rs = prep.executeQuery();
rs.moveToInsertRow(); rs.moveToInsertRow();
rs.updateInt(1, 1); rs.updateInt(1, 1);
...@@ -151,6 +156,94 @@ public class TestResultSet extends TestBase { ...@@ -151,6 +156,94 @@ public class TestResultSet extends TestBase {
rs = stat.executeQuery("select * from test"); rs = stat.executeQuery("select * from test");
assertTrue(rs.next()); assertTrue(rs.next());
assertEquals("Hello", rs.getString(2)); assertEquals("Hello", rs.getString(2));
assertEquals("Hello", rs.getString("data"));
assertEquals("Hello", rs.getNString(2));
assertEquals("Hello", rs.getNString("data"));
assertEquals("Hello", IOUtils.readStringAndClose(
rs.getNCharacterStream(2), -1));
assertEquals("Hello", IOUtils.readStringAndClose(
rs.getNCharacterStream("data"), -1));
assertEquals("Hello", IOUtils.readStringAndClose(
rs.getNClob(2).getCharacterStream(), -1));
assertEquals("Hello", IOUtils.readStringAndClose(
rs.getNClob("data").getCharacterStream(), -1));
rs = prep.executeQuery();
rs.moveToInsertRow();
rs.updateInt(1, 2);
rs.updateNString(2, "Hello");
rs.insertRow();
rs.moveToInsertRow();
rs.updateInt(1, 3);
rs.updateNString("data", "Hello");
rs.insertRow();
Clob c;
Writer w;
rs.moveToInsertRow();
rs.updateInt(1, 4);
c = conn.createClob();
w = c.setCharacterStream(1);
w.write("Hello");
w.close();
rs.updateClob(2, c);
rs.insertRow();
rs.moveToInsertRow();
rs.updateInt(1, 5);
c = conn.createClob();
w = c.setCharacterStream(1);
w.write("Hello");
w.close();
rs.updateClob("data", c);
rs.insertRow();
InputStream in;
rs.moveToInsertRow();
rs.updateInt(1, 6);
in = new ByteArrayInputStream("Hello".getBytes("UTF-8"));
rs.updateAsciiStream(2, in);
rs.insertRow();
rs.moveToInsertRow();
rs.updateInt(1, 7);
in = new ByteArrayInputStream("Hello".getBytes("UTF-8"));
rs.updateAsciiStream("data", in);
rs.insertRow();
rs.moveToInsertRow();
rs.updateInt(1, 8);
in = new ByteArrayInputStream("Hello-".getBytes("UTF-8"));
rs.updateAsciiStream(2, in, 5);
rs.insertRow();
rs.moveToInsertRow();
rs.updateInt(1, 9);
in = new ByteArrayInputStream("Hello-".getBytes("UTF-8"));
rs.updateAsciiStream("data", in, 5);
rs.insertRow();
rs.moveToInsertRow();
rs.updateInt(1, 10);
in = new ByteArrayInputStream("Hello-".getBytes("UTF-8"));
rs.updateAsciiStream(2, in, 5L);
rs.insertRow();
rs.moveToInsertRow();
rs.updateInt(1, 11);
in = new ByteArrayInputStream("Hello-".getBytes("UTF-8"));
rs.updateAsciiStream("data", in, 5L);
rs.insertRow();
rs = stat.executeQuery("select * from test");
while (rs.next()) {
assertEquals("Hello", rs.getString(2));
}
stat.execute("drop table test"); stat.execute("drop table test");
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论