提交 94ea0d82 authored 作者: Sergi Vladykin's avatar Sergi Vladykin 提交者: GitHub

Merge pull request #348 from kostya-sh/fix-describe-statement-response

......@@ -308,7 +308,12 @@ public class PgServerThread implements Runnable {
if (p == null) {
sendErrorResponse("Prepared not found: " + name);
} else {
sendParameterDescription(p);
try {
sendParameterDescription(p.prep.getParameterMetaData(), p.paramType);
sendRowDescription(p.prep.getMetaData());
} catch (Exception e) {
sendErrorResponse(e);
}
}
} else if (type == 'P') {
Portal p = portals.get(name);
......@@ -636,17 +641,14 @@ public class PgServerThread implements Runnable {
sendMessage();
}
private void sendParameterDescription(Prepared p) throws IOException {
try {
PreparedStatement prep = p.prep;
ParameterMetaData meta = prep.getParameterMetaData();
private void sendParameterDescription(ParameterMetaData meta, int[] paramTypes) throws Exception {
int count = meta.getParameterCount();
startMessage('t');
writeShort(count);
for (int i = 0; i < count; i++) {
int type;
if (p.paramType != null && p.paramType[i] != 0) {
type = p.paramType[i];
if (paramTypes != null && paramTypes[i] != 0) {
type = paramTypes[i];
} else {
type = PgServer.PG_TYPE_VARCHAR;
}
......@@ -654,9 +656,6 @@ public class PgServerThread implements Runnable {
writeInt(type);
}
sendMessage();
} catch (Exception e) {
sendErrorResponse(e);
}
}
private void sendNoData() throws IOException {
......
......@@ -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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论