Page 1 of 1

ZeosDBO 6.6.2 postgresql StartTransaction

Posted: 17.12.2007, 14:32
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

Posted: 18.12.2007, 10:51
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

Posted: 19.12.2007, 11:06
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?

Posted: 19.12.2007, 12:01
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

Posted: 31.03.2013, 22:31
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...