pg: send RowDescription in response to Describe (statement variant)

According to https://www.postgresql.org/docs/9.1/static/protocol-flow.html

  The Describe message (statement variant) specifies the name of an
  existing prepared statement (or an empty string for the unnamed
  prepared statement). The response is a ParameterDescription message
  describing the parameters needed by the statement, followed by a
  RowDescription message describing the rows that will be returned when
  the statement is eventually executed (or a NoData message if the
  statement will not return rows)
上级 57a2c96f
...@@ -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,17 +641,14 @@ public class PgServerThread implements Runnable { ...@@ -636,17 +641,14 @@ public class PgServerThread implements Runnable {
sendMessage(); sendMessage();
} }
private void sendParameterDescription(Prepared p) throws IOException { private void sendParameterDescription(ParameterMetaData meta, int[] paramTypes) throws Exception {
try {
PreparedStatement prep = p.prep;
ParameterMetaData meta = prep.getParameterMetaData();
int count = meta.getParameterCount(); int count = meta.getParameterCount();
startMessage('t'); startMessage('t');
writeShort(count); writeShort(count);
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
int type; int type;
if (p.paramType != null && p.paramType[i] != 0) { if (paramTypes != null && paramTypes[i] != 0) {
type = p.paramType[i]; type = paramTypes[i];
} else { } else {
type = PgServer.PG_TYPE_VARCHAR; type = PgServer.PG_TYPE_VARCHAR;
} }
...@@ -654,9 +656,6 @@ public class PgServerThread implements Runnable { ...@@ -654,9 +656,6 @@ public class PgServerThread implements Runnable {
writeInt(type); writeInt(type);
} }
sendMessage(); sendMessage();
} catch (Exception e) {
sendErrorResponse(e);
}
} }
private void sendNoData() throws IOException { private void sendNoData() throws IOException {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论