Page 1 of 1

Invalid operation in AutocommitMode

Posted: 18.05.2008, 17:45
by markbass72
hi all

my instalation: laz 0.9.24 beta and zeos 6.6.2 (under MS Vista)

i'm using firebird db server (not embedded) and i've already looked in this site about this topic... however i think there's something strange

i know using firebird, working with AutocommitMode = TRUE is good; i know too that StartTransaction escape from this setting and allow to work in "OFF MODE" until a commit or rollback explicit invocation.

so i use this code:
procedure TForm1.ExecuteSqlScript;
var sApp: string;
begin
sApp := 'script.sql';

if Memo1.Lines.Count = 0 then
Memo1.Lines.LoadFromFile(sApp);

ZSQLProcessor1.Script.Assign(Memo1.Lines);

cnConn.StartTransaction;
Try
ZSQLProcessor1.Execute;
Except
on e: exception do begin
Memo2.Lines.Add('error: ' + e.Message);
Memo2.Lines.Add(' rollback forced');
cnConn.Rollback;
Memo2.Lines.Add(' rollback done');
end;
End;
cnConn.Commit;

end;

the code above is ok but i can't avoid to the end user a "Invalid operation inAutocommit mode" message

i come from delphi and i've recently started using lazarus with zeos... so is that a zeos bug or a my-source-bug?

thanks
markbass72

Posted: 19.05.2008, 12:11
by mdaems
Do you get this error after the rollback is forced or also when the Except block isn't executed?
After the rollback : this is a normal error as the rollback switches back to autocommit mode.
After good execution of the Try-block : this looks like a Zeoslib bug.

Mark

Posted: 19.05.2008, 15:53
by patyi
Suggestion :

if not ZSQLProcessor1.Autocommit then
cnConn.Commit;

regards Patyi.

Posted: 19.05.2008, 23:36
by mdaems
ZSQLProcessor1.Autocommit
Where does this property/method come from??? Autocommit is a connection property, as far as I know...

Mark

Posted: 20.05.2008, 11:11
by markbass72
reading carefully mdaems's and patyi's replies i think mistake is in my code
look at comments:

cnConn.StartTransaction;
Try
ZSQLProcessor1.Execute;
cnConn.Commit; // <- this is the correct place
Except
on e: exception do begin
Memo2.Lines.Add('error: ' + e.Message);
Memo2.Lines.Add(' rollback forced');
cnConn.Rollback;
Memo2.Lines.Add(' rollback done');
end;
End;
// <- in case of exception i think here, thanks to rollback,
// i'm already in "ON MODE"
//
// cnConn.Commit;

in can't run this code now but i'll test this as soon as possible (and i'll post the result ;)

thanks
markbass72

Posted: 20.05.2008, 14:13
by markbass72
tested
all ok: commit needed to be placed before the "except" keyword

however, as suggested by patyi, a read only property like "AutocommitState" can be useful (although, in this case, I would have to write a not very good code)

thanks to all

markbass72

Posted: 21.05.2008, 09:25
by mdaems
You would like this property on the ZSQLProcessor?
I think you could just read ZSQLProcessor1.Connection.AutoCommit and ZSQLProcessor1.Connection.InTransaction booleans.

Mark

Posted: 21.05.2008, 10:29
by markbass72
you are right
must be tested properties of Connection instead of Processor



markbass72