|
8 | 8 | *
|
9 | 9 | *
|
10 | 10 | * IDENTIFICATION
|
11 |
| - * $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.175 2006/08/14 21:14:41 tgl Exp $ |
| 11 | + * $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.176 2006/08/15 19:01:17 tgl Exp $ |
12 | 12 | *
|
13 | 13 | *-------------------------------------------------------------------------
|
14 | 14 | */
|
@@ -252,6 +252,12 @@ plpgsql_exec_function(PLpgSQL_function *func, FunctionCallInfo fcinfo)
|
252 | 252 | */
|
253 | 253 | exec_set_found(&estate, false);
|
254 | 254 |
|
| 255 | + /* |
| 256 | + * Let the instrumentation plugin peek at this function |
| 257 | + */ |
| 258 | + if (*plugin_ptr && (*plugin_ptr)->func_beg) |
| 259 | + ((*plugin_ptr)->func_beg)(&estate, func); |
| 260 | + |
255 | 261 | /*
|
256 | 262 | * Now call the toplevel block of statements
|
257 | 263 | */
|
@@ -387,6 +393,12 @@ plpgsql_exec_function(PLpgSQL_function *func, FunctionCallInfo fcinfo)
|
387 | 393 | }
|
388 | 394 | }
|
389 | 395 |
|
| 396 | + /* |
| 397 | + * Let the instrumentation plugin peek at this function |
| 398 | + */ |
| 399 | + if (*plugin_ptr && (*plugin_ptr)->func_end) |
| 400 | + ((*plugin_ptr)->func_end)(&estate, func); |
| 401 | + |
390 | 402 | /* Clean up any leftover temporary memory */
|
391 | 403 | FreeExprContext(estate.eval_econtext);
|
392 | 404 | estate.eval_econtext = NULL;
|
@@ -580,6 +592,12 @@ plpgsql_exec_trigger(PLpgSQL_function *func,
|
580 | 592 | */
|
581 | 593 | exec_set_found(&estate, false);
|
582 | 594 |
|
| 595 | + /* |
| 596 | + * Let the instrumentation plugin peek at this function |
| 597 | + */ |
| 598 | + if (*plugin_ptr && (*plugin_ptr)->func_beg) |
| 599 | + ((*plugin_ptr)->func_beg)(&estate, func); |
| 600 | + |
583 | 601 | /*
|
584 | 602 | * Now call the toplevel block of statements
|
585 | 603 | */
|
@@ -633,6 +651,12 @@ plpgsql_exec_trigger(PLpgSQL_function *func,
|
633 | 651 | rettup = SPI_copytuple((HeapTuple) (estate.retval));
|
634 | 652 | }
|
635 | 653 |
|
| 654 | + /* |
| 655 | + * Let the instrumentation plugin peek at this function |
| 656 | + */ |
| 657 | + if (*plugin_ptr && (*plugin_ptr)->func_end) |
| 658 | + ((*plugin_ptr)->func_end)(&estate, func); |
| 659 | + |
636 | 660 | /* Clean up any leftover temporary memory */
|
637 | 661 | FreeExprContext(estate.eval_econtext);
|
638 | 662 | estate.eval_econtext = NULL;
|
@@ -1037,6 +1061,10 @@ exec_stmt(PLpgSQL_execstate *estate, PLpgSQL_stmt *stmt)
|
1037 | 1061 | save_estmt = estate->err_stmt;
|
1038 | 1062 | estate->err_stmt = stmt;
|
1039 | 1063 |
|
| 1064 | + /* Let the plugin know that we are about to execute this statement */ |
| 1065 | + if (*plugin_ptr && (*plugin_ptr)->stmt_beg) |
| 1066 | + ((*plugin_ptr)->stmt_beg)(estate, stmt); |
| 1067 | + |
1040 | 1068 | CHECK_FOR_INTERRUPTS();
|
1041 | 1069 |
|
1042 | 1070 | switch (stmt->cmd_type)
|
@@ -1122,6 +1150,10 @@ exec_stmt(PLpgSQL_execstate *estate, PLpgSQL_stmt *stmt)
|
1122 | 1150 | elog(ERROR, "unrecognized cmdtype: %d", stmt->cmd_type);
|
1123 | 1151 | }
|
1124 | 1152 |
|
| 1153 | + /* Let the plugin know that we have finished executing this statement */ |
| 1154 | + if (*plugin_ptr && (*plugin_ptr)->stmt_end) |
| 1155 | + ((*plugin_ptr)->stmt_end)(estate, stmt); |
| 1156 | + |
1125 | 1157 | estate->err_stmt = save_estmt;
|
1126 | 1158 |
|
1127 | 1159 | return rc;
|
@@ -2123,6 +2155,21 @@ plpgsql_estate_setup(PLpgSQL_execstate *estate,
|
2123 | 2155 | * child of simple_eval_estate.
|
2124 | 2156 | */
|
2125 | 2157 | estate->eval_econtext = CreateExprContext(simple_eval_estate);
|
| 2158 | + |
| 2159 | + /* |
| 2160 | + * Let the plugin see this function before we initialize any |
| 2161 | + * local PL/pgSQL variables - note that we also give the plugin |
| 2162 | + * a few function pointers so it can call back into PL/pgSQL |
| 2163 | + * for doing things like variable assignments and stack traces |
| 2164 | + */ |
| 2165 | + if (*plugin_ptr) |
| 2166 | + { |
| 2167 | + (*plugin_ptr)->error_callback = plpgsql_exec_error_callback; |
| 2168 | + (*plugin_ptr)->assign_expr = exec_assign_expr; |
| 2169 | + |
| 2170 | + if ((*plugin_ptr)->func_setup) |
| 2171 | + ((*plugin_ptr)->func_setup)(estate, func); |
| 2172 | + } |
2126 | 2173 | }
|
2127 | 2174 |
|
2128 | 2175 | /* ----------
|
|
0 commit comments