---------- * plpgsql_exec_trigger Called by the call handler for * trigger execution. * ---------- */
| 903 | * ---------- |
| 904 | */ |
| 905 | HeapTuple |
| 906 | plpgsql_exec_trigger(PLpgSQL_function *func, |
| 907 | TriggerData *trigdata) |
| 908 | { |
| 909 | PLpgSQL_execstate estate; |
| 910 | ErrorContextCallback plerrcontext; |
| 911 | int rc; |
| 912 | TupleDesc tupdesc; |
| 913 | PLpgSQL_rec *rec_new, |
| 914 | *rec_old; |
| 915 | HeapTuple rettup; |
| 916 | |
| 917 | /* |
| 918 | * Setup the execution state |
| 919 | */ |
| 920 | plpgsql_estate_setup(&estate, func, NULL, NULL, NULL); |
| 921 | estate.trigdata = trigdata; |
| 922 | |
| 923 | /* |
| 924 | * Setup error traceback support for ereport() |
| 925 | */ |
| 926 | plerrcontext.callback = plpgsql_exec_error_callback; |
| 927 | plerrcontext.arg = &estate; |
| 928 | plerrcontext.previous = error_context_stack; |
| 929 | error_context_stack = &plerrcontext; |
| 930 | |
| 931 | /* |
| 932 | * Make local execution copies of all the datums |
| 933 | */ |
| 934 | estate.err_text = gettext_noop("during initialization of execution state"); |
| 935 | copy_plpgsql_datums(&estate, func); |
| 936 | |
| 937 | /* |
| 938 | * Put the OLD and NEW tuples into record variables |
| 939 | * |
| 940 | * We set up expanded records for both variables even though only one may |
| 941 | * have a value. This allows record references to succeed in functions |
| 942 | * that are used for multiple trigger types. For example, we might have a |
| 943 | * test like "if (TG_OP = 'INSERT' and NEW.foo = 'xyz')", which should |
| 944 | * work regardless of the current trigger type. If a value is actually |
| 945 | * fetched from an unsupplied tuple, it will read as NULL. |
| 946 | */ |
| 947 | tupdesc = RelationGetDescr(trigdata->tg_relation); |
| 948 | |
| 949 | rec_new = (PLpgSQL_rec *) (estate.datums[func->new_varno]); |
| 950 | rec_old = (PLpgSQL_rec *) (estate.datums[func->old_varno]); |
| 951 | |
| 952 | rec_new->erh = make_expanded_record_from_tupdesc(tupdesc, |
| 953 | estate.datum_context); |
| 954 | rec_old->erh = make_expanded_record_from_exprecord(rec_new->erh, |
| 955 | estate.datum_context); |
| 956 | |
| 957 | if (!TRIGGER_FIRED_FOR_ROW(trigdata->tg_event)) |
| 958 | { |
| 959 | /* |
| 960 | * Per-statement triggers don't use OLD/NEW variables |
| 961 | */ |
| 962 | } |
no test coverage detected