* procedural language
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.79 2003/02/16 02:30:39 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.80 2003/03/02 20:45:47 tgl Exp $
*
* This software is copyrighted by Jan Wieck - Hamburg.
*
if (rc != PLPGSQL_RC_OK)
{
/*
- * We're aborting the loop, so cleanup and set FOUND
+ * We're aborting the loop, so cleanup and set FOUND.
+ * (This code should match the code after the loop.)
*/
- exec_set_found(estate, found);
SPI_freetuptable(tuptab);
SPI_cursor_close(portal);
+ exec_set_found(estate, found);
if (rc == PLPGSQL_RC_EXIT)
{
}
/*
+ * Release last group of tuples
+ */
+ SPI_freetuptable(tuptab);
+
+ /*
* Close the implicit cursor
*/
SPI_cursor_close(portal);
if (n == 0)
exec_move_row(estate, rec, row, NULL, tuptab->tupdesc);
else
- found = true;
+ found = true; /* processed at least one tuple */
/*
* Now do the loop
*/
rc = exec_stmts(estate, stmt->body);
- /*
- * We're aborting the loop, so cleanup and set FOUND
- */
if (rc != PLPGSQL_RC_OK)
{
- exec_set_found(estate, found);
+ /*
+ * We're aborting the loop, so cleanup and set FOUND.
+ * (This code should match the code after the loop.)
+ */
SPI_freetuptable(tuptab);
SPI_cursor_close(portal);
+ exec_set_found(estate, found);
if (rc == PLPGSQL_RC_EXIT)
{
}
/*
- * Close the cursor
+ * Release last group of tuples
+ */
+ SPI_freetuptable(tuptab);
+
+ /*
+ * Close the implicit cursor
*/
SPI_cursor_close(portal);
pfree(curname);
/* ----------
- * Initialize the global found variable to false
- * ----------
- */
- exec_set_found(estate, false);
-
- /* ----------
* Determine if we fetch into a record or a row
* ----------
*/
if (stmt->rec != NULL)
rec = (PLpgSQL_rec *) (estate->datums[stmt->rec->recno]);
+ else if (stmt->row != NULL)
+ row = (PLpgSQL_row *) (estate->datums[stmt->row->rowno]);
else
- {
- if (stmt->row != NULL)
- row = (PLpgSQL_row *) (estate->datums[stmt->row->rowno]);
- else
- elog(ERROR, "unsupported target in exec_stmt_select()");
- }
+ elog(ERROR, "unsupported target in exec_stmt_fetch()");
/* ----------
* Fetch 1 tuple from the cursor
n = SPI_processed;
/* ----------
- * If the FETCH didn't return a row, set the target
- * to NULL and return with FOUND = false.
+ * Set the target and the global FOUND variable appropriately.
* ----------
*/
if (n == 0)
{
exec_move_row(estate, rec, row, NULL, tuptab->tupdesc);
- return PLPGSQL_RC_OK;
+ exec_set_found(estate, false);
+ }
+ else
+ {
+ exec_move_row(estate, rec, row, tuptab->vals[0], tuptab->tupdesc);
+ exec_set_found(estate, true);
}
-
- /* ----------
- * Put the result into the target and set found to true
- * ----------
- */
- exec_move_row(estate, rec, row, tuptab->vals[0], tuptab->tupdesc);
- exec_set_found(estate, true);
SPI_freetuptable(tuptab);