Using Firebird embedded

Hi,


I am trying to use firebird embedded.  I have copied dlls into system folder (Windows32) and everything is working nice. I can use TIBDatabase to connect to database and other IB components to connect to data.  Now, is there any possibility to use same approach with Aurelius?  Seems that I have to create connection, and for that I need dbexpress drivers for Firebird.  At least that is what I found out so far....

Thanks,
Simon

You can use either dbExpress or IBExpress with Aurelius (and many other database components). They those components are configured doesn't matter to Aurelius - if they can connect to database, Aurelius can. So if your TIBDatabase is working, it will work with Aurelius.

OK.  How I do it?  I am using TIBDatabase component on DataModule and I configure that component to access database.  How I can convert that into IDBConnection interface?  In your demos you are using TdbGoConnectionAdapter,  TDBXConnectionFactory and so on...

You can take a look at this topic in manual: http://www.tmssoftware.com.br/aurelius/doc/web/index.html?component_adapters.htm.

Just use this to retrieve the IDBConnection from TIDBDatabase component:

MyConnection := TIBExpressConnectionAdapter.Create(IBDatabase1, False);

OK.  This is what I did.  Downloaded embedded database file from firebird web site.  Copied that file into windows system folder (gds32.dll).  I have run Delphi created project and within that project one DataModule.  I have created empty firebird database using third party tool.  On created DataModule I have dropped TIBDatabase component and created connection to my newly created database.  I have connected to it successfully.  If I create any table, it is visible in my delphi project.  For example, I create table Person (using third party tool) and dropped TIBTable on DataModule and that table was able to see person table in the database.  So that works.  Now...I did what you have told me:


function TDataModule1.GetConnection: IDBConnection;
begin
  Result := TIBExpressConnectionAdapter.Create(IBDatabase1, True);
  if Result = nil then
    raise Exception.Create('Invalid connection settings. Cannot connect to database.');
  if not Result.IsConnected then
    Result.Connect;
end;

I call this function from my main form like this:

procedure TForm1.btnCreateScheemaClick(Sender: TObject);
var
  DatabaseManager: TDatabaseManager;
begin
  if MessageDlg('Confirm creating database schema?', mtWarning, [mbYes, mbNo], 0, mbYes) <> mrYes then
    Exit;

  DatabaseManager := TDatabaseManager.Create(Connection);
  try
    DatabaseManager.BuildDatabase;
    ShowMessage('Database schema created succesfully.');
  finally
    DatabaseManager.Free;
  end;
end;

where connection is function:

function TForm1.Connection: IDBConnection;
begin
  Result := DataModule1.Connection;
end;

I have included Aurelius.Drivers.IBExpress and Aurelius.Sql.Interbase in uses of DataModule.
All of this creates IDBConnection and seems to work without problems.  Well,  then I have included Entities.pas from your demo example:

unit Entities;

interface
uses
  Aurelius.Mapping.Attributes;

type
  [Entity]
  [Automapping]
  TPerson = class
  private
    FId: integer;
    FLastName: string;
    FFirstName: string;
    FEmail: string;
  public
    property Id: integer read FId;
    property LastName: string read FLastName write FLastName;
    property FirstName: string read FFirstName write FFirstName;
    property Email: string read FEmail write FEmail;
  end;

implementation

end.

And when I press create schema button, it says that schema is created.  Only problem is that database is still empty...table Person has not been created.
I have included Entities file in both uses (main form and DataModule).

Simon

The problem here is with the linker. You don't use those classes anywhere in your application, thus the linker removes them and Aurelius can't get any info about it. You should somehow use the TPerson class, something as simple as this would be enough:

TPerson.Create.Free;

That worked!!!


Thanks,
Simon