@@ -590,58 +590,19 @@ void EXE_execute_db_triggers(thread_db* tdbb, jrd_tra* transaction, TriggerActio
590
590
// Execute DDL triggers.
591
591
void EXE_execute_ddl_triggers (thread_db* tdbb, jrd_tra* transaction, bool preTriggers, int action)
592
592
{
593
- Jrd::Attachment* attachment = tdbb->getAttachment ();
593
+ const auto attachment = tdbb->getAttachment ();
594
594
595
- // Our caller verifies (ATT_no_db_triggers) if DDL triggers should not run.
595
+ // Our caller verifies (ATT_no_db_triggers) if DDL triggers should not run
596
596
597
597
if (attachment->att_ddl_triggers )
598
598
{
599
- TrigVector triggers;
600
- TrigVector* triggersPtr = &triggers;
601
- HalfStaticArray<Trigger*, 4 > cachedTriggers;
602
-
603
- for (auto & trigger : *attachment->att_ddl_triggers )
604
- {
605
- const auto type = trigger.type & ~TRIGGER_TYPE_MASK;
606
- const bool preTrigger = ((type & 1 ) == 0 );
607
-
608
- if ((type & (1LL << action)) && (preTriggers == preTrigger))
609
- {
610
- triggers.add () = trigger;
611
- cachedTriggers.add (&trigger);
612
- }
613
- }
614
-
615
- if (triggers.hasData ())
616
- {
617
- FbLocalStatus tempStatus;
618
-
619
- jrd_tra* const oldTransaction = tdbb->getTransaction ();
620
- tdbb->setTransaction (transaction);
621
-
622
- try
623
- {
624
- EXE_execute_triggers (tdbb, &triggersPtr, NULL , NULL , TRIGGER_DDL,
625
- preTriggers ? StmtNode::PRE_TRIG : StmtNode::POST_TRIG);
626
- }
627
- catch (const Exception& ex)
628
- {
629
- ex.stuffException (&tempStatus);
630
- }
631
-
632
- tdbb->setTransaction (oldTransaction);
633
-
634
- // Triggers could be compiled inside EXE_execute_triggers(),
635
- // so ensure the new pointers are copied back to the cache
636
- fb_assert (triggers.getCount () == cachedTriggers.getCount ());
637
- for (unsigned i = 0 ; i < triggers.getCount (); i++)
638
- {
639
- *cachedTriggers[i] = triggers[i];
640
- triggers[i].extTrigger = nullptr ; // avoid deletion inside d'tor
641
- }
599
+ AutoSetRestore2<jrd_tra*, thread_db> tempTrans (tdbb,
600
+ &thread_db::getTransaction,
601
+ &thread_db::setTransaction,
602
+ transaction);
642
603
643
- tempStatus. check ();
644
- }
604
+ EXE_execute_triggers (tdbb, &attachment-> att_ddl_triggers , NULL , NULL , TRIGGER_DDL,
605
+ preTriggers ? StmtNode::PRE_TRIG : StmtNode::POST_TRIG, action);
645
606
}
646
607
}
647
608
@@ -1166,7 +1127,8 @@ void EXE_execute_triggers(thread_db* tdbb,
1166
1127
record_param* old_rpb,
1167
1128
record_param* new_rpb,
1168
1129
TriggerAction trigger_action,
1169
- StmtNode::WhichTrigger which_trig)
1130
+ StmtNode::WhichTrigger which_trig,
1131
+ int ddl_action)
1170
1132
{
1171
1133
/* *************************************
1172
1134
*
@@ -1219,6 +1181,20 @@ void EXE_execute_triggers(thread_db* tdbb,
1219
1181
{
1220
1182
for (TrigVector::iterator ptr = vector->begin (); ptr != vector->end (); ++ptr)
1221
1183
{
1184
+ if (trigger_action == TRIGGER_DDL && ddl_action)
1185
+ {
1186
+ // Skip triggers not matching our action
1187
+
1188
+ fb_assert (which_trig == StmtNode::PRE_TRIG || which_trig == StmtNode::POST_TRIG);
1189
+ const bool preTriggers = (which_trig == StmtNode::PRE_TRIG);
1190
+
1191
+ const auto type = ptr->type & ~TRIGGER_TYPE_MASK;
1192
+ const bool preTrigger = ((type & 1 ) == 0 );
1193
+
1194
+ if (!(type & (1LL << ddl_action)) || preTriggers != preTrigger)
1195
+ continue ;
1196
+ }
1197
+
1222
1198
ptr->compile (tdbb);
1223
1199
1224
1200
trigger = ptr->statement ->findRequest (tdbb);
0 commit comments