mirror of
https://github.com/postgres/postgres.git
synced 2025-11-10 17:42:29 +03:00
Fix the mechanism for reporting the original table OID and column number
of columns of a query result so that it can "see through" cursors and prepared statements. Per gripe a couple months back from John DeSoi.
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.449 2005/06/17 22:32:46 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.450 2005/06/22 17:45:45 tgl Exp $
|
||||
*
|
||||
* NOTES
|
||||
* this is the "main" module of the postgres backend and
|
||||
@@ -1928,15 +1928,9 @@ exec_describe_statement_message(const char *stmt_name)
|
||||
*/
|
||||
tupdesc = FetchPreparedStatementResultDesc(pstmt);
|
||||
if (tupdesc)
|
||||
{
|
||||
List *targetlist;
|
||||
|
||||
if (ChoosePortalStrategy(pstmt->query_list) == PORTAL_ONE_SELECT)
|
||||
targetlist = ((Query *) linitial(pstmt->query_list))->targetList;
|
||||
else
|
||||
targetlist = NIL;
|
||||
SendRowDescriptionMessage(tupdesc, targetlist, NULL);
|
||||
}
|
||||
SendRowDescriptionMessage(tupdesc,
|
||||
FetchPreparedStatementTargetList(pstmt),
|
||||
NULL);
|
||||
else
|
||||
pq_putemptymessage('n'); /* NoData */
|
||||
|
||||
@@ -1962,16 +1956,9 @@ exec_describe_portal_message(const char *portal_name)
|
||||
return; /* can't actually do anything... */
|
||||
|
||||
if (portal->tupDesc)
|
||||
{
|
||||
List *targetlist;
|
||||
|
||||
if (portal->strategy == PORTAL_ONE_SELECT)
|
||||
targetlist = ((Query *) linitial(portal->parseTrees))->targetList;
|
||||
else
|
||||
targetlist = NIL;
|
||||
SendRowDescriptionMessage(portal->tupDesc, targetlist,
|
||||
SendRowDescriptionMessage(portal->tupDesc,
|
||||
FetchPortalTargetList(portal),
|
||||
portal->formats);
|
||||
}
|
||||
else
|
||||
pq_putemptymessage('n'); /* NoData */
|
||||
}
|
||||
|
||||
@@ -8,13 +8,14 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/tcop/pquery.c,v 1.93 2005/03/25 21:57:58 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/tcop/pquery.c,v 1.94 2005/06/22 17:45:46 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include "postgres.h"
|
||||
|
||||
#include "commands/prepare.h"
|
||||
#include "commands/trigger.h"
|
||||
#include "executor/executor.h"
|
||||
#include "miscadmin.h"
|
||||
@@ -252,6 +253,56 @@ ChoosePortalStrategy(List *parseTrees)
|
||||
return strategy;
|
||||
}
|
||||
|
||||
/*
|
||||
* FetchPortalTargetList
|
||||
* Given a portal that returns tuples, extract the query targetlist.
|
||||
* Returns NIL if the portal doesn't have a determinable targetlist.
|
||||
*
|
||||
* Note: do not modify the result.
|
||||
*
|
||||
* XXX be careful to keep this in sync with FetchPreparedStatementTargetList,
|
||||
* and with UtilityReturnsTuples.
|
||||
*/
|
||||
List *
|
||||
FetchPortalTargetList(Portal portal)
|
||||
{
|
||||
if (portal->strategy == PORTAL_ONE_SELECT)
|
||||
return ((Query *) linitial(portal->parseTrees))->targetList;
|
||||
if (portal->strategy == PORTAL_UTIL_SELECT)
|
||||
{
|
||||
Node *utilityStmt;
|
||||
|
||||
utilityStmt = ((Query *) linitial(portal->parseTrees))->utilityStmt;
|
||||
switch (nodeTag(utilityStmt))
|
||||
{
|
||||
case T_FetchStmt:
|
||||
{
|
||||
FetchStmt *substmt = (FetchStmt *) utilityStmt;
|
||||
Portal subportal;
|
||||
|
||||
Assert(!substmt->ismove);
|
||||
subportal = GetPortalByName(substmt->portalname);
|
||||
Assert(PortalIsValid(subportal));
|
||||
return FetchPortalTargetList(subportal);
|
||||
}
|
||||
|
||||
case T_ExecuteStmt:
|
||||
{
|
||||
ExecuteStmt *substmt = (ExecuteStmt *) utilityStmt;
|
||||
PreparedStatement *entry;
|
||||
|
||||
Assert(!substmt->into);
|
||||
entry = FetchPreparedStatement(substmt->name, true);
|
||||
return FetchPreparedStatementTargetList(entry);
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return NIL;
|
||||
}
|
||||
|
||||
/*
|
||||
* PortalStart
|
||||
* Prepare a portal for execution.
|
||||
|
||||
Reference in New Issue
Block a user