summaryrefslogtreecommitdiff
path: root/src/backend/executor/spi.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2001-11-05 19:41:56 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2001-11-05 19:41:56 +0000
commit0053cebea5f3803e853accafb1810afd8cb02b0e (patch)
tree39e5f8502394d93dc87c7b5ce74ab5846da45fcc /src/backend/executor/spi.c
parentea08e6cd5542cb269ecd3e735f1dfa3bb61fbc4f (diff)
Fix coredump in plpgsql when trying to return a rowtype result.
Need to return a TupleTableSlot, not just a bare tuple.
Diffstat (limited to 'src/backend/executor/spi.c')
-rw-r--r--src/backend/executor/spi.c36
1 files changed, 35 insertions, 1 deletions
diff --git a/src/backend/executor/spi.c b/src/backend/executor/spi.c
index e4c2dac40db..428a4cb7d3f 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.60 2001/10/25 05:49:29 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/executor/spi.c,v 1.61 2001/11/05 19:41:56 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -360,6 +360,40 @@ SPI_copytupledesc(TupleDesc tupdesc)
return ctupdesc;
}
+TupleTableSlot *
+SPI_copytupleintoslot(HeapTuple tuple, TupleDesc tupdesc)
+{
+ MemoryContext oldcxt = NULL;
+ TupleTableSlot *cslot;
+ HeapTuple ctuple;
+ TupleDesc ctupdesc;
+
+ if (tuple == NULL || tupdesc == NULL)
+ {
+ SPI_result = SPI_ERROR_ARGUMENT;
+ return NULL;
+ }
+
+ if (_SPI_curid + 1 == _SPI_connected) /* connected */
+ {
+ if (_SPI_current != &(_SPI_stack[_SPI_curid + 1]))
+ elog(FATAL, "SPI: stack corrupted");
+ oldcxt = MemoryContextSwitchTo(_SPI_current->savedcxt);
+ }
+
+ ctuple = heap_copytuple(tuple);
+ ctupdesc = CreateTupleDescCopy(tupdesc);
+
+ cslot = MakeTupleTableSlot();
+ ExecSetSlotDescriptor(cslot, ctupdesc, true);
+ cslot = ExecStoreTuple(ctuple, cslot, InvalidBuffer, true);
+
+ if (oldcxt)
+ MemoryContextSwitchTo(oldcxt);
+
+ return cslot;
+}
+
HeapTuple
SPI_modifytuple(Relation rel, HeapTuple tuple, int natts, int *attnum,
Datum *Values, char *Nulls)