Triggers, @@Identity and TADOQuery
From: Andrew Venmore (avenmoreatananzidotcodotza)
Date: 08/24/04
- Next message: Arnie Mauer: "Re: ADO DB2 Exception Error"
- Previous message: Jeremy Collins: "Re: Open method of ADO Stream Object"
- Next in thread: Andrew Venmore: "Re: Triggers, @@Identity and TADOQuery"
- Reply: Andrew Venmore: "Re: Triggers, @@Identity and TADOQuery"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 24 Aug 2004 13:10:23 +0200
Hi All
I am trying to set up simple auditing functionality for my users on
MSSQL using the brute-force, trigger way.
I create a trigger on MyTable which writes records into MyAuditTable.
I soon learn not to use/return @@Identity in my stored procs as it
contains the identity of the last record written (in MyAuditTable),
but rather to use scope_identity() or ident_current('MyTable').
I have now also discovered that using TADOQuery.Append/Post also
presents a problem. In the following scenario:
MyQuery.Append;
MyQuery.FieldByName('SomeField').AsString := 'Something';
MyQuery.Post;
MyQuery.FieldByName('MyTableID').AsInteger will now have the wrong
value (the ID of MyAuditTable).
Observing the throughput with SQL Profiler, I see that the data is
appended, then "SELECT @@IDENTITY" is called, which I presume is used
to update the ID field in the dataset.
Stepping into ADODB.pas, I find that the above commands are issued
from within MSADO15.DLL (RecordSet.Update()).
Does anyone know if there is any way to alter this behaviour, or if
there is any possible solution/workaround (besides not using
append/post).
Thanks for any input.
Andrew Venmore
[avenmoreatananzidotcodotza]
- Next message: Arnie Mauer: "Re: ADO DB2 Exception Error"
- Previous message: Jeremy Collins: "Re: Open method of ADO Stream Object"
- Next in thread: Andrew Venmore: "Re: Triggers, @@Identity and TADOQuery"
- Reply: Andrew Venmore: "Re: Triggers, @@Identity and TADOQuery"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|