diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2004-08-02 01:30:51 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2004-08-02 01:30:51 +0000 |
commit | f622c5404905cb998adabe3a3527f7e9cdace229 (patch) | |
tree | bc65d3f7d71a9a8c09945e7072bbca2baeb937a3 /src/backend/commands/portalcmds.c | |
parent | 410b1dfb885f5b6d60f89003baba32a4efe93225 (diff) |
Allow DECLARE CURSOR to take parameters from the portal in which it is
executed. Previously, the DECLARE would succeed but subsequent FETCHes
would fail since the parameter values supplied to DECLARE were not
propagated to the portal created for the cursor.
In support of this, add type Oids to ParamListInfo entries, which seems
like a good idea anyway since code that extracts a value can double-check
that it got the type of value it was expecting.
Oliver Jowett, with minor editorialization by Tom Lane.
Diffstat (limited to 'src/backend/commands/portalcmds.c')
-rw-r--r-- | src/backend/commands/portalcmds.c | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/src/backend/commands/portalcmds.c b/src/backend/commands/portalcmds.c index 509d9e0dfa1..64d0c77489b 100644 --- a/src/backend/commands/portalcmds.c +++ b/src/backend/commands/portalcmds.c @@ -14,7 +14,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/portalcmds.c,v 1.30 2004/07/31 00:45:31 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/commands/portalcmds.c,v 1.31 2004/08/02 01:30:40 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -36,7 +36,7 @@ * Execute SQL DECLARE CURSOR command. */ void -PerformCursorOpen(DeclareCursorStmt *stmt) +PerformCursorOpen(DeclareCursorStmt *stmt, ParamListInfo params) { List *rewritten; Query *query; @@ -104,6 +104,17 @@ PerformCursorOpen(DeclareCursorStmt *stmt) list_make1(plan), PortalGetHeapMemory(portal)); + /* + * Also copy the outer portal's parameter list into the inner portal's + * memory context. We want to pass down the parameter values in case + * we had a command like + * DECLARE c CURSOR FOR SELECT ... WHERE foo = $1 + * This will have been parsed using the outer parameter set and the + * parameter value needs to be preserved for use when the cursor is + * executed. + */ + params = copyParamList(params); + MemoryContextSwitchTo(oldContext); /* @@ -123,9 +134,9 @@ PerformCursorOpen(DeclareCursorStmt *stmt) } /* - * Start execution --- never any params for a cursor. + * Start execution, inserting parameters if any. */ - PortalStart(portal, NULL); + PortalStart(portal, params); Assert(portal->strategy == PORTAL_ONE_SELECT); |