|
8 | 8 | * |
9 | 9 | * |
10 | 10 | * IDENTIFICATION |
11 | | - * $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.253 2010/01/02 16:58:13 momjian Exp $ |
| 11 | + * $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.254 2010/01/19 01:35:31 tgl Exp $ |
12 | 12 | * |
13 | 13 | *------------------------------------------------------------------------- |
14 | 14 | */ |
@@ -200,7 +200,8 @@ static PreparedParamsData *exec_eval_using_params(PLpgSQL_execstate *estate, |
200 | 200 | List *params); |
201 | 201 | static void free_params_data(PreparedParamsData *ppd); |
202 | 202 | static Portal exec_dynquery_with_params(PLpgSQL_execstate *estate, |
203 | | - PLpgSQL_expr *query, List *params); |
| 203 | + PLpgSQL_expr *dynquery, List *params, |
| 204 | + const char *portalname, int cursorOptions); |
204 | 205 |
|
205 | 206 |
|
206 | 207 | /* ---------- |
@@ -2337,7 +2338,7 @@ exec_stmt_return_query(PLpgSQL_execstate *estate, |
2337 | 2338 | /* RETURN QUERY EXECUTE */ |
2338 | 2339 | Assert(stmt->dynquery != NULL); |
2339 | 2340 | portal = exec_dynquery_with_params(estate, stmt->dynquery, |
2340 | | - stmt->params); |
| 2341 | + stmt->params, NULL, 0); |
2341 | 2342 | } |
2342 | 2343 |
|
2343 | 2344 | tupmap = convert_tuples_by_position(portal->tupDesc, |
@@ -3133,7 +3134,8 @@ exec_stmt_dynfors(PLpgSQL_execstate *estate, PLpgSQL_stmt_dynfors *stmt) |
3133 | 3134 | Portal portal; |
3134 | 3135 | int rc; |
3135 | 3136 |
|
3136 | | - portal = exec_dynquery_with_params(estate, stmt->query, stmt->params); |
| 3137 | + portal = exec_dynquery_with_params(estate, stmt->query, stmt->params, |
| 3138 | + NULL, 0); |
3137 | 3139 |
|
3138 | 3140 | /* |
3139 | 3141 | * Execute the loop |
@@ -3161,7 +3163,6 @@ exec_stmt_open(PLpgSQL_execstate *estate, PLpgSQL_stmt_open *stmt) |
3161 | 3163 | PLpgSQL_expr *query; |
3162 | 3164 | Portal portal; |
3163 | 3165 | ParamListInfo paramLI; |
3164 | | - bool isnull; |
3165 | 3166 |
|
3166 | 3167 | /* ---------- |
3167 | 3168 | * Get the cursor variable and if it has an assigned name, check |
@@ -3201,43 +3202,11 @@ exec_stmt_open(PLpgSQL_execstate *estate, PLpgSQL_stmt_open *stmt) |
3201 | 3202 | * This is an OPEN refcursor FOR EXECUTE ... |
3202 | 3203 | * ---------- |
3203 | 3204 | */ |
3204 | | - Datum queryD; |
3205 | | - Oid restype; |
3206 | | - char *querystr; |
3207 | | - SPIPlanPtr curplan; |
3208 | | - |
3209 | | - /* ---------- |
3210 | | - * We evaluate the string expression after the |
3211 | | - * EXECUTE keyword. It's result is the querystring we have |
3212 | | - * to execute. |
3213 | | - * ---------- |
3214 | | - */ |
3215 | | - queryD = exec_eval_expr(estate, stmt->dynquery, &isnull, &restype); |
3216 | | - if (isnull) |
3217 | | - ereport(ERROR, |
3218 | | - (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), |
3219 | | - errmsg("query string argument of EXECUTE is null"))); |
3220 | | - |
3221 | | - /* Get the C-String representation */ |
3222 | | - querystr = convert_value_to_string(queryD, restype); |
3223 | | - |
3224 | | - exec_eval_cleanup(estate); |
3225 | | - |
3226 | | - /* ---------- |
3227 | | - * Now we prepare a query plan for it and open a cursor |
3228 | | - * ---------- |
3229 | | - */ |
3230 | | - curplan = SPI_prepare_cursor(querystr, 0, NULL, stmt->cursor_options); |
3231 | | - if (curplan == NULL) |
3232 | | - elog(ERROR, "SPI_prepare_cursor failed for \"%s\": %s", |
3233 | | - querystr, SPI_result_code_string(SPI_result)); |
3234 | | - portal = SPI_cursor_open(curname, curplan, NULL, NULL, |
3235 | | - estate->readonly_func); |
3236 | | - if (portal == NULL) |
3237 | | - elog(ERROR, "could not open cursor for query \"%s\": %s", |
3238 | | - querystr, SPI_result_code_string(SPI_result)); |
3239 | | - pfree(querystr); |
3240 | | - SPI_freeplan(curplan); |
| 3205 | + portal = exec_dynquery_with_params(estate, |
| 3206 | + stmt->dynquery, |
| 3207 | + stmt->params, |
| 3208 | + curname, |
| 3209 | + stmt->cursor_options); |
3241 | 3210 |
|
3242 | 3211 | /* |
3243 | 3212 | * If cursor variable was NULL, store the generated portal name in it |
@@ -5530,8 +5499,11 @@ free_params_data(PreparedParamsData *ppd) |
5530 | 5499 | * Open portal for dynamic query |
5531 | 5500 | */ |
5532 | 5501 | static Portal |
5533 | | -exec_dynquery_with_params(PLpgSQL_execstate *estate, PLpgSQL_expr *dynquery, |
5534 | | - List *params) |
| 5502 | +exec_dynquery_with_params(PLpgSQL_execstate *estate, |
| 5503 | + PLpgSQL_expr *dynquery, |
| 5504 | + List *params, |
| 5505 | + const char *portalname, |
| 5506 | + int cursorOptions) |
5535 | 5507 | { |
5536 | 5508 | Portal portal; |
5537 | 5509 | Datum query; |
@@ -5564,20 +5536,22 @@ exec_dynquery_with_params(PLpgSQL_execstate *estate, PLpgSQL_expr *dynquery, |
5564 | 5536 | PreparedParamsData *ppd; |
5565 | 5537 |
|
5566 | 5538 | ppd = exec_eval_using_params(estate, params); |
5567 | | - portal = SPI_cursor_open_with_args(NULL, |
| 5539 | + portal = SPI_cursor_open_with_args(portalname, |
5568 | 5540 | querystr, |
5569 | 5541 | ppd->nargs, ppd->types, |
5570 | 5542 | ppd->values, ppd->nulls, |
5571 | | - estate->readonly_func, 0); |
| 5543 | + estate->readonly_func, |
| 5544 | + cursorOptions); |
5572 | 5545 | free_params_data(ppd); |
5573 | 5546 | } |
5574 | 5547 | else |
5575 | 5548 | { |
5576 | | - portal = SPI_cursor_open_with_args(NULL, |
| 5549 | + portal = SPI_cursor_open_with_args(portalname, |
5577 | 5550 | querystr, |
5578 | 5551 | 0, NULL, |
5579 | 5552 | NULL, NULL, |
5580 | | - estate->readonly_func, 0); |
| 5553 | + estate->readonly_func, |
| 5554 | + cursorOptions); |
5581 | 5555 | } |
5582 | 5556 |
|
5583 | 5557 | if (portal == NULL) |
|
0 commit comments