pg: add test that verifies PGServer response to Describe message

Prior to the fix the test would fail with NPE:

  Exception in thread "main" java.lang.NullPointerException
      at org.postgresql.jdbc2.AbstractJdbc2ResultSet.checkColumnIndex(AbstractJdbc2ResultSet.java:2619)
      at org.postgresql.jdbc2.AbstractJdbc2ResultSet.checkResultSet(AbstractJdbc2ResultSet.java:2637)
      at org.postgresql.jdbc2.AbstractJdbc2ResultSet.getInt(AbstractJdbc2ResultSet.java:2005)
      at org.h2.test.server.TestPGServer.testPrepareWithUnspecifiedType(TestPGServer.java:76)
      at org.h2.test.server.TestPGServer.test(TestPGServer.java:44)
      at org.h2.test.server.TestPGServer.main(TestPGServer.java:29)
上级 a50f5960
......@@ -23,6 +23,7 @@ import java.util.concurrent.Future;
import org.h2.test.TestBase;
import org.h2.tools.Server;
import org.postgresql.PGStatement;
/**
* Tests the PostgreSQL server protocol compliant implementation.
......@@ -46,6 +47,7 @@ public class TestPgServer extends TestBase {
testKeyAlias();
testCancelQuery();
testBinaryTypes();
testPrepareWithUnspecifiedType();
}
private void testLowerCaseIdentifiers() throws SQLException {
......@@ -407,4 +409,39 @@ public class TestPgServer extends TestBase {
server.stop();
}
}
private void testPrepareWithUnspecifiedType() throws Exception {
if (!getPgJdbcDriver()) {
return;
}
Server server = Server.createPgServer(
"-pgPort", "5535", "-pgDaemon", "-key", "test", "mem:test");
server.start();
try {
Connection conn = DriverManager.getConnection(
"jdbc:postgresql://localhost:5535/test", "sa", "sa");
Statement stmt = conn.createStatement();
stmt.executeUpdate("create table t1 (id integer, value boolean)");
stmt.executeUpdate("INSERT INTO t1 VALUES (1,'t')");
stmt.executeUpdate("INSERT INTO t1 VALUES (2,'f')");
stmt.close();
PreparedStatement pstmt = conn.prepareStatement("SELECT * FROM t1 WHERE value = ?");
((PGStatement) pstmt).setPrepareThreshold(1); // force server side prepare
assertTrue(((PGStatement) pstmt).isUseServerPrepare());
pstmt.setObject(1, false, Types.OTHER);
ResultSet rs = pstmt.executeQuery();
assertTrue(rs.next());
assertEquals(2, rs.getInt(1));
rs.close();
pstmt.close();
conn.close();
} finally {
server.stop();
}
}
}
......@@ -209,6 +209,7 @@ public class Build extends BuildBase {
File.pathSeparator + "ext/org.osgi.core-4.2.0.jar" +
File.pathSeparator + "ext/org.osgi.enterprise-4.2.0.jar" +
File.pathSeparator + "ext/jts-core-1.14.0.jar" +
File.pathSeparator + "ext/postgresql-8.3-603.jdbc3.jar" +
File.pathSeparator + javaToolsJar;
FileList files;
if (clientOnly) {
......@@ -317,6 +318,9 @@ public class Build extends BuildBase {
downloadOrVerify("ext/junit-4.12.jar",
"junit", "junit", "4.12",
"2973d150c0dc1fefe998f834810d68f278ea58ec", offline);
downloadOrVerify("ext/postgresql-8.3-603.jdbc3.jar",
"postgresql", "postgresql", "8.3-603.jdbc3",
"33d531c3c53055ddcbea3d88bfa093466ffef924", offline);
}
private void downloadOrVerify(String target, String group, String artifact,
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论