#1 mORMot 1 » Can one use mormot with legacy Firebird tables? » 2014-10-30 15:22:47

fabvit
Replies: 14

Having read the SAD manual and several posts about the mormot framework I cannot understand if I can use legacy tables with mormot.

For example if I have a firebird table where its primary key is composed by several fields instead of the surrogate ID key field, how do I tell mormot to cope with this multi-field primary key? May be there is a way, in mormot, to configure a multi-field primary.

I've tried using firebird external tables in mormot. As far as I've investigated I've seen that every class property declared  as string, will be translated in to a BLOB field in the corresponding Firebird extenal table: this surprises me a lot (I'm not a big fan of BLOB fields). Is there in mormot something to configure a string property of a class to be represented as VARCHAR or as CHAR in Firebird?

thank you so much

fabio vitale

#3 Re: mORMot 1 » CreateMissingTables does not create tables in external FirebirdDB » 2014-10-28 16:56:27

Hi Arnaud: finally I've founded the problem!!!!

In unit SampleData.pas is defined the TSQLSampleRecord class.

This class had a property defined as follow:

property Time: TModTime read fTime write fTime;


Guess what? "Time" is a reserved word in Firebird, hence when CreateMissingTables() is called there is an error creating a table with a column that has a reserved word name!

I changed the above line as follow and voila the problem disappeared.

property ModTime: TModTime read fModTime write fModTime;

May be it would be useful to change the SampleData.pas in the public mormot repository to avoid other user the same problem when they try to use external tables *AND* Firebird.

thank you!

fabio

#4 Re: mORMot 1 » CreateMissingTables does not create tables in external FirebirdDB » 2014-10-28 15:04:00

Ok thanks: I will try to follow your suggestion but I will first try to update from GitHub my local  mormot repository to a more recent version than the one I've installed on my pc.
As a side note, I'm using the last stable release of AnyDAC not FireDAC and this may be something that I've to further investigate.

I'll surely let you know my findings.

thank you!

fabio

#5 Re: mORMot 1 » CreateMissingTables does not create tables in external FirebirdDB » 2014-10-28 14:51:09

>Just ignore this exception,

but... no tables are created in the external firebird database after calling CreateMissingTables

Do you think the external tables will be created when I will add some data to them from the client?

#6 Re: mORMot 1 » CreateMissingTables does not create tables in external FirebirdDB » 2014-10-28 08:39:51

I've modified my code as for your suggestion.
Now the problem is that I get the following exception:

exception class   : ESQLite3Exception
exception message : TSQLSampleRecord: unable to create external missing field SampleRecord.Time - SQL="ALTER TABLE SampleRecord ADD Time BIGINT".

As far as I can see, the firebird database is created but it seems that there is an attempt to alter table SampleRecord  *before* having first created it.
In fact the firebird database is empty after I run the program.

Any ideas?

procedure TForm1.FormCreate(Sender: TObject);
var
  FirebirdServerIP: RawUTF8;
  FirebirdFDBFile: RawUTF8;
begin
  FirebirdServerIP := '127.0.0.1';
  FirebirdFDBFile  := 'C:\data\MORMOT_CLIENT_SERVER.FDB';

  DeleteFile(UTF8ToString(FirebirdFDBFile));

  // 0. Create an AnyDAC Physical DriverLink for Firebird (or drop a TADPhysIBDriverLink on the form)
  TADPhysIBDriverLink.Create(Application).VendorLib := 'fbclient.dll';

  // 1. Populate the AnyDAC/FireDAC Firebird ConnectionProperties
  fConnectionProps := TSQLDBFireDACConnectionProperties.Create('IB?CreateDatabase=Yes',
                                                               FirebirdServerIP + ':' + FirebirdFDBFile,
                                                               'SYSDBA','masterkey'
                                                              );

  // 2. Connecting has the side effect of creating the database file ( *if* 'IB?CreateDatabase=Yes')
  //
  // N.B. AFAIR initial fConnectionProps.ThreadSafeConnection.Connect is not needed:
  //      it will be made the first time the ORM would use the external DB.
  // fConnectionProps.ThreadSafeConnection.Connect;

  // 3. Create the Model
  Model := CreateSampleModel;

  // 4. Register all external tables (*BEFORE* calling TSQLRestClientDB/TSQLRestServerDB.Create!)
  // VirtualTableExternalRegister(Model, TSQLSampleRecord, fConnectionProps, 'SampleRecord');
  VirtualTableExternalRegisterAll(Model, fConnectionProps, false);

  // 5. Create missing tables
  DB := TSQLRestServerDB.Create(Model, SQLITE_MEMORY_DATABASE_NAME, true);
  DB.CreateMissingTables();

  Server := TSQLHttpServer.Create('8080',[DB],'+',useHttpApiRegisteringURI);
  Server.AccessControlAllowOrigin := '*'; // allow cross-site AJAX queries
end;

#7 mORMot 1 » CreateMissingTables does not create tables in external FirebirdDB » 2014-10-27 16:50:56

fabvit
Replies: 14

I've modified the sample Project04Server (HTTP) to use external tables.

