Diese Seite mit anderen teilen ...

Informationen zum Thema:
Forum:
WinDev Forum
Beiträge im Thema:
4
Erster Beitrag:
vor 2 Jahren, 4 Monaten
Letzter Beitrag:
vor 2 Jahren, 4 Monaten
Beteiligte Autoren:
Steven Sitas, Peter H., Paulo Oliveira

WinDEV15 - Is this safe (Multiple Triggers)

Startbeitrag von Steven Sitasam 02.02.2011 12:37

Hello,

at the beginning of my app I describe a Trigger FOR ALL MY TABLES, like:

// 'Before' Trigger
HDescribeTrigger("*", "HAdd,HModify,HDelete", Trigger_DateUser, hTriggerBefore)
// 'After' trigger
HDescribeTrigger("*", "HAdd,HModify,HDelete", Trigger_DateUser, hTriggerAfter)


Everything works just fine.

Now I add another Trigger for just ONE TABLE, like.
HDescribeTrigger(myTable, "HAdd,HModify,HDelete", Trigger_myTable, hTriggerBefore)

What I see (and I like) is that WinDEV now uses the second Trigger for "myTable" and the first trigger for all other files.


So is this safe to have 2 or more triggers for a table?

Steven Sitas







Antworten:
It works but....
It depends a lot on what/how you are doing the trigger procedures.

I don't know any way of controlling the order they fire(that can be a problem) and it's harder to garantee that you don't end up with nested triggers or recursive ones.

The link bellow is for SQLSERVER but some of the recomendations are valid for every db engine (as far as i know INSTEAD OF doesn't exist in HF).
http://searchsqlserver.techtarget.com/feature/Why-use-triggers-in-Microsoft-SQL-Server

von Paulo Oliveira - am 02.02.2011 14:09
Hi,

I recall having encountered something similar years ago. I believe only one trigger for a certain event (add/update/delete) is executed in HF, even if you define multiple ones for it. Thougt I found it somewhere in the notes in the help file. Don't know if it still goes for more recent versions of HF. This is really a bad limitation (which makes no sense actually). The best way to manage this is create a trigger for *ALL* files and manage the table specific stuff in it as well by testing h.filename.

Cheers,

P.

von Peter H. - am 07.02.2011 22:54
Hi,
you are right.
Only the last defined trigger for a table fires up.

I was hopping to use "after" triggers WITH transactions.
Unfortunatelly with the "after triggers" there is NO "automatic" way to return an error.

I "worked around" this using a GLOBAL variable.

Steven Sitas





von Steven Sitas - am 08.02.2011 11:38
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.