Page 1 of 1

ZQuery in transaction

Posted: 22.02.2017, 09:24
by k1attila1
Hello

I have two table : table1 and table2

ZQuery1 = table1
ZQuery2 = table2

After post a new record in ZQuery1 (table1) i'd like to modify something in ZQuery2 (table2) in ZQuery1.afterpost event.
Is it possible to do it in one transaction ?
And rollback the changes in ZQuery1 and ZQuery2 if something wrong happen in ZQuery2 ?

ZQuery1.table1afterpost(.........)
begin
ZQuery2.Edit;
ZQuery2FiledX.value:='xxx';
ZQuery2.Post; //if happen something wrong here what can i do to rollback all changes in ZQuery1 ?

end;

thank you in advance
Attila

Re: ZQuery in transaction

Posted: 22.02.2017, 09:28
by k1attila1
Sorry I use FireBird SQL 2.5

Re: ZQuery in transaction

Posted: 22.02.2017, 10:26
by miab3
@k1attila1

ZConnection1.StartTransaction;
...
...
ZConnection1.Commit;
or
ZConnection1.Rollback;

Michal

Re: ZQuery in transaction

Posted: 22.02.2017, 10:36
by k1attila1
Thank you miab3

But i edit table1 in dbgrid.

After post a record in the grid , i would like to made some changes in table2, in table1.afterpost eventhandler.

If there is something wrong happen in table1.afterpost i would like to rollback all changes in table2 and table1.

thank you
Attila

Re: ZQuery in transaction

Posted: 22.02.2017, 13:58
by marsupilami
You might want to check wether it makes sense to start a transaction in the before post event and commit or roll back it in the after post event. Unfortunately if you have to roll it back you would have to close and open your query, I think. Something alon these lines...

With best regards,

Jan

Re: ZQuery in transaction

Posted: 22.02.2017, 17:16
by k1attila1
Hello Jan
Thank you

Maybe i found a solution :

ZConnection.Autocommit:=false;

and i use

manual commit and rollback :

ZConnection.Commit or ZConnection.Rollback


Thnak you Attila