diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2001-08-02 18:08:43 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2001-08-02 18:08:43 +0000 |
commit | f59f3c88994063f2199f04853447510fd44c3635 (patch) | |
tree | e8d2bd8a80999590b43abda7e13c99b8a571b671 /src | |
parent | ba4d223cd976dce8504cbd4a86fbd9973e7b5c5a (diff) | |
download | postgresql-f59f3c88994063f2199f04853447510fd44c3635.tar.gz postgresql-f59f3c88994063f2199f04853447510fd44c3635.zip |
Add a SPI_copytupledesc function that parallels SPI_copytuple --- ie,
it copies the tupdesc into upper-executor memory. This is necessary
for returning tuple descriptors without leaking all of lower exec memory.
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/executor/spi.c | 33 | ||||
-rw-r--r-- | src/include/executor/spi.h | 24 |
2 files changed, 43 insertions, 14 deletions
diff --git a/src/backend/executor/spi.c b/src/backend/executor/spi.c index 7b4030d580a..8c6420ae4cc 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.56 2001/08/02 16:05:23 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/executor/spi.c,v 1.57 2001/08/02 18:08:43 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -333,6 +333,33 @@ SPI_copytuple(HeapTuple tuple) return ctuple; } +TupleDesc +SPI_copytupledesc(TupleDesc tupdesc) +{ + MemoryContext oldcxt = NULL; + TupleDesc ctupdesc; + + if (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); + } + + ctupdesc = CreateTupleDescCopy(tupdesc); + + if (oldcxt) + MemoryContextSwitchTo(oldcxt); + + return ctupdesc; +} + HeapTuple SPI_modifytuple(Relation rel, HeapTuple tuple, int natts, int *attnum, Datum *Values, char *Nulls) @@ -1232,7 +1259,7 @@ _SPI_end_call(bool procmem) } static bool -_SPI_checktuples() +_SPI_checktuples(void) { uint32 processed = _SPI_current->processed; SPITupleTable *tuptable = _SPI_current->tuptable; @@ -1244,8 +1271,8 @@ _SPI_checktuples() failed = true; } else -/* some tuples were processed */ { + /* some tuples were processed */ if (tuptable == NULL) /* spi_printtup was not called */ failed = true; else if (processed != (tuptable->alloced - tuptable->free)) diff --git a/src/include/executor/spi.h b/src/include/executor/spi.h index 3a7c7807942..bef68bc7a6e 100644 --- a/src/include/executor/spi.h +++ b/src/include/executor/spi.h @@ -2,6 +2,7 @@ * * spi.h * + * $Id: spi.h,v 1.28 2001/08/02 18:08:43 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -48,17 +49,17 @@ typedef struct HeapTuple *vals; /* tuples */ } SPITupleTable; -#define SPI_ERROR_CONNECT -1 -#define SPI_ERROR_COPY -2 -#define SPI_ERROR_OPUNKNOWN -3 -#define SPI_ERROR_UNCONNECTED -4 -#define SPI_ERROR_CURSOR -5 -#define SPI_ERROR_ARGUMENT -6 -#define SPI_ERROR_PARAM -7 -#define SPI_ERROR_TRANSACTION -8 -#define SPI_ERROR_NOATTRIBUTE -9 -#define SPI_ERROR_NOOUTFUNC -10 -#define SPI_ERROR_TYPUNKNOWN -11 +#define SPI_ERROR_CONNECT (-1) +#define SPI_ERROR_COPY (-2) +#define SPI_ERROR_OPUNKNOWN (-3) +#define SPI_ERROR_UNCONNECTED (-4) +#define SPI_ERROR_CURSOR (-5) +#define SPI_ERROR_ARGUMENT (-6) +#define SPI_ERROR_PARAM (-7) +#define SPI_ERROR_TRANSACTION (-8) +#define SPI_ERROR_NOATTRIBUTE (-9) +#define SPI_ERROR_NOOUTFUNC (-10) +#define SPI_ERROR_TYPUNKNOWN (-11) #define SPI_OK_CONNECT 1 #define SPI_OK_FINISH 2 @@ -87,6 +88,7 @@ extern void *SPI_saveplan(void *plan); extern int SPI_freeplan(void *plan); extern HeapTuple SPI_copytuple(HeapTuple tuple); +extern TupleDesc SPI_copytupledesc(TupleDesc tupdesc); extern HeapTuple SPI_modifytuple(Relation rel, HeapTuple tuple, int natts, int *attnum, Datum *Values, char *Nulls); extern int SPI_fnumber(TupleDesc tupdesc, char *fname); |