aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/backend/commands/prepare.c30
-rw-r--r--src/backend/tcop/postgres.c26
-rw-r--r--src/backend/tcop/utility.c23
-rw-r--r--src/include/commands/prepare.h3
-rw-r--r--src/include/libpq/pqcomm.h4
-rw-r--r--src/interfaces/libpq/libpq-int.h4
6 files changed, 62 insertions, 28 deletions
diff --git a/src/backend/commands/prepare.c b/src/backend/commands/prepare.c
index c317494f6fa..6e16853fd78 100644
--- a/src/backend/commands/prepare.c
+++ b/src/backend/commands/prepare.c
@@ -10,7 +10,7 @@
* Copyright (c) 2002-2003, PostgreSQL Global Development Group
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/prepare.c,v 1.16 2003/05/06 20:26:26 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/prepare.c,v 1.17 2003/05/06 21:51:41 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -394,6 +394,34 @@ FetchPreparedStatementParams(const char *stmt_name)
}
/*
+ * Given a prepared statement, determine the result tupledesc it will
+ * produce. Returns NULL if the execution will not return tuples.
+ *
+ * Note: the result is created or copied into current memory context.
+ */
+TupleDesc
+FetchPreparedStatementResultDesc(PreparedStatement *stmt)
+{
+ Query *query;
+
+ switch (ChoosePortalStrategy(stmt->query_list))
+ {
+ case PORTAL_ONE_SELECT:
+ query = (Query *) lfirst(stmt->query_list);
+ return ExecCleanTypeFromTL(query->targetList, false);
+
+ case PORTAL_UTIL_SELECT:
+ query = (Query *) lfirst(stmt->query_list);
+ return UtilityTupleDescriptor(query->utilityStmt);
+
+ case PORTAL_MULTI_QUERY:
+ /* will not return tuples */
+ break;
+ }
+ return NULL;
+}
+
+/*
* Implements the 'DEALLOCATE' utility statement: deletes the
* specified plan from storage.
*/
diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c
index a7dd5cb904a..c9ba35f7bde 100644
--- a/src/backend/tcop/postgres.c
+++ b/src/backend/tcop/postgres.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.336 2003/05/06 20:26:27 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.337 2003/05/06 21:51:41 tgl Exp $
*
* NOTES
* this is the "main" module of the postgres backend and
@@ -1428,6 +1428,7 @@ static void
exec_describe_statement_message(const char *stmt_name)
{
PreparedStatement *pstmt;
+ TupleDesc tupdesc;
List *l;
StringInfoData buf;
@@ -1445,6 +1446,9 @@ exec_describe_statement_message(const char *stmt_name)
if (whereToSendOutput != Remote)
return; /* can't actually do anything... */
+ /*
+ * First describe the parameters...
+ */
pq_beginmessage(&buf, 't'); /* parameter description message type */
pq_sendint(&buf, length(pstmt->argtype_list), 4);
@@ -1455,6 +1459,24 @@ exec_describe_statement_message(const char *stmt_name)
pq_sendint(&buf, (int) ptype, 4);
}
pq_endmessage(&buf);
+
+ /*
+ * Next send RowDescription or NoData to describe the result...
+ */
+ tupdesc = FetchPreparedStatementResultDesc(pstmt);
+ if (tupdesc)
+ {
+ List *targetlist;
+
+ if (ChoosePortalStrategy(pstmt->query_list) == PORTAL_ONE_SELECT)
+ targetlist = ((Query *) lfirst(pstmt->query_list))->targetList;
+ else
+ targetlist = NIL;
+ SendRowDescriptionMessage(tupdesc, targetlist);
+ }
+ else
+ pq_putemptymessage('n'); /* NoData */
+
}
/*
@@ -2359,7 +2381,7 @@ PostgresMain(int argc, char *argv[], const char *username)
if (!IsUnderPostmaster)
{
puts("\nPOSTGRES backend interactive interface ");
- puts("$Revision: 1.336 $ $Date: 2003/05/06 20:26:27 $\n");
+ puts("$Revision: 1.337 $ $Date: 2003/05/06 21:51:41 $\n");
}
/*
diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c
index 5fce0d5e755..5f015f4636a 100644
--- a/src/backend/tcop/utility.c
+++ b/src/backend/tcop/utility.c
@@ -10,7 +10,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.199 2003/05/06 20:26:27 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.200 2003/05/06 21:51:41 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -1052,11 +1052,6 @@ UtilityReturnsTuples(Node *parsetree)
portal = GetPortalByName(stmt->portalname);
if (!PortalIsValid(portal))
return false; /* not our business to raise error */
- /*
- * Note: if portal contains multiple statements then it's
- * possible some of them will return tuples, but we don't
- * handle that case here.
- */
return portal->tupDesc ? true : false;
}
@@ -1077,7 +1072,7 @@ UtilityReturnsTuples(Node *parsetree)
case PORTAL_UTIL_SELECT:
return true;
case PORTAL_MULTI_QUERY:
- /* can't figure it out, per note above */
+ /* will not return tuples */
break;
}
return false;
@@ -1124,25 +1119,13 @@ UtilityTupleDescriptor(Node *parsetree)
{
ExecuteStmt *stmt = (ExecuteStmt *) parsetree;
PreparedStatement *entry;
- Query *query;
if (stmt->into)
return NULL;
entry = FetchPreparedStatement(stmt->name, false);
if (!entry)
return NULL; /* not our business to raise error */
- switch (ChoosePortalStrategy(entry->query_list))
- {
- case PORTAL_ONE_SELECT:
- query = (Query *) lfirst(entry->query_list);
- return ExecCleanTypeFromTL(query->targetList, false);
- case PORTAL_UTIL_SELECT:
- query = (Query *) lfirst(entry->query_list);
- return UtilityTupleDescriptor(query->utilityStmt);
- case PORTAL_MULTI_QUERY:
- break;
- }
- return NULL;
+ return FetchPreparedStatementResultDesc(entry);
}
case T_ExplainStmt:
diff --git a/src/include/commands/prepare.h b/src/include/commands/prepare.h
index 2438077624b..5b8f32dd4ca 100644
--- a/src/include/commands/prepare.h
+++ b/src/include/commands/prepare.h
@@ -6,7 +6,7 @@
*
* Copyright (c) 2002-2003, PostgreSQL Global Development Group
*
- * $Id: prepare.h,v 1.5 2003/05/06 20:26:27 tgl Exp $
+ * $Id: prepare.h,v 1.6 2003/05/06 21:51:42 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -57,5 +57,6 @@ extern PreparedStatement *FetchPreparedStatement(const char *stmt_name,
bool throwError);
extern void DropPreparedStatement(const char *stmt_name, bool showError);
extern List *FetchPreparedStatementParams(const char *stmt_name);
+extern TupleDesc FetchPreparedStatementResultDesc(PreparedStatement *stmt);
#endif /* PREPARE_H */
diff --git a/src/include/libpq/pqcomm.h b/src/include/libpq/pqcomm.h
index b6961e824cd..998b3a391f5 100644
--- a/src/include/libpq/pqcomm.h
+++ b/src/include/libpq/pqcomm.h
@@ -9,7 +9,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: pqcomm.h,v 1.82 2003/05/05 00:44:56 tgl Exp $
+ * $Id: pqcomm.h,v 1.83 2003/05/06 21:51:42 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -106,7 +106,7 @@ typedef union SockAddr
/* The earliest and latest frontend/backend protocol version supported. */
#define PG_PROTOCOL_EARLIEST PG_PROTOCOL(1,0)
-#define PG_PROTOCOL_LATEST PG_PROTOCOL(3,106) /* XXX temporary value */
+#define PG_PROTOCOL_LATEST PG_PROTOCOL(3,107) /* XXX temporary value */
typedef uint32 ProtocolVersion; /* FE/BE protocol version number */
diff --git a/src/interfaces/libpq/libpq-int.h b/src/interfaces/libpq/libpq-int.h
index 3fcecd63e23..1a25105ead0 100644
--- a/src/interfaces/libpq/libpq-int.h
+++ b/src/interfaces/libpq/libpq-int.h
@@ -12,7 +12,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: libpq-int.h,v 1.67 2003/05/05 00:44:56 tgl Exp $
+ * $Id: libpq-int.h,v 1.68 2003/05/06 21:51:42 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -56,7 +56,7 @@ typedef int ssize_t; /* ssize_t doesn't exist in VC (atleast
* pqcomm.h describe what the backend knows, not what libpq knows.
*/
-#define PG_PROTOCOL_LIBPQ PG_PROTOCOL(3,106) /* XXX temporary value */
+#define PG_PROTOCOL_LIBPQ PG_PROTOCOL(3,107) /* XXX temporary value */
/*
* POSTGRES backend dependent Constants.