ZQuery in transaction

The official tester's forum for ZeosLib 7.1. Ask for help, post proposals or solutions.
Post Reply
k1attila1
Junior Boarder
Junior Boarder
Posts: 29
Joined: 24.05.2013, 06:38

ZQuery in transaction

Post 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
k1attila1
Junior Boarder
Junior Boarder
Posts: 29
Joined: 24.05.2013, 06:38

Re: ZQuery in transaction

Post by k1attila1 »

Sorry I use FireBird SQL 2.5
miab3
Zeos Test Team
Zeos Test Team
Posts: 1310
Joined: 11.05.2012, 12:32
Location: Poland

Re: ZQuery in transaction

Post by miab3 »

@k1attila1

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

Michal
k1attila1
Junior Boarder
Junior Boarder
Posts: 29
Joined: 24.05.2013, 06:38

Re: ZQuery in transaction

Post 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
marsupilami
Platinum Boarder
Platinum Boarder
Posts: 1956
Joined: 17.01.2011, 14:17

Re: ZQuery in transaction

Post 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
k1attila1
Junior Boarder
Junior Boarder
Posts: 29
Joined: 24.05.2013, 06:38

Re: ZQuery in transaction

Post 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
Post Reply