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,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 {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论