|
8 | 8 | *
|
9 | 9 | *
|
10 | 10 | * IDENTIFICATION
|
11 |
| - * $PostgreSQL: pgsql/src/backend/executor/spi.c,v 1.187 2008/01/01 19:45:49 momjian Exp $ |
| 11 | + * $PostgreSQL: pgsql/src/backend/executor/spi.c,v 1.188 2008/02/12 04:09:44 tgl Exp $ |
12 | 12 | *
|
13 | 13 | *-------------------------------------------------------------------------
|
14 | 14 | */
|
@@ -886,6 +886,10 @@ SPI_cursor_open(const char *name, SPIPlanPtr plan,
|
886 | 886 | Assert(list_length(plan->plancache_list) == 1);
|
887 | 887 | plansource = (CachedPlanSource *) linitial(plan->plancache_list);
|
888 | 888 |
|
| 889 | + /* Push the SPI stack */ |
| 890 | + if (_SPI_begin_call(false) < 0) |
| 891 | + elog(ERROR, "SPI_cursor_open called while not connected"); |
| 892 | + |
889 | 893 | /* Reset SPI result (note we deliberately don't touch lastoid) */
|
890 | 894 | SPI_processed = 0;
|
891 | 895 | SPI_tuptable = NULL;
|
@@ -1041,6 +1045,9 @@ SPI_cursor_open(const char *name, SPIPlanPtr plan,
|
1041 | 1045 |
|
1042 | 1046 | Assert(portal->strategy != PORTAL_MULTI_QUERY);
|
1043 | 1047 |
|
| 1048 | + /* Pop the SPI stack */ |
| 1049 | + _SPI_end_call(false); |
| 1050 | + |
1044 | 1051 | /* Return the created portal */
|
1045 | 1052 | return portal;
|
1046 | 1053 | }
|
@@ -1180,16 +1187,27 @@ SPI_is_cursor_plan(SPIPlanPtr plan)
|
1180 | 1187 | }
|
1181 | 1188 |
|
1182 | 1189 | if (list_length(plan->plancache_list) != 1)
|
| 1190 | + { |
| 1191 | + SPI_result = 0; |
1183 | 1192 | return false; /* not exactly 1 pre-rewrite command */
|
| 1193 | + } |
1184 | 1194 | plansource = (CachedPlanSource *) linitial(plan->plancache_list);
|
1185 | 1195 |
|
| 1196 | + /* Need _SPI_begin_call in case replanning invokes SPI-using functions */ |
| 1197 | + SPI_result = _SPI_begin_call(false); |
| 1198 | + if (SPI_result < 0) |
| 1199 | + return false; |
| 1200 | + |
1186 | 1201 | if (plan->saved)
|
1187 | 1202 | {
|
1188 | 1203 | /* Make sure the plan is up to date */
|
1189 | 1204 | cplan = RevalidateCachedPlan(plansource, true);
|
1190 | 1205 | ReleaseCachedPlan(cplan, true);
|
1191 | 1206 | }
|
1192 | 1207 |
|
| 1208 | + _SPI_end_call(false); |
| 1209 | + SPI_result = 0; |
| 1210 | + |
1193 | 1211 | /* Does it return tuples? */
|
1194 | 1212 | if (plansource->resultDesc)
|
1195 | 1213 | return true;
|
|
0 commit comments