Page 1 of 1

transaction

Posted: Mon 15 Mar 2010 21:12
by calou
Hello,

In this example (autocommit is false)

Code: Select all

for i:=0 to 20 do
begin
  ibcquery.sql.text:='select * from MyTable where nom=:nom';
  ibcquery.fieldbyname('nom').asstring=inttostr(i);
  ibcquery.open;
  something...
end;
ibcquery.transaction.rollback;
if i have understood correctly the behavior of ibccquery, when i call .open a transaction is automatically starded. But are all the transactions in the for loop have the same number?
I ask this question because i am not sure that when i call the .rollback i close all the transactions that have been opened in the for loop or if i have to call the .rollback after the "something"

Thanks for explanations

Regards

Posted: Wed 17 Mar 2010 11:08
by bork
Hello,

In your example all loop iterations will be executed in the same transaction. And rollback in the end will cancel all you actions in the loop (because AutoCommit = false).

If you want to execute each loop iteration in a new transaction you should create an array of transactions and you should assign ibcquery.Transaction := TransactionArray in each iteration of the loop. Then after loop you can commit or rollback each transaction separately.

Posted: Wed 17 Mar 2010 15:43
by calou
Thank you very much for this very clear explanations

Regards