8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-22 16:43:03 +01:00

Ensure the DDL trigger requests are cached (#7426)

While this commit does not fix all problems with cached triggers, I see no good reason to defer it.
This commit is contained in:
Dmitry Yemanov 2023-09-04 09:31:07 +03:00 committed by GitHub
parent 0493422c9f
commit 00c2d10102
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -560,8 +560,9 @@ void EXE_execute_ddl_triggers(thread_db* tdbb, jrd_tra* transaction, bool preTri
{
TrigVector triggers;
TrigVector* triggersPtr = &triggers;
HalfStaticArray<Trigger*, 4> cachedTriggers;
for (const auto& trigger : *attachment->att_ddl_triggers)
for (auto& trigger : *attachment->att_ddl_triggers)
{
const auto type = trigger.type & ~TRIGGER_TYPE_MASK;
const bool preTrigger = ((type & 1) == 0);
@ -569,11 +570,14 @@ void EXE_execute_ddl_triggers(thread_db* tdbb, jrd_tra* transaction, bool preTri
if ((type & (1LL << action)) && (preTriggers == preTrigger))
{
triggers.add() = trigger;
cachedTriggers.add(&trigger);
}
}
if (triggers.hasData())
{
FbLocalStatus tempStatus;
jrd_tra* const oldTransaction = tdbb->getTransaction();
tdbb->setTransaction(transaction);
@ -581,14 +585,24 @@ void EXE_execute_ddl_triggers(thread_db* tdbb, jrd_tra* transaction, bool preTri
{
EXE_execute_triggers(tdbb, &triggersPtr, NULL, NULL, TRIGGER_DDL,
preTriggers ? StmtNode::PRE_TRIG : StmtNode::POST_TRIG);
tdbb->setTransaction(oldTransaction);
}
catch (const Exception&)
catch (const Exception& ex)
{
tdbb->setTransaction(oldTransaction);
throw;
ex.stuffException(&tempStatus);
}
tdbb->setTransaction(oldTransaction);
// Triggers could be compiled inside EXE_execute_triggers(),
// so ensure the new pointers are copied back to the cache
fb_assert(triggers.getCount() == cachedTriggers.getCount());
for (unsigned i = 0; i < triggers.getCount(); i++)
{
*cachedTriggers[i] = triggers[i];
triggers[i].extTrigger = nullptr; // avoid deletion inside d'tor
}
tempStatus.check();
}
}
}