Skip to content

Commit eeb9294

Browse files
committed
Backported part of PR #7426 that is necessary to fix #8079
1 parent 6ee48f4 commit eeb9294

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
@@ -581,35 +581,13 @@ void EXE_execute_ddl_triggers(thread_db* tdbb, jrd_tra* transaction, bool preTri
581581

582582
if (attachment->att_ddl_triggers)
583583
{
584-
jrd_tra* const oldTransaction = tdbb->getTransaction();
585-
tdbb->setTransaction(transaction);
586-
587-
try
588-
{
589-
TrigVector triggers;
590-
TrigVector* triggersPtr = &triggers;
584+
AutoSetRestore2<jrd_tra*, thread_db> tempTrans(tdbb,
585+
&thread_db::getTransaction,
586+
&thread_db::setTransaction,
587+
transaction);
591588

592-
for (TrigVector::iterator i = attachment->att_ddl_triggers->begin();
593-
i != attachment->att_ddl_triggers->end();
594-
++i)
595-
{
596-
if ((i->type & (1LL << action)) &&
597-
((preTriggers && (i->type & 0x1) == 0) || (!preTriggers && (i->type & 0x1) == 0x1)))
598-
{
599-
triggers.add() = *i;
600-
}
601-
}
602-
603-
EXE_execute_triggers(tdbb, &triggersPtr, NULL, NULL, TRIGGER_DDL,
604-
StmtNode::ALL_TRIGS);
605-
606-
tdbb->setTransaction(oldTransaction);
607-
}
608-
catch (...)
609-
{
610-
tdbb->setTransaction(oldTransaction);
611-
throw;
612-
}
589+
EXE_execute_triggers(tdbb, &attachment->att_ddl_triggers, NULL, NULL, TRIGGER_DDL,
590+
preTriggers ? StmtNode::PRE_TRIG : StmtNode::POST_TRIG, action);
613591
}
614592
}
615593

@@ -1092,10 +1070,12 @@ static void execute_looper(thread_db* tdbb,
10921070

10931071

10941072
void EXE_execute_triggers(thread_db* tdbb,
1095-
TrigVector** triggers,
1096-
record_param* old_rpb,
1097-
record_param* new_rpb,
1098-
TriggerAction trigger_action, StmtNode::WhichTrigger which_trig)
1073+
TrigVector** triggers,
1074+
record_param* old_rpb,
1075+
record_param* new_rpb,
1076+
TriggerAction trigger_action,
1077+
StmtNode::WhichTrigger which_trig,
1078+
int ddl_action)
10991079
{
11001080
/**************************************
11011081
*
@@ -1148,6 +1128,20 @@ void EXE_execute_triggers(thread_db* tdbb,
11481128
{
11491129
for (TrigVector::iterator ptr = vector->begin(); ptr != vector->end(); ++ptr)
11501130
{
1131+
if (trigger_action == TRIGGER_DDL && ddl_action)
1132+
{
1133+
// Skip triggers not matching our action
1134+
1135+
fb_assert(which_trig == StmtNode::PRE_TRIG || which_trig == StmtNode::POST_TRIG);
1136+
const bool preTriggers = (which_trig == StmtNode::PRE_TRIG);
1137+
1138+
const auto type = ptr->type & ~TRIGGER_TYPE_MASK;
1139+
const bool preTrigger = ((type & 1) == 0);
1140+
1141+
if (!(type & (1LL << ddl_action)) || preTriggers != preTrigger)
1142+
continue;
1143+
}
1144+
11511145
ptr->compile(tdbb);
11521146

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

src/jrd/exe_proto.h

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

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

5151
void EXE_receive(Jrd::thread_db*, Jrd::jrd_req*, USHORT, ULONG, void*, bool = false);
5252
void EXE_release(Jrd::thread_db*, Jrd::jrd_req*);

0 commit comments

Comments
 (0)