ZeosDBO 6.6.2 postgresql StartTransaction

Forum related to version 6.5.1 (alpha) and 6.6.x (beta) of ZeosLib's DBOs

Moderators: gto, cipto_kh, EgonHugeist

Post Reply
bakter
Fresh Boarder
Fresh Boarder
Posts: 3
Joined: 14.10.2005, 13:42

ZeosDBO 6.6.2 postgresql StartTransaction

Post by bakter »

I get a SInvalidOpInNonAutoCommit exception when i call the StartTransaction method.

I found the following method in ZConnection.pas:

procedure TZConnection.CheckAutoCommitMode;
begin
if not FAutoCommit and (FExplicitTransactionCounter = 0) then
raise EZDatabaseError.Create(SInvalidOpInNonAutoCommit);
end;

When I write the condition to
"not FAutoCommit and (FExplicitTransactionCounter <> 0)"
then everything seems correct
You do not have the required permissions to view the files attached to this post.
User avatar
mdaems
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium
Contact:

Post by mdaems »

Bakter,

Please have a look at the other forum topics concerning StartTransaction.
In short : StartTransaction should only be used when in AutoCommit Mode. It's an 'escape from autocommit' feature. Otherwise transaction handling happens automatically. Just use rollback and commit where you need it.

Mark
Image
bakter
Fresh Boarder
Fresh Boarder
Posts: 3
Joined: 14.10.2005, 13:42

Post by bakter »

thanks for the information

it's quite strange behavour first hear:D

I used to set AutoCommit to False then call StartTranscation and open a try..except block, then set AutoCommit to True.
So I think, I would remove then 'AutoCommit changing lines', and everythink will be fine, it's right? :D

When should I use the AutoCommit = False mode?
User avatar
mdaems
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium
Contact:

Post by mdaems »

When you want transactions and don't want to use starttransaction, of course...
Set it to false and your life should be easy. Transaction opened and closed for you. Just do your dml and call commit afterwards. It's similar to the way it works in Oracle or Mysql. There you don't start the transactions explicitly either.
Mark
Image
jpgonzalez
Fresh Boarder
Fresh Boarder
Posts: 5
Joined: 31.03.2013, 21:07

Post by jpgonzalez »

I use ZConnection with de autocommit = true
I Have this code:

try
DmMain.ZConnection.StartTransaction;
................
DmOperacionesVehiculos.QryInsertarVehiculo.ExecSQL;
................
................
DmOperacionesVehiculos.QryGuardarOperacion.ExecSQL;
................
DmOperacionesVehiculos.QryGuardarBoleto.ExecSQL;
................
................
DmMain.ZConnection.Commit;
ShowMessage('La operacion de compra se ha guardado con exito');
except
DmMain.ZConnection.Rollback;
ShowMessage('No se pudo guardar la compra');
end;

When I have a problem in the second query (QryGuardarOperacion), Rollback don´t work correctly, because the first query (QryInsertarVehiculo) post the data in the BD, despite i use startTransaction.
This problem creates inconsistency in the database, because the vehicle is post, but not the other information.
I don´t know if this is a bug of the Zeos version.
When I use the autocommit = false, the data is not post in the BD despite I use the commit command.


After that, I tested putting autocommit = false, without the command StartTransaction
This was running the entire block of code perfectly, but the data is not stored in the database.
I could see the data in the program, but not in the database, as if making a post in memory.

I do not know what happens, but in both cases (autocommit = autocommit = true and false) bring me any problems.

Can you tell me what can I do?
The Zeos Version is = 7.0.0-dev

PD: sorry for my english...
Post Reply