From: Tom Lane Date: Wed, 29 Jan 2003 15:24:57 +0000 (+0000) Subject: SPI_exec shouldn't return SPI_OK_SELECT if it hasn't actually returned X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=fa2285180c5e236c7a9d3a1044022bc578e24b6f;p=users%2Fbernd%2Fpostgres.git SPI_exec shouldn't return SPI_OK_SELECT if it hasn't actually returned a tuple table. Fixes core dump in pltcl (and probably other PLs) when executing a query rewritten by a rule. Per bug report from Wolfgang Walter. --- diff --git a/src/backend/executor/spi.c b/src/backend/executor/spi.c index 26083738e2..93e3bf1444 100644 --- a/src/backend/executor/spi.c +++ b/src/backend/executor/spi.c @@ -124,6 +124,14 @@ SPI_finish(void) MemoryContextDelete(_SPI_current->execCxt); MemoryContextDelete(_SPI_current->procCxt); + /* + * Reset result variables, especially SPI_tuptable which is probably + * pointing at a just-deleted tuptable + */ + SPI_processed = 0; + SPI_lastoid = InvalidOid; + SPI_tuptable = NULL; + /* * After _SPI_begin_call _SPI_connected == _SPI_curid. Now we are * closing connection to SPI and returning to upper Executor and so @@ -1330,6 +1338,11 @@ _SPI_pquery(QueryDesc *queryDesc, EState *state, int tcount) SPI_lastoid = save_lastoid; SPI_tuptable = _SPI_current->tuptable; } + else if (res == SPI_OK_SELECT) + { + /* Don't return SPI_OK_SELECT if we discarded the result */ + res = SPI_OK_UTILITY; + } queryDesc->dest = dest; return res;