#1 2014-02-21 14:04:37

vlda
Member
Registered: 2014-02-11
Posts: 2

External database with remote access Firebird and FireDAC

Hi
I wonder where I find a step by step example to use external database with remote access Firebird 2.5 and FireDAC. I only found examples like this with SQLite below:

Example de Roberto Schneiders
Delphi XE5

uses
  ...RMotSQLite3, mORMot, mORMotHttpServer;
  type
  TSQLPessoa = class(TSQLRecord)
  private
    FIdade: Integer;
    FNome: RawUTF8;
  published
    property Idade: Integer read FIdade write FIdade;
    property Nome: RawUTF8 read FNome write FNome;
  end;
...
  private
    { Private declarations }
    ModeloDados: TSQLModel;
    ModeloServicos:TSQLModel;
    BaseDados: TSQLRestServerDB;
    ServidorHTTP: TSQLHttpServer;
    ServidorServicos: TSQLRestServer;
    procedure ConfigurarLog;
    procedure InicializarBancoDeDados;
    procedure InicializarServicos;
    procedure InicializarServidorHTTP;
  public
    { Public declarations }
  end;

var
  FrmServidor: TFrmServidor;

implementation

{$R *.dfm}

uses uPessoa,  SynCommons, SynZip, uCalculadoraImpl, uCalculadora;

procedure TFrmServidor.InicializarBancoDeDados;
begin
  // Configura Log
  TSQLLog.Family.Level := LOG_VERBOSE;

  // Cria o modelo da base de dados contendo a classe/tabela TSQLPessoa
  ModeloDados := TSQLModel.Create([TSQLPessoa]);

  //Inicializa a base de dados. Se o arquivo não existir, será criado.
  BaseDados := TSQLRestServerDB.Create(ModeloDados, 'BasededadosSQLite.db3');

  // Atualizará o esquema da base de dados de acordo com o modelo. Ex: Tabela nova/Campo novo
  BaseDados.CreateMissingTables(0);
end;

procedure TFrmServidor.InicializarServicos;
begin
  // Test TInterfacedObject
  ModeloServicos := TSQLModel.Create([],'services');
  ServidorServicos := TSQLRestServerFullMemory.Create(ModeloServicos);
  ServidorServicos.ServiceRegister(TCalculadora,[TypeInfo(ICalculadora)], sicShared);
end;

procedure TFrmServidor.InicializarServidorHTTP;
begin
  ServidorHTTP := TSQLHttpServer.Create('8080', [BaseDados, ServidorServicos]);
  Label1.Caption := 'Servidor rodando na porta 8080'
end;

Last edited by vlda (2014-02-21 14:18:14)

Offline

#2 2014-02-21 14:50:38

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: External database with remote access Firebird and FireDAC

Just declare the tables in ModeloDados model as external.

Take a look at the SAD 1.18 pdf, and external database support.

See also sample "15 - External DB performance" and the procedure TTestExternalDatabase.JETDatabase in SynSelfTests.pas.

Perhaps something like this (not test, just typing in the forum):

TSQLPessoa = class(TSQLRecord)
  private
    FIdade: Integer;
    FNome: RawUTF8;
  published
    property Idade: Integer read FIdade write FIdade;
    property Nome: RawUTF8 index 40 read FNome write FNome; // added "index 40" to define a VARCHAR(40) kind of column and not a text BLOB
  end;

TADPhysIBDriverLink.Create(Application).VendorLib := 'Firebird'+suffix+'\fbembed.dll'; // if needed
Props := TSQLDBFireDACConnectionProperties.Create(FIREDAC_PROVIDER[dFirebird]+'?CreateDatabase=Yes','','',''); // more or less
VirtualTableExternalRegister(ModeloDados,TSQLPessoa,Props);

The remaining of the code does not need to be changed.

Offline

#3 2014-02-21 15:04:29

vlda
Member
Registered: 2014-02-11
Posts: 2

Re: External database with remote access Firebird and FireDAC

Congratulations for the reply so quickly. I did not expect.
I'll study the code. I am returning many years without programming any help is welcome. Thank you.

Offline

#4 2014-02-21 15:53:14

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: External database with remote access Firebird and FireDAC

You are welcome.

Happy you are feel interested by our little mORMot.
smile

Offline

Board footer

Powered by FluxBB