ZQuery in transaction

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

ZQuery in transaction

Postby k1attila1 » 22.02.2017, 09:24

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

Postby k1attila1 » 22.02.2017, 09:28

Sorry I use FireBird SQL 2.5

miab3
Zeos Test Team
Zeos Test Team
Posts: 916
Joined: 11.05.2012, 12:32
Location: Poland

Re: ZQuery in transaction

Postby miab3 » 22.02.2017, 10:26

@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

Postby k1attila1 » 22.02.2017, 10:36

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
Gold Boarder
Gold Boarder
Posts: 589
Joined: 17.01.2011, 14:17

Re: ZQuery in transaction

Postby marsupilami » 22.02.2017, 13:58

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

Postby k1attila1 » 22.02.2017, 17:16

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


Return to “ZeosLib 7.1 stable Forum”

Who is online

Users browsing this forum: No registered users and 1 guest