提交 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 { ...@@ -308,7 +308,12 @@ public class PgServerThread implements Runnable {
if (p == null) { if (p == null) {
sendErrorResponse("Prepared not found: " + name); sendErrorResponse("Prepared not found: " + name);
} else { } else {
sendParameterDescription(p); try {
sendParameterDescription(p.prep.getParameterMetaData(), p.paramType);
sendRowDescription(p.prep.getMetaData());
} catch (Exception e) {
sendErrorResponse(e);
}
} }
} else if (type == 'P') { } else if (type == 'P') {
Portal p = portals.get(name); Portal p = portals.get(name);
...@@ -636,27 +641,21 @@ public class PgServerThread implements Runnable { ...@@ -636,27 +641,21 @@ public class PgServerThread implements Runnable {
sendMessage(); sendMessage();
} }
private void sendParameterDescription(Prepared p) throws IOException { private void sendParameterDescription(ParameterMetaData meta, int[] paramTypes) throws Exception {
try { int count = meta.getParameterCount();
PreparedStatement prep = p.prep; startMessage('t');
ParameterMetaData meta = prep.getParameterMetaData(); writeShort(count);
int count = meta.getParameterCount(); for (int i = 0; i < count; i++) {
startMessage('t'); int type;
writeShort(count); if (paramTypes != null && paramTypes[i] != 0) {
for (int i = 0; i < count; i++) { type = paramTypes[i];
int type; } else {
if (p.paramType != null && p.paramType[i] != 0) { type = PgServer.PG_TYPE_VARCHAR;
type = p.paramType[i];
} else {
type = PgServer.PG_TYPE_VARCHAR;
}
server.checkType(type);
writeInt(type);
} }
sendMessage(); server.checkType(type);
} catch (Exception e) { writeInt(type);
sendErrorResponse(e);
} }
sendMessage();
} }
private void sendNoData() throws IOException { private void sendNoData() throws IOException {
......
...@@ -23,6 +23,7 @@ import java.util.concurrent.Future; ...@@ -23,6 +23,7 @@ import java.util.concurrent.Future;
import org.h2.test.TestBase; import org.h2.test.TestBase;
import org.h2.tools.Server; import org.h2.tools.Server;
import org.postgresql.PGStatement;
/** /**
* Tests the PostgreSQL server protocol compliant implementation. * Tests the PostgreSQL server protocol compliant implementation.
...@@ -46,6 +47,7 @@ public class TestPgServer extends TestBase { ...@@ -46,6 +47,7 @@ public class TestPgServer extends TestBase {
testKeyAlias(); testKeyAlias();
testCancelQuery(); testCancelQuery();
testBinaryTypes(); testBinaryTypes();
testPrepareWithUnspecifiedType();
} }
private void testLowerCaseIdentifiers() throws SQLException { private void testLowerCaseIdentifiers() throws SQLException {
...@@ -407,4 +409,39 @@ public class TestPgServer extends TestBase { ...@@ -407,4 +409,39 @@ public class TestPgServer extends TestBase {
server.stop(); 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 { ...@@ -209,6 +209,7 @@ public class Build extends BuildBase {
File.pathSeparator + "ext/org.osgi.core-4.2.0.jar" + File.pathSeparator + "ext/org.osgi.core-4.2.0.jar" +
File.pathSeparator + "ext/org.osgi.enterprise-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/jts-core-1.14.0.jar" +
File.pathSeparator + "ext/postgresql-8.3-603.jdbc3.jar" +
File.pathSeparator + javaToolsJar; File.pathSeparator + javaToolsJar;
FileList files; FileList files;
if (clientOnly) { if (clientOnly) {
...@@ -317,6 +318,9 @@ public class Build extends BuildBase { ...@@ -317,6 +318,9 @@ public class Build extends BuildBase {
downloadOrVerify("ext/junit-4.12.jar", downloadOrVerify("ext/junit-4.12.jar",
"junit", "junit", "4.12", "junit", "junit", "4.12",
"2973d150c0dc1fefe998f834810d68f278ea58ec", offline); "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, private void downloadOrVerify(String target, String group, String artifact,
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论