CommitRetaining question
Posted: Fri 03 May 2013 09:41
Using: Delphi XE2 Enterprise, Firebird 2.51, UniDAC 5.01 Pro, Windows 8 64-bit, VCL Forms application
What exactly does TUniConnection.CommitRetaining do?
Is this code a good way of doing INSERT stored procedure?
Will there be any performance problems with this code?
Update:
Is there any better way of doing things? I am getting table key violation errors when running the same code second time.
So, I am illustrating this by including the additional information in the first code example:
What changes need to be made to my code or transaction style to fix this error?
What exactly does TUniConnection.CommitRetaining do?
Is this code a good way of doing INSERT stored procedure?
Code: Select all
if datamod.UniConnection1.InTransaction then
datamod.UniConnection1.CommitRetaining;
try
(* here execute a INSERT stored procedure *)
if datamod.UniConnection1.InTransaction then
datamod.UniConnection1.CommitRetaining;
except
on E: Exception do
begin
if datamod.UniConnection1.InTransaction then
datamod.UniConnection1.RollbackRetaining;
raise Exception.Create(E.Message);
end;
end;
Update:
Is there any better way of doing things? I am getting table key violation errors when running the same code second time.
The reason is that this Insert stored procedure is getting the value to be inserted from another SELECT stored procedure that is executed just before it is executed.---------------------------
Debugger Exception Notification
---------------------------
Project xxxx.exe raised exception class EUniError with message '
attempt to store duplicate value (visible to active transactions) in unique index "IXINVTYIDBATCHNO"
At procedure 'INVTY_BATCH_I' line: 10, col: 3'.
---------------------------
Break Continue Help
---------------------------
So, I am illustrating this by including the additional information in the first code example:
Code: Select all
if datamod.UniConnection1.InTransaction then
datamod.UniConnection1.CommitRetaining;
try
(* here execute a SELECT stored procedure
getting a value from a table, and store
it to variable.
*)
(* here execute a INSERT stored procedure
using the value from the SELECT stored
procedure above.
The insert is being made to a table with
unique field constraint.
Exception occurs here due to key violation
in the table being inserted to.
This means that the SELECT stored procedure
above is returning an old value from the table.
... SELECT MAX(RowId) FROM MyTable ....
*)
if datamod.UniConnection1.InTransaction then
datamod.UniConnection1.CommitRetaining;
except
on E: Exception do
begin
if datamod.UniConnection1.InTransaction then
datamod.UniConnection1.RollbackRetaining;
raise Exception.Create(E.Message);
end;
end;
What changes need to be made to my code or transaction style to fix this error?