1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-14 18:42:34 +03:00

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.
This commit is contained in:
Tom Lane
2004-08-02 01:30:51 +00:00
parent 410b1dfb88
commit f622c54049
18 changed files with 262 additions and 114 deletions

View File

@ -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);