I have implemented logic for an audit trail using MS SQL (SQL Server 2012). I use triggers to implement it.
Unfortunately, this seems to cause me a lot of grief.
I first noticed that using an “after insert” trigger caused havock. I suppose it was due to the fact that the DHTMLX logic uses scope_identity() to know what was last inserted. (In my case, the last inserted record after the “after insert” trigger was the record inserted in the audit trail table.)
So I moved the logic to an “instead of” (no before trigger with MS SQL) insert trigger but that seems also to create problems (first AddRow works, second errors), for a reason I can’t fathom. As far as I know the instead trigger works: inserts first into the audit trail table then into the standard table (called entries below).
This is what I see in the PHP log (shortened for readability) :
[code]===================================
Log started, 30/06/2014 12:47:51
DataProcessor object initialized
1404103671399_gr_id => 1404103671399
1404103671399_c9 => 424
1404103671399_c10 => 424
1404103671399_!nativeeditor_status => inserted
ids => 1404103671399
Row data [1404103671399]
entriesId => 1404103671399
eventNbr => 424
deleteEventNbr => 424
!nativeeditor_status => inserted
INSERT INTO entries(…) VALUES (…‘424’,‘424’'…);SELECT SCOPE_IDENTITY() as dhx_id
Edit operation finished
0 => action:inserted; sid:1404103671399; tid:;
Done in 0.014346122741699s
====================================
Log started, 30/06/2014 12:47:52
DataProcessor object initialized
1404103672079_gr_id => 1404103672079
1404103672079_c9 => 425
1404103672079_c10 => 425
1404103672079_!nativeeditor_status =>
ids => 1404103672079
Row data [1404103672079]
eventNbr => 425
deleteEventNbr => 425
!nativeeditor_status =>
Access control: operation blocked
Edit operation finished
0 => action:error; sid:1404103672079; tid:1404103672079;
Done in 0.002769947052002s
[/code]
Note the empty tid on the first insert and the “operation blocked” on the second insert…
When I delete the “instead of insert” trigger I get this (which works well) :
====================================
Log started, 30/06/2014 12:57:44
====================================
DataProcessor object initialized
1404104264419_gr_id => 1404104264419
1404104264419_c9 => 426
1404104264419_c10 => 426
1404104264419_!nativeeditor_status => inserted
ids => 1404104264419
Row data [1404104264419]
entriesId => 1404104264419
eventNbr => 426
deleteEventNbr => 426
!nativeeditor_status => inserted
INSERT INTO entries(...) VALUES (...'426','426'...);SELECT SCOPE_IDENTITY() as dhx_id
Edit operation finished
0 => action:inserted; sid:1404104264419; tid:65;
Done in 0.0083949565887451s
====================================
Log started, 30/06/2014 12:57:45
====================================
DataProcessor object initialized
1404104265122_gr_id => 1404104265122
1404104265122_c9 => 427
1404104265122_c10 => 427
1404104265122_!nativeeditor_status => inserted
ids => 1404104265122
Row data [1404104265122]
entriesId => 1404104265122
eventNbr => 427
deleteEventNbr => 427
!nativeeditor_status => inserted
INSERT INTO entries(...) VALUES (...'427','427'...);SELECT SCOPE_IDENTITY() as dhx_id
Edit operation finished
0 => action:inserted; sid:1404104265122; tid:66;
Done in 0.0068371295928955s
What to do?