diff --git a/src/jrd/exe.cpp b/src/jrd/exe.cpp index 630a608163..254f219248 100644 --- a/src/jrd/exe.cpp +++ b/src/jrd/exe.cpp @@ -1070,11 +1070,9 @@ void EXE_execute_triggers(thread_db* tdbb, AutoPtr null_rec; - if (!old_rec && !new_rec) - { - // this is a database trigger - } - else if (!old_rec || !new_rec) + const bool is_db_trigger = (!old_rec && !new_rec); + + if (!is_db_trigger && (!old_rec || !new_rec)) { const Record* record = old_rec ? old_rec : new_rec; fb_assert(record && record->rec_format); @@ -1097,39 +1095,42 @@ void EXE_execute_triggers(thread_db* tdbb, jrd_req* trigger = ptr->statement->findRequest(tdbb); - if (trigger->req_rpb.getCount() > 0) + if (!is_db_trigger) { - trigger->req_rpb[0].rpb_record = old_rec ? old_rec : null_rec.get(); - - if (old_rec && trigger_action != jrd_req::req_trigger_insert) + if (trigger->req_rpb.getCount() > 0) { - trigger->req_rpb[0].rpb_number = old_rpb->rpb_number; - trigger->req_rpb[0].rpb_number.setValid(true); - } - else - trigger->req_rpb[0].rpb_number.setValid(false); - } + trigger->req_rpb[0].rpb_record = old_rec ? old_rec : null_rec.get(); - if (trigger->req_rpb.getCount() > 1) - trigger->req_rpb[1].rpb_record = new_rec ? new_rec : null_rec.get(); - - if (new_rec && !(which_trig == StmtNode::PRE_TRIG && - trigger_action == jrd_req::req_trigger_insert)) - { - if (which_trig == StmtNode::PRE_TRIG && - trigger_action == jrd_req::req_trigger_update) - { - new_rpb->rpb_number = old_rpb->rpb_number; + if (old_rec && trigger_action != jrd_req::req_trigger_insert) + { + trigger->req_rpb[0].rpb_number = old_rpb->rpb_number; + trigger->req_rpb[0].rpb_number.setValid(true); + } + else + trigger->req_rpb[0].rpb_number.setValid(false); } if (trigger->req_rpb.getCount() > 1) + trigger->req_rpb[1].rpb_record = new_rec ? new_rec : null_rec.get(); + + if (new_rec && !(which_trig == StmtNode::PRE_TRIG && + trigger_action == jrd_req::req_trigger_insert)) { - trigger->req_rpb[1].rpb_number = new_rpb->rpb_number; - trigger->req_rpb[1].rpb_number.setValid(true); + if (which_trig == StmtNode::PRE_TRIG && + trigger_action == jrd_req::req_trigger_update) + { + new_rpb->rpb_number = old_rpb->rpb_number; + } + + if (trigger->req_rpb.getCount() > 1) + { + trigger->req_rpb[1].rpb_number = new_rpb->rpb_number; + trigger->req_rpb[1].rpb_number.setValid(true); + } } + else if (trigger->req_rpb.getCount() > 1) + trigger->req_rpb[1].rpb_number.setValid(false); } - else if (trigger->req_rpb.getCount() > 1) - trigger->req_rpb[1].rpb_number.setValid(false); trigger->req_timestamp = timestamp; trigger->req_trigger_action = trigger_action;