Invalid operation in AutocommitMode

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

Moderators: gto, cipto_kh, EgonHugeist

Post Reply
markbass72
Fresh Boarder
Fresh Boarder
Posts: 13
Joined: 06.04.2008, 10:16
Location: Macerata

Invalid operation in AutocommitMode

Post 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
User avatar
mdaems
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium
Contact:

Post 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
Image
patyi
Fresh Boarder
Fresh Boarder
Posts: 24
Joined: 12.11.2005, 21:57

Post by patyi »

Suggestion :

if not ZSQLProcessor1.Autocommit then
cnConn.Commit;

regards Patyi.
User avatar
mdaems
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium
Contact:

Post by mdaems »

ZSQLProcessor1.Autocommit
Where does this property/method come from??? Autocommit is a connection property, as far as I know...

Mark
Image
markbass72
Fresh Boarder
Fresh Boarder
Posts: 13
Joined: 06.04.2008, 10:16
Location: Macerata

Post 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
markbass72
Fresh Boarder
Fresh Boarder
Posts: 13
Joined: 06.04.2008, 10:16
Location: Macerata

Post 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
User avatar
mdaems
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium
Contact:

Post 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
Image
markbass72
Fresh Boarder
Fresh Boarder
Posts: 13
Joined: 06.04.2008, 10:16
Location: Macerata

Post by markbass72 »

you are right
must be tested properties of Connection instead of Processor



markbass72
Post Reply