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 {
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,27 +641,21 @@ public class PgServerThread implements Runnable {
sendMessage();
}
private void sendParameterDescription(Prepared p) throws IOException {
try {
PreparedStatement prep = p.prep;
ParameterMetaData meta = prep.getParameterMetaData();
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];
} else {
type = PgServer.PG_TYPE_VARCHAR;
}
server.checkType(type);
writeInt(type);
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 (paramTypes != null && paramTypes[i] != 0) {
type = paramTypes[i];
} else {
type = PgServer.PG_TYPE_VARCHAR;
}
sendMessage();
} catch (Exception e) {
sendErrorResponse(e);
server.checkType(type);
writeInt(type);
}
sendMessage();
}
private void sendNoData() throws IOException {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论