aboutsummaryrefslogtreecommitdiff
path: root/src/backend/executor/spi.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2003-01-29 15:24:46 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2003-01-29 15:24:46 +0000
commit26f56131aed776a9a14fe9866895e05d51e23003 (patch)
tree8ec219cc9fa6a96659c5f9f092c92604ad2ab548 /src/backend/executor/spi.c
parent6976205b4bc665146216c04f1eca573b7169bb29 (diff)
downloadpostgresql-26f56131aed776a9a14fe9866895e05d51e23003.tar.gz
postgresql-26f56131aed776a9a14fe9866895e05d51e23003.zip
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.
Diffstat (limited to 'src/backend/executor/spi.c')
-rw-r--r--src/backend/executor/spi.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/backend/executor/spi.c b/src/backend/executor/spi.c
index 3df2426473a..193bd08b4d7 100644
--- a/src/backend/executor/spi.c
+++ b/src/backend/executor/spi.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/executor/spi.c,v 1.84 2003/01/21 22:06:12 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/executor/spi.c,v 1.85 2003/01/29 15:24:46 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -125,6 +125,14 @@ SPI_finish(void)
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
* _SPI_connected must be equal to _SPI_curid.
@@ -1314,6 +1322,11 @@ _SPI_pquery(QueryDesc *queryDesc, bool runit, 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;
+ }
ExecutorEnd(queryDesc);