aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVadim B. Mikheev <vadim4o@yahoo.com>1997-09-25 12:16:05 +0000
committerVadim B. Mikheev <vadim4o@yahoo.com>1997-09-25 12:16:05 +0000
commitbb0cc20e64d29b05eb32fd9f970f9697d473000a (patch)
tree9a99fd9a6617c94f28d98e133cfad60c6a8e74ee
parentbe5241420ab960f37fb957723da11ed277ad887d (diff)
downloadpostgresql-bb0cc20e64d29b05eb32fd9f970f9697d473000a.tar.gz
postgresql-bb0cc20e64d29b05eb32fd9f970f9697d473000a.zip
Fix handling of SPI_tuptable.
-rw-r--r--src/backend/executor/spi.c31
1 files changed, 12 insertions, 19 deletions
diff --git a/src/backend/executor/spi.c b/src/backend/executor/spi.c
index 6a3d1485158..c1a584846ae 100644
--- a/src/backend/executor/spi.c
+++ b/src/backend/executor/spi.c
@@ -60,7 +60,7 @@ static int _SPI_begin_call(bool execmem);
static int _SPI_end_call(bool procmem);
static MemoryContext _SPI_execmem(void);
static MemoryContext _SPI_procmem(void);
-static bool _SPI_checktuples(bool isRetrieveIntoRelation);
+static bool _SPI_checktuples(void);
#ifdef SPI_EXECUTOR_STATS
extern int ShowExecutorStats;
@@ -774,19 +774,16 @@ _SPI_execute_plan(_SPI_plan * plan, Datum * Values, char *Nulls, int tcount)
static int
_SPI_pquery(QueryDesc * queryDesc, EState * state, int tcount)
{
- Query *parseTree;
- Plan *plan;
- int operation;
+ Query *parseTree = queryDesc->parsetree;
+ Plan *plan = queryDesc->plantree;
+ int operation = queryDesc->operation;
+ CommandDest dest = queryDesc->dest;
TupleDesc tupdesc;
bool isRetrieveIntoPortal = false;
bool isRetrieveIntoRelation = false;
char *intoName = NULL;
int res;
- parseTree = queryDesc->parsetree;
- plan = queryDesc->plantree;
- operation = queryDesc->operation;
-
switch (operation)
{
case CMD_SELECT:
@@ -804,6 +801,7 @@ _SPI_pquery(QueryDesc * queryDesc, EState * state, int tcount)
{
res = SPI_OK_SELINTO;
isRetrieveIntoRelation = true;
+ queryDesc->dest = None; /* */
}
break;
case CMD_INSERT:
@@ -844,7 +842,7 @@ _SPI_pquery(QueryDesc * queryDesc, EState * state, int tcount)
_SPI_current->processed = state->es_processed;
if (operation == CMD_SELECT && queryDesc->dest == SPI)
{
- if (_SPI_checktuples(isRetrieveIntoRelation))
+ if (_SPI_checktuples())
elog(FATAL, "SPI_select: # of processed tuples check failed");
}
@@ -858,11 +856,12 @@ _SPI_pquery(QueryDesc * queryDesc, EState * state, int tcount)
}
#endif
- if (queryDesc->dest == SPI)
+ if (dest == SPI)
{
SPI_processed = _SPI_current->processed;
SPI_tuptable = _SPI_current->tuptable;
}
+ queryDesc->dest = dest;
return (res);
@@ -898,7 +897,7 @@ _SPI_fetch(FetchStmt * stmt)
* context */
_SPI_current->processed = state->es_processed;
- if (_SPI_checktuples(false))
+ if (_SPI_checktuples())
elog(FATAL, "SPI_fetch: # of processed tuples check failed");
SPI_processed = _SPI_current->processed;
@@ -982,7 +981,7 @@ _SPI_end_call(bool procmem)
}
static bool
-_SPI_checktuples(bool isRetrieveIntoRelation)
+_SPI_checktuples()
{
uint32 processed = _SPI_current->processed;
SPITupleTable *tuptable = _SPI_current->tuptable;
@@ -993,15 +992,9 @@ _SPI_checktuples(bool isRetrieveIntoRelation)
if (tuptable != NULL)
failed = true;
}
- else
-/* some tuples were processed */
+ else /* some tuples were processed */
{
if (tuptable == NULL) /* spi_printtup was not called */
- {
- if (!isRetrieveIntoRelation)
- failed = true;
- }
- else if (isRetrieveIntoRelation)
failed = true;
else if (processed != (tuptable->alloced - tuptable->free))
failed = true;