Skip to content

Commit 007ddc6

Browse files
committed
Backported part of PR #7426 that is necessary to fix #8079
1 parent da67df2 commit 007ddc6

File tree

2 files changed

+27
-33
lines changed

2 files changed

+27
-33
lines changed

src/jrd/exe.cpp

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -553,35 +553,13 @@ void EXE_execute_ddl_triggers(thread_db* tdbb, jrd_tra* transaction, bool preTri
553553

554554
if (attachment->att_ddl_triggers)
555555
{
556-
jrd_tra* const oldTransaction = tdbb->getTransaction();
557-
tdbb->setTransaction(transaction);
558-
559-
try
560-
{
561-
TrigVector triggers;
562-
TrigVector* triggersPtr = &triggers;
556+
AutoSetRestore2<jrd_tra*, thread_db> tempTrans(tdbb,
557+
&thread_db::getTransaction,
558+
&thread_db::setTransaction,
559+
transaction);
563560

564-
for (TrigVector::iterator i = attachment->att_ddl_triggers->begin();
565-
i != attachment->att_ddl_triggers->end();
566-
++i)
567-
{
568-
if ((i->type & (1LL << action)) &&
569-
((preTriggers && (i->type & 0x1) == 0) || (!preTriggers && (i->type & 0x1) == 0x1)))
570-
{
571-
triggers.add() = *i;
572-
}
573-
}
574-
575-
EXE_execute_triggers(tdbb, &triggersPtr, NULL, NULL, TRIGGER_DDL,
576-
StmtNode::ALL_TRIGS);
577-
578-
tdbb->setTransaction(oldTransaction);
579-
}
580-
catch (...)
581-
{
582-
tdbb->setTransaction(oldTransaction);
583-
throw;
584-
}
561+
EXE_execute_triggers(tdbb, &attachment->att_ddl_triggers, NULL, NULL, TRIGGER_DDL,
562+
preTriggers ? StmtNode::PRE_TRIG : StmtNode::POST_TRIG, action);
585563
}
586564
}
587565

@@ -1009,10 +987,12 @@ static void execute_looper(thread_db* tdbb,
1009987

1010988

1011989
void EXE_execute_triggers(thread_db* tdbb,
1012-
TrigVector** triggers,
1013-
record_param* old_rpb,
1014-
record_param* new_rpb,
1015-
TriggerAction trigger_action, StmtNode::WhichTrigger which_trig)
990+
TrigVector** triggers,
991+
record_param* old_rpb,
992+
record_param* new_rpb,
993+
TriggerAction trigger_action,
994+
StmtNode::WhichTrigger which_trig,
995+
int ddl_action)
1016996
{
1017997
/**************************************
1018998
*
@@ -1061,6 +1041,20 @@ void EXE_execute_triggers(thread_db* tdbb,
10611041
{
10621042
for (TrigVector::iterator ptr = vector->begin(); ptr != vector->end(); ++ptr)
10631043
{
1044+
if (trigger_action == TRIGGER_DDL && ddl_action)
1045+
{
1046+
// Skip triggers not matching our action
1047+
1048+
fb_assert(which_trig == StmtNode::PRE_TRIG || which_trig == StmtNode::POST_TRIG);
1049+
const bool preTriggers = (which_trig == StmtNode::PRE_TRIG);
1050+
1051+
const FB_UINT64 type = ptr->type & ~TRIGGER_TYPE_MASK;
1052+
const bool preTrigger = ((type & 1) == 0);
1053+
1054+
if (!(type & (1LL << ddl_action)) || preTriggers != preTrigger)
1055+
continue;
1056+
}
1057+
10641058
ptr->compile(tdbb);
10651059

10661060
trigger = ptr->statement->findRequest(tdbb);

src/jrd/exe_proto.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const Jrd::StmtNode* EXE_looper(Jrd::thread_db* tdbb, Jrd::jrd_req* request,
4444
const Jrd::StmtNode* in_node);
4545

4646
void EXE_execute_triggers(Jrd::thread_db*, Jrd::TrigVector**, Jrd::record_param*, Jrd::record_param*,
47-
enum TriggerAction, Jrd::StmtNode::WhichTrigger);
47+
enum TriggerAction, Jrd::StmtNode::WhichTrigger, int = 0);
4848

4949
void EXE_receive(Jrd::thread_db*, Jrd::jrd_req*, USHORT, ULONG, UCHAR*, bool = false);
5050
void EXE_release(Jrd::thread_db*, Jrd::jrd_req*);

0 commit comments

Comments
 (0)