@@ -553,35 +553,13 @@ void EXE_execute_ddl_triggers(thread_db* tdbb, jrd_tra* transaction, bool preTri
553
553
554
554
if (attachment->att_ddl_triggers )
555
555
{
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);
563
560
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);
585
563
}
586
564
}
587
565
@@ -1009,10 +987,12 @@ static void execute_looper(thread_db* tdbb,
1009
987
1010
988
1011
989
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)
1016
996
{
1017
997
/* *************************************
1018
998
*
@@ -1061,6 +1041,20 @@ void EXE_execute_triggers(thread_db* tdbb,
1061
1041
{
1062
1042
for (TrigVector::iterator ptr = vector->begin (); ptr != vector->end (); ++ptr)
1063
1043
{
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
+
1064
1058
ptr->compile (tdbb);
1065
1059
1066
1060
trigger = ptr->statement ->findRequest (tdbb);
0 commit comments