|
3 | 3 | * procedural language |
4 | 4 | * |
5 | 5 | * IDENTIFICATION |
6 | | - * $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.114 2004/08/02 17:03:45 tgl Exp $ |
| 6 | + * $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.115 2004/08/13 18:47:56 tgl Exp $ |
7 | 7 | * |
8 | 8 | * This software is copyrighted by Jan Wieck - Hamburg. |
9 | 9 | * |
@@ -2090,8 +2090,29 @@ exec_prepare_plan(PLpgSQL_execstate * estate, |
2090 | 2090 | */ |
2091 | 2091 | plan = SPI_prepare(expr->query, expr->nparams, argtypes); |
2092 | 2092 | if (plan == NULL) |
2093 | | - elog(ERROR, "SPI_prepare failed for \"%s\": %s", |
2094 | | - expr->query, SPI_result_code_string(SPI_result)); |
| 2093 | + { |
| 2094 | + /* Some SPI errors deserve specific error messages */ |
| 2095 | + switch (SPI_result) |
| 2096 | + { |
| 2097 | + case SPI_ERROR_COPY: |
| 2098 | + ereport(ERROR, |
| 2099 | + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), |
| 2100 | + errmsg("cannot COPY to/from client in PL/pgSQL"))); |
| 2101 | + case SPI_ERROR_CURSOR: |
| 2102 | + ereport(ERROR, |
| 2103 | + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), |
| 2104 | + errmsg("cannot manipulate cursors directly in PL/pgSQL"), |
| 2105 | + errhint("Use PL/pgSQL's cursor features instead."))); |
| 2106 | + case SPI_ERROR_TRANSACTION: |
| 2107 | + ereport(ERROR, |
| 2108 | + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), |
| 2109 | + errmsg("cannot begin/end transactions in PL/pgSQL"), |
| 2110 | + errhint("Use a BEGIN block with an EXCEPTION clause instead."))); |
| 2111 | + default: |
| 2112 | + elog(ERROR, "SPI_prepare failed for \"%s\": %s", |
| 2113 | + expr->query, SPI_result_code_string(SPI_result)); |
| 2114 | + } |
| 2115 | + } |
2095 | 2116 | expr->plan = SPI_saveplan(plan); |
2096 | 2117 | spi_plan = (_SPI_plan *) expr->plan; |
2097 | 2118 | expr->plan_argtypes = spi_plan->argtypes; |
@@ -2272,6 +2293,22 @@ exec_stmt_dynexecute(PLpgSQL_execstate * estate, |
2272 | 2293 | break; |
2273 | 2294 | } |
2274 | 2295 |
|
| 2296 | + /* Some SPI errors deserve specific error messages */ |
| 2297 | + case SPI_ERROR_COPY: |
| 2298 | + ereport(ERROR, |
| 2299 | + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), |
| 2300 | + errmsg("cannot COPY to/from client in PL/pgSQL"))); |
| 2301 | + case SPI_ERROR_CURSOR: |
| 2302 | + ereport(ERROR, |
| 2303 | + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), |
| 2304 | + errmsg("cannot manipulate cursors directly in PL/pgSQL"), |
| 2305 | + errhint("Use PL/pgSQL's cursor features instead."))); |
| 2306 | + case SPI_ERROR_TRANSACTION: |
| 2307 | + ereport(ERROR, |
| 2308 | + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), |
| 2309 | + errmsg("cannot begin/end transactions in PL/pgSQL"), |
| 2310 | + errhint("Use a BEGIN block with an EXCEPTION clause instead."))); |
| 2311 | + |
2275 | 2312 | default: |
2276 | 2313 | elog(ERROR, "SPI_exec failed executing query \"%s\": %s", |
2277 | 2314 | querystr, SPI_result_code_string(exec_res)); |
|
0 commit comments