|
8 | 8 | *
|
9 | 9 | *
|
10 | 10 | * IDENTIFICATION
|
11 |
| - * $PostgreSQL: pgsql/src/backend/tcop/pquery.c,v 1.93 2005/03/25 21:57:58 tgl Exp $ |
| 11 | + * $PostgreSQL: pgsql/src/backend/tcop/pquery.c,v 1.94 2005/06/22 17:45:46 tgl Exp $ |
12 | 12 | *
|
13 | 13 | *-------------------------------------------------------------------------
|
14 | 14 | */
|
15 | 15 |
|
16 | 16 | #include"postgres.h"
|
17 | 17 |
|
| 18 | +#include"commands/prepare.h" |
18 | 19 | #include"commands/trigger.h"
|
19 | 20 | #include"executor/executor.h"
|
20 | 21 | #include"miscadmin.h"
|
@@ -252,6 +253,56 @@ ChoosePortalStrategy(List *parseTrees)
|
252 | 253 | returnstrategy;
|
253 | 254 | }
|
254 | 255 |
|
| 256 | +/* |
| 257 | + * FetchPortalTargetList |
| 258 | + *Given a portal that returns tuples, extract the query targetlist. |
| 259 | + *Returns NIL if the portal doesn't have a determinable targetlist. |
| 260 | + * |
| 261 | + * Note: do not modify the result. |
| 262 | + * |
| 263 | + * XXX be careful to keep this in sync with FetchPreparedStatementTargetList, |
| 264 | + * and with UtilityReturnsTuples. |
| 265 | + */ |
| 266 | +List* |
| 267 | +FetchPortalTargetList(Portalportal) |
| 268 | +{ |
| 269 | +if (portal->strategy==PORTAL_ONE_SELECT) |
| 270 | +return ((Query*)linitial(portal->parseTrees))->targetList; |
| 271 | +if (portal->strategy==PORTAL_UTIL_SELECT) |
| 272 | +{ |
| 273 | +Node*utilityStmt; |
| 274 | + |
| 275 | +utilityStmt= ((Query*)linitial(portal->parseTrees))->utilityStmt; |
| 276 | +switch (nodeTag(utilityStmt)) |
| 277 | +{ |
| 278 | +caseT_FetchStmt: |
| 279 | +{ |
| 280 | +FetchStmt*substmt= (FetchStmt*)utilityStmt; |
| 281 | +Portalsubportal; |
| 282 | + |
| 283 | +Assert(!substmt->ismove); |
| 284 | +subportal=GetPortalByName(substmt->portalname); |
| 285 | +Assert(PortalIsValid(subportal)); |
| 286 | +returnFetchPortalTargetList(subportal); |
| 287 | +} |
| 288 | + |
| 289 | +caseT_ExecuteStmt: |
| 290 | +{ |
| 291 | +ExecuteStmt*substmt= (ExecuteStmt*)utilityStmt; |
| 292 | +PreparedStatement*entry; |
| 293 | + |
| 294 | +Assert(!substmt->into); |
| 295 | +entry=FetchPreparedStatement(substmt->name, true); |
| 296 | +returnFetchPreparedStatementTargetList(entry); |
| 297 | +} |
| 298 | + |
| 299 | +default: |
| 300 | +break; |
| 301 | +} |
| 302 | +} |
| 303 | +returnNIL; |
| 304 | +} |
| 305 | + |
255 | 306 | /*
|
256 | 307 | * PortalStart
|
257 | 308 | *Prepare a portal for execution.
|
|