My goal is to setup a mini project with a client and a server to explore remote ORM.

But as soon as I call CreateMissingTables, tables are created in the internal SQlite database instead of the external FirebirdDB.

What is wrong with my picture?

The following code is excerpted from the server:

procedure TForm1.FormCreate(Sender: TObject);
var
  FirebirdServerIP: RawUTF8;
  FirebirdFDBFile: RawUTF8;
begin
  FirebirdServerIP := '127.0.0.1';
  FirebirdFDBFile  := 'C:\Users\fabio.SFERACONSULTING\Desktop\Mormot Samples Fabio\04 - HTTP Client-Server\data\MORMOT_CLIENT_SERVER.FDB';

  DeleteFile(UTF8ToString(FirebirdFDBFile));

  // 0. Create an AnyDAC Physical DriverLink for Firebird (or drop a TADPhysIBDriverLink on the form)
  TADPhysIBDriverLink.Create(Application).VendorLib := 'fbclient.dll';

  // 1. Populate the AnyDAC/FireDAC Firebird ConnectionProperties
  fConnectionProps := TSQLDBFireDACConnectionProperties.Create('IB?CreateDatabase=Yes',
                                                               FirebirdServerIP + ':' + FirebirdFDBFile,
                                                               'SYSDBA','masterkey'
                                                              );

  // 2. Connecting has the side effect of creating the database file
  fConnectionProps.ThreadSafeConnection.Connect;

  // 3. Create the Model
  Model := CreateSampleModel;

  // 4. Register all external tables (*BEFORE* calling TSQLRestClientDB/TSQLRestServerDB.Create!)
  VirtualTableExternalRegister(Model, TSQLSampleRecord, fConnectionProps, 'SampleRecord');

  DB := TSQLRestServerDB.Create(Model, ChangeFileExt(paramstr(0), '.db3'), true);

  DB.CreateMissingTables(0);  <======= Tables are not created in external Firebird DB, but instead are created in  to the SQlite database

  Server := TSQLHttpServer.Create('8080',[DB],'+',useHttpApiRegisteringURI);
  Server.AccessControlAllowOrigin := '*'; // allow cross-site AJAX queries
end;

#8 Re: mORMot 1 » Newbie questions » 2014-10-27 12:26:59

Arnaud merci mille :-)

I'll investigate and study as for your suggestions.

thank you!
--
fabio vitale

#9 mORMot 1 » Newbie questions » 2014-10-27 09:44:27

fabvit
Replies: 2

First of all let me say that I'm really impressed by the mormot framework.
I'm a RemObject/DataAbstract user and I'm seriously thinking to switch over mormot.

After having read the 1.8 documentation and done some lab experiment I've some newbie questions that I cannot find answer for.

Q1. External database access using AnyDAC still create a SQLite table
Using Firebird with AnyDAC I was able to create a simple project (I do not know how to upload to Synopse forums).

Why does mormot anyway creates a SQlite db, as in the following code  (// 5. Create a REST Client)?
I mean: does the creation of at least one SQlite db is mandatory *even* if you only use External database access?

procedure TMainForm.SetupDataBase;
var
  FirebirdServerIP: RawUTF8;
  FirebirdFDBFile: RawUTF8;
begin
  FirebirdServerIP := '127.0.0.1';
  FirebirdFDBFile  := 'C:\1DP\prove\mORMot_Test_Fabio\Data\MORMOT.FDB';

  DeleteFile(UTF8ToString(FirebirdFDBFile));

  // 0. Create an AnyDAC Physical DriverLink for Firebird (or drop a TADPhysIBDriverLink on the form)
  TADPhysIBDriverLink.Create(Application).VendorLib := 'fbclient.dll';

  // 1. Populate the AnyDAC/FireDAC Firebird ConnectionProperties
  fConnectionProps := TSQLDBFireDACConnectionProperties.Create('IB?CreateDatabase=Yes',
                                                               FirebirdServerIP + ':' + FirebirdFDBFile,
                                                               'SYSDBA','masterkey'
                                                              );

  // 2. Connecting has the side effect of creating the database file
  fConnectionProps.ThreadSafeConnection.Connect;

  // 3. Create the Model
  fModel := CreateModel;

  // 4. Register all external tables (*BEFORE* calling TSQLRestClientDB.Create!)
  VirtualTableExternalRegister(fModel, TSQLBaby, fConnectionProps, 'Baby');
  VirtualTableExternalRegister(fModel, TSQLParent, fConnectionProps, 'Parent');

  // 5. Create a REST Client
  fClient := TSQLRestClientDB.Create(fModel, nil, string('SQliteDb.sqlite'), TSQLRestServerDB, false, '');

  // 6. Create all missing tables/fields
  fClient.Server.CreateMissingTables;
end;

Q2. How to use mormot with DBAware controls like TEdit, TDBGrid etc?

Q3. How to transform my little sample project from a monolithic client-server to two distinct executables: client.exe and server.exe.

Can someone please help me, telling where can I upload my sample project in order to show you the code?

Thank you very much in advance.

--

fabio vitale

Board footer

Powered by FluxBB