#1 2014-09-18 08:31:16

willignicolas
Member
Registered: 2014-09-18
Posts: 1

Help on ORM Embbed server with firedac connection

Hi,

I test Mormot to use it on a existing project.

We need to use a ORM connected with Firedac (On Oracle, MSSQL, ACCESS, Postresql) on an standalone software.

So i have test many samples and read the documentation and code this for the test :


SampleData.pas

 TSQLSampleRecord = class(TSQLRecord)
  private
    fQuestion: String;
    fName: String;
    fTime: TDateTime;
    fColor : TColor;
  published
    property Timetest: TDateTime read fTime write fTime;
    property Name: String read fName write fName;
    property Question: String read fQuestion write fQuestion;
    property Color : TColor read fColor write fColor;
  end;

function CreateSampleModel: TSQLModel;

implementation

function CreateSampleModel: TSQLModel;
begin
  result := TSQLModel.Create([TSQLSampleRecord]);
end;

my FormMain :

procedure TForm1.FormCreate(Sender: TObject);
begin
  Model := CreateSampleModel; // from SampleData unit
  aProps := TSQLDBFireDACConnectionProperties.Create(FIREDAC_PROVIDER[dJet] , 'C:\Users\Dev\Desktop\mORMot-master\SQLite3\Samples\01 - In Memory ORM\test.mdb' , '' , '');
  VirtualTableExternalRegisterAll(Model,aProps);
  Database := TSQLRestServerDB.Create(Model, ':memory:' ,false);
  TSQLRestServerDB(Database).CreateMissingTables;
end;

procedure TForm1.AddButtonClick(Sender: TObject);
var Rec: TSQLSampleRecord;
begin
  Rec := TSQLSampleRecord.Create;
  try
    // we use explicit StringToUTF8() for conversion below
    // a real application should use TLanguageFile.StringToUTF8() in mORMoti18n
    Rec.Name := NameEdit.Text;
    Rec.Question := QuestionMemo.Text;
    Rec.Timetest := Now;
    Rec.Color := clgray;
    if Database.Add(Rec,true)=0 then
      ShowMessage('Error adding the data') else begin
      NameEdit.Text := '';
      QuestionMemo.Text := '';
      NameEdit.SetFocus;
    end;
  finally
    Rec.Free;
  end;
end;

The connection to the DB via Firedac is OK, the CreateMissingTables do is job on my Access base.

But the Database.Add() Create a Project1.db and save the SQLSampleRecord in this file with json format. (And only when i close the application)

I have take the "01 - In Memory ORM" Sample to start this test.

If i code this instead :

 Database := TSQLRestServerDB.Create(Model, 'C:\Users\Dev\Desktop\mORMot-master\SQLite3\Samples\01 - In Memory ORM\test.mdb' ,false);

I have this error : SQLLITE_NOTADB: File is encrypted or is not a database.

have somebody an idea?


Thank's for your help.

Offline

#2 2014-09-18 10:24:33

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

Re: Help on ORM Embbed server with firedac connection

Could you try with TOleDBJetConnectionProperties instead of TSQLDBFireDACConnectionProperties ?

Are you using the latest 1.18 unstable version from http://synopse.info/files/mORMotNightlyBuild.zip and http://synopse.info/files/sqlite3obj.7z ?

BTW:
1. TSQLRestServerDB expects the DB to be a SQLite3 DB, not a Jet DB so you need to use external tables.
2. Access/Jet is deprecated (not even available for Win64 application), and much slower than the internal SQlite3 engine - and it is known to have big issues when run in multi-thread mode (like in our server) - so never start a new project with Jet/MSAccess!
3. For external tables, you should specify a field/column length in TSQLRecord definition, using the "index" keyword.
4. Your code seems a bit difficult to follow - you should better start from "28 - Simple RESTful ORM Server" sample instead.

Offline

Board footer

Powered by FluxBB