@@ -581,35 +581,13 @@ void EXE_execute_ddl_triggers(thread_db* tdbb, jrd_tra* transaction, bool preTri
581
581
582
582
if (attachment->att_ddl_triggers )
583
583
{
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);
591
588
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);
613
591
}
614
592
}
615
593
@@ -1092,10 +1070,12 @@ static void execute_looper(thread_db* tdbb,
1092
1070
1093
1071
1094
1072
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)
1099
1079
{
1100
1080
/* *************************************
1101
1081
*
@@ -1148,6 +1128,20 @@ void EXE_execute_triggers(thread_db* tdbb,
1148
1128
{
1149
1129
for (TrigVector::iterator ptr = vector->begin (); ptr != vector->end (); ++ptr)
1150
1130
{
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
+
1151
1145
ptr->compile (tdbb);
1152
1146
1153
1147
trigger = ptr->statement ->findRequest (tdbb);
0 commit comments