Firebird Embedded

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
isysoftware
Posts: 44
Joined: Wed 14 Nov 2012 17:33

Firebird Embedded

Post by isysoftware » Thu 10 Nov 2016 13:19

Hi All,
with this code, I use Firebird embedded for my application leaving server blank:
with ServerConn do
begin
if(Connected) then Disconnect;
ProviderName:=ConnIni.ReadString('fbconnection','ProviderName','');
// server:=ConnIni.ReadString('fbconnection','server','');
// port := ConnIni.ReadInteger('fbconnection','port',0);
password:='masterkey';
username:='SYSDBA';
Database:=ExtractFilePath(Application.ExeName)+'Data\'+ConnIni.ReadString('fbconnection','database','');
SpecificOptions.Values['ClientLibrary'] := 'fbclient.dll';
end;
ServerConn.Connect;
In this way, I use a local database.

I have problems with this code:

with aq do
begin
edit;
FieldByName('eurocoworking').AsFloat:=euroCow;
FieldByName('Numgiorni').AsFloat:=NumGiorni;
FieldByName('PerceCoworking').AsFloat:=perceCOw;
FieldByName('eurocoworking').AsFloat:=euroCow;
FieldByName('costozero').AsFloat:=COstozero;
FieldByName('percericarico').AsFloat:=perceRic;
FieldByName('imporicarico').AsFloat:=Imporicarico;
FieldByName('costoalcliente').AsFloat:=costoAlCLiente;
try
begin
Connection.StartTransaction;
post;
Connection.Commit;
end;
except on E: Exception do
begin
if(Connection.InTransaction) then
Connection.Rollback;
end;
end;
end;

On connection.starttransaction I have an exception: Can't perform operation on active transaction.

With Firebird embedded, I don't need transaction?

Can you help me?

Thanks, Flavio

FCS
Posts: 176
Joined: Sat 23 Feb 2013 18:46

Re: Firebird Embedded

Post by FCS » Thu 10 Nov 2016 13:46

Hi,

As I remember, when you connect to FireBird the transaction is started automatically. Read documentation and the posts on this forum.

Regards
Michal

isysoftware
Posts: 44
Joined: Wed 14 Nov 2012 17:33

Re: Firebird Embedded

Post by isysoftware » Thu 10 Nov 2016 14:03

This means that if I have an application and I would like to have the same code for MySQL e Firebird, I need to rewrite many parts of my code? It isn't possible only change the Provider?

FCS
Posts: 176
Joined: Sat 23 Feb 2013 18:46

Re: Firebird Embedded

Post by FCS » Thu 10 Nov 2016 15:06

Hi,

Probably you should make some exceptions in your code, but I'm not working with FireBird. The programmers from DevArt can give you more detailed answer.
Read the posts on this forum. This subject was described here many times.

Michal

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: Firebird Embedded

Post by ViktorV » Fri 11 Nov 2016 13:08

InterBase/Firebird requires an active transaction for any operation with data, even for opening dataset. Therefore, when calling TUniQuery.Open, it is verified if a transaction associated with it is running and, if it is not so - it is automatically run. In your example dataset uses a default transaction TUniConnection, therefore when attempting to call the Connection.StartTransaction method in your example, you get the "Can't perform operation on active transaction" error, because when opening dataset the transaction has already started.
To solve the issue you can use the following advice:
- use for dataset a separate transaction, not a default transaction TUniConnection;
- use for data modification UpdateTransaction.
You can get more information about working with transactions when connecting to Firebird on our forum:
viewtopic.php?f=28&t=25591
viewtopic.php?f=28&t=32310
viewtopic.php?f=24&t=25421

FredS
Posts: 272
Joined: Mon 10 Nov 2014 17:52

Re: Firebird Embedded

Post by FredS » Sun 13 Nov 2016 18:30

isysoftware wrote:This means that if I have an application and I would like to have the same code for MySQL e Firebird, I need to rewrite many parts of my code? It isn't possible only change the Provider?
Not so UNI now is it..

I solved this issue with a Class Helper, Commit and Rollback (not shown) all redirect to their respective Retaining calls for FB.
If you want strict transaction handling in FB then turn off AutoCommit:

Code: Select all

procedure TUniConnection.StartTransaction(const TurnAutoCommitOFF: boolean = false);
begin
  case dbProvider of
    dbFirebird: begin
        if TurnAutoCommitOFF then AutoCommit := false;
        if AutoCommit then Exit;
        if InTransaction then inherited CommitRetaining
        else inherited StartTransaction;
      end;
    else inherited StartTransaction;
  end;
end;

Post Reply