33 * procedural language
44 *
55 * IDENTIFICATION
6- * $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.41 2001/04/30 20:05:40 tgl Exp $
6+ * $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.42 2001/05/08 01:00:53 tgl Exp $
77 *
88 * This software is copyrighted by Jan Wieck - Hamburg.
99 *
@@ -1344,6 +1344,8 @@ exec_stmt_fors(PLpgSQL_execstate * estate, PLpgSQL_stmt_fors * stmt)
13441344 */
13451345exec_run_select (estate ,stmt -> query ,0 );
13461346n = SPI_processed ;
1347+ tuptab = SPI_tuptable ;
1348+ SPI_tuptable = NULL ;
13471349
13481350/*
13491351 * If the query didn't return any row, set the target to NULL and
@@ -1363,9 +1365,6 @@ exec_stmt_fors(PLpgSQL_execstate * estate, PLpgSQL_stmt_fors * stmt)
13631365/*
13641366 * Now do the loop
13651367 */
1366- tuptab = SPI_tuptable ;
1367- SPI_tuptable = NULL ;
1368-
13691368for (i = 0 ;i < n ;i ++ )
13701369{
13711370
@@ -1445,6 +1444,8 @@ exec_stmt_select(PLpgSQL_execstate * estate, PLpgSQL_stmt_select * stmt)
14451444 */
14461445exec_run_select (estate ,stmt -> query ,1 );
14471446n = SPI_processed ;
1447+ tuptab = SPI_tuptable ;
1448+ SPI_tuptable = NULL ;
14481449
14491450/*
14501451 * If the query didn't return any row, set the target to NULL and
@@ -1459,9 +1460,6 @@ exec_stmt_select(PLpgSQL_execstate * estate, PLpgSQL_stmt_select * stmt)
14591460/*
14601461 * Put the result into the target and set found to true
14611462 */
1462- tuptab = SPI_tuptable ;
1463- SPI_tuptable = NULL ;
1464-
14651463exec_move_row (estate ,rec ,row ,tuptab -> vals [0 ],tuptab -> tupdesc );
14661464
14671465exec_set_found (estate , true);
@@ -2053,6 +2051,8 @@ exec_stmt_dynfors(PLpgSQL_execstate * estate, PLpgSQL_stmt_dynfors * stmt)
20532051pfree (querystr );
20542052
20552053n = SPI_processed ;
2054+ tuptab = SPI_tuptable ;
2055+ SPI_tuptable = NULL ;
20562056
20572057/*
20582058 * If the query didn't return any row, set the target to NULL and
@@ -2072,9 +2072,6 @@ exec_stmt_dynfors(PLpgSQL_execstate * estate, PLpgSQL_stmt_dynfors * stmt)
20722072/*
20732073 * Now do the loop
20742074 */
2075- tuptab = SPI_tuptable ;
2076- SPI_tuptable = NULL ;
2077-
20782075for (i = 0 ;i < n ;i ++ )
20792076{
20802077
@@ -2322,9 +2319,9 @@ exec_eval_expr(PLpgSQL_execstate * estate,
23222319 * Check that the expression returned one single Datum
23232320 */
23242321if (SPI_processed > 1 )
2325- elog (ERROR ,"query \"%s\"didn't return a single value " ,expr -> query );
2322+ elog (ERROR ,"query \"%s\"returned more than one row " ,expr -> query );
23262323if (SPI_tuptable -> tupdesc -> natts != 1 )
2327- elog (ERROR ,"query \"%s\"didn't return a single value " ,expr -> query );
2324+ elog (ERROR ,"query \"%s\"returned more than one column " ,expr -> query );
23282325
23292326/*
23302327 * Return the result and its type
@@ -2630,14 +2627,14 @@ exec_move_row(PLpgSQL_execstate * estate,
26302627if (i < t_natts )
26312628{
26322629value = SPI_getbinval (tup ,tupdesc ,i + 1 ,& isnull );
2630+ valtype = SPI_gettypeid (tupdesc ,i + 1 );
26332631}
26342632else
26352633{
26362634value = (Datum )0 ;
26372635isnull = true;
2636+ valtype = InvalidOid ;
26382637}
2639- /* tupdesc should have entries for all columns I expect... */
2640- valtype = SPI_gettypeid (tupdesc ,i + 1 );
26412638
26422639exec_assign_value (estate ,estate -> datums [row -> varnos [i ]],
26432640value ,valtype ,& isnull );