|
8 | 8 | *
|
9 | 9 | *
|
10 | 10 | * IDENTIFICATION
|
11 |
| - * $Header: /cvsroot/pgsql/src/backend/executor/spi.c,v 1.63 2001/11/21 18:30:58 tgl Exp $ |
| 11 | + * $Header: /cvsroot/pgsql/src/backend/executor/spi.c,v 1.64 2002/01/03 20:30:47 tgl Exp $ |
12 | 12 | *
|
13 | 13 | *-------------------------------------------------------------------------
|
14 | 14 | */
|
|
19 | 19 | #include "commands/command.h"
|
20 | 20 | #include "executor/spi_priv.h"
|
21 | 21 | #include "tcop/tcopprot.h"
|
| 22 | +#include "utils/lsyscache.h" |
22 | 23 |
|
23 | 24 |
|
24 | 25 | uint32 SPI_processed = 0;
|
@@ -782,16 +783,34 @@ SPI_cursor_open(char *name, void *plan, Datum *Values, char *Nulls)
|
782 | 783 | /* If the plan has parameters, put them into the executor state */
|
783 | 784 | if (spiplan->nargs > 0)
|
784 | 785 | {
|
785 |
| - ParamListInfo paramLI = (ParamListInfo) palloc((spiplan->nargs + 1) * |
786 |
| - sizeof(ParamListInfoData)); |
| 786 | + ParamListInfo paramLI; |
| 787 | + |
| 788 | + paramLI = (ParamListInfo) palloc((spiplan->nargs + 1) * |
| 789 | + sizeof(ParamListInfoData)); |
| 790 | + MemSet(paramLI, 0, (spiplan->nargs + 1) * sizeof(ParamListInfoData)); |
787 | 791 |
|
788 | 792 | eState->es_param_list_info = paramLI;
|
789 | 793 | for (k = 0; k < spiplan->nargs; paramLI++, k++)
|
790 | 794 | {
|
791 | 795 | paramLI->kind = PARAM_NUM;
|
792 | 796 | paramLI->id = k + 1;
|
793 | 797 | paramLI->isnull = (Nulls && Nulls[k] == 'n');
|
794 |
| - paramLI->value = Values[k]; |
| 798 | + if (paramLI->isnull) |
| 799 | + { |
| 800 | + /* nulls just copy */ |
| 801 | + paramLI->value = Values[k]; |
| 802 | + } |
| 803 | + else |
| 804 | + { |
| 805 | + /* pass-by-ref values must be copied into portal context */ |
| 806 | + int16 paramTypLen; |
| 807 | + bool paramTypByVal; |
| 808 | + |
| 809 | + get_typlenbyval(spiplan->argtypes[k], |
| 810 | + ¶mTypLen, ¶mTypByVal); |
| 811 | + paramLI->value = datumCopy(Values[k], |
| 812 | + paramTypByVal, paramTypLen); |
| 813 | + } |
795 | 814 | }
|
796 | 815 | paramLI->kind = PARAM_INVALID;
|
797 | 816 | }
|
@@ -1077,8 +1096,11 @@ _SPI_execute_plan(_SPI_plan *plan, Datum *Values, char *Nulls, int tcount)
|
1077 | 1096 | state = CreateExecutorState();
|
1078 | 1097 | if (nargs > 0)
|
1079 | 1098 | {
|
1080 |
| - ParamListInfo paramLI = (ParamListInfo) palloc((nargs + 1) * |
1081 |
| - sizeof(ParamListInfoData)); |
| 1099 | + ParamListInfo paramLI; |
| 1100 | + |
| 1101 | + paramLI = (ParamListInfo) palloc((nargs + 1) * |
| 1102 | + sizeof(ParamListInfoData)); |
| 1103 | + MemSet(paramLI, 0, (nargs + 1) * sizeof(ParamListInfoData)); |
1082 | 1104 |
|
1083 | 1105 | state->es_param_list_info = paramLI;
|
1084 | 1106 | for (k = 0; k < plan->nargs; paramLI++, k++)
|
|
0 commit comments