3
3
* procedural language
4
4
*
5
5
* IDENTIFICATION
6
- * $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.48 2001/10/25 05:50:20 momjian Exp $
6
+ * $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.49 2001/11/05 19:41:56 tgl Exp $
7
7
*
8
8
* This software is copyrighted by Jan Wieck - Hamburg.
9
9
*
@@ -400,32 +400,43 @@ plpgsql_exec_function(PLpgSQL_function * func, FunctionCallInfo fcinfo)
400
400
401
401
fcinfo -> isnull = estate .retisnull ;
402
402
403
- if (!estate .retistuple )
403
+ if (!estate .retisnull )
404
404
{
405
- estate .retval = exec_cast_value (estate .retval , estate .rettype ,
406
- func -> fn_rettype ,
407
- & (func -> fn_retinput ),
408
- func -> fn_rettypelem ,
409
- -1 ,
410
- & fcinfo -> isnull );
411
-
412
- /*
413
- * If the functions return type isn't by value, copy the value
414
- * into upper executor memory context.
415
- */
416
- if (!fcinfo -> isnull && !func -> fn_retbyval )
405
+ if (estate .retistuple )
406
+ {
407
+ /* Copy tuple to upper executor memory */
408
+ /* Here we need to return a TupleTableSlot not just a tuple */
409
+ estate .retval = (Datum )
410
+ SPI_copytupleintoslot ((HeapTuple ) (estate .retval ),
411
+ estate .rettupdesc );
412
+ }
413
+ else
417
414
{
418
- int len ;
419
- Datum tmp ;
415
+ /* Cast value to proper type */
416
+ estate .retval = exec_cast_value (estate .retval , estate .rettype ,
417
+ func -> fn_rettype ,
418
+ & (func -> fn_retinput ),
419
+ func -> fn_rettypelem ,
420
+ -1 ,
421
+ & fcinfo -> isnull );
422
+ /*
423
+ * If the functions return type isn't by value, copy the value
424
+ * into upper executor memory context.
425
+ */
426
+ if (!fcinfo -> isnull && !func -> fn_retbyval )
427
+ {
428
+ int len ;
429
+ Datum tmp ;
420
430
421
- if (func -> fn_rettyplen < 0 )
422
- len = VARSIZE (estate .retval );
423
- else
424
- len = func -> fn_rettyplen ;
431
+ if (func -> fn_rettyplen < 0 )
432
+ len = VARSIZE (estate .retval );
433
+ else
434
+ len = func -> fn_rettyplen ;
425
435
426
- tmp = (Datum ) SPI_palloc (len );
427
- memcpy ((void * ) tmp , (void * ) estate .retval , len );
428
- estate .retval = tmp ;
436
+ tmp = (Datum ) SPI_palloc (len );
437
+ memcpy ((void * ) tmp , (void * ) estate .retval , len );
438
+ estate .retval = tmp ;
439
+ }
429
440
}
430
441
}
431
442
@@ -1619,8 +1630,8 @@ exec_stmt_return(PLpgSQL_execstate * estate, PLpgSQL_stmt_return * stmt)
1619
1630
1620
1631
if (HeapTupleIsValid (rec -> tup ))
1621
1632
{
1622
- estate -> retval = (Datum ) SPI_copytuple ( rec -> tup ) ;
1623
- estate -> rettupdesc = SPI_copytupledesc ( rec -> tupdesc ) ;
1633
+ estate -> retval = (Datum ) rec -> tup ;
1634
+ estate -> rettupdesc = rec -> tupdesc ;
1624
1635
estate -> retisnull = false;
1625
1636
}
1626
1637
return PLPGSQL_RC_RETURN ;
@@ -1631,16 +1642,10 @@ exec_stmt_return(PLpgSQL_execstate * estate, PLpgSQL_stmt_return * stmt)
1631
1642
exec_run_select (estate , stmt -> expr , 1 , NULL );
1632
1643
if (estate -> eval_processed > 0 )
1633
1644
{
1634
- estate -> retval = (Datum ) SPI_copytuple ( estate -> eval_tuptable -> vals [0 ]) ;
1635
- estate -> rettupdesc = SPI_copytupledesc ( estate -> eval_tuptable -> tupdesc ) ;
1645
+ estate -> retval = (Datum ) estate -> eval_tuptable -> vals [0 ];
1646
+ estate -> rettupdesc = estate -> eval_tuptable -> tupdesc ;
1636
1647
estate -> retisnull = false;
1637
1648
}
1638
-
1639
- /*
1640
- * Okay to clean up here, since we already copied result tuple
1641
- * to upper executor.
1642
- */
1643
- exec_eval_cleanup (estate );
1644
1649
}
1645
1650
return PLPGSQL_RC_RETURN ;
1646
1651
}
0 commit comments