#1 Re: mORMot 1 » Can Mormot write a Pascal class in code based on a database table? » 2020-02-12 12:09:43

Thanks for the link.   OK, so DB to Pascal class is not the done thing.   Focus on the classes, you say.   Shame as my DB Schema really reflects my domain and work flow. 

I did already write a Pascal procedure to iterate each field in each database table and automatically generate the Pascal code for a class for each table.  And I thought that was pretty neat, when it worked and compiled too!!

So I might still use that procedure to create class templates from the database tables and then further work on the automatically generated code to make the classes mORMot compatible.

#2 mORMot 1 » Can Mormot write a Pascal class in code based on a database table? » 2020-02-12 11:10:33

Hi,

I am new to MORMOT and understand that extending the TSQLRecord class one can build a class in Pascal code which can then automate database table design and creation, JSON transport and much more.  This is very powerful. 

But I already have a Firebird 3 database schema with 34 tables which already defines my domain information structure very well. 

I need now to make Pascal classes which replicate this same database structure, and connect to and from the database, and then also allow JSON transport for a client - server multi-tier product. 

As I already have the database structure designed, is it possible in MORMOT to read this Firebird database schema and then automatically create the Pascal classes, presumably using TSQLRecord?  This seems to be the reverse of the automation of the database from the Pascal classes usually done in MORMOT. 

Please advise

Thanks

Martin

#3 Re: mORMot 1 » Learning mORMot, information overload » 2018-06-13 13:22:12

Thanks JD.  Encouraging to know I'm not the only one. As you can see form the interest in this post with over 180 views, lots of people have the same problem.   Will follow up on your advice and the link. 

Cheers,

Martin

#4 Re: mORMot 1 » Learning mORMot, information overload » 2018-06-13 09:25:18

Hi bLight,

I'm in the same situation as you and do find the overload to be a problem, and fully admit I'm not up to speed with fundamentals in the mORMot domain despite some effort to learn.  I can agree with you than mORMot has a steep learning curve, even though the reference manual is excellent and comprehensive.  It's just too big for the time I have to spend on coding.  It's not that I'm completely stupid (four degrees including PhD), it's that I have a day job for 60 h a week and a young family.   Taming the Mormot website was a bit of help but I haven't really got to the point that I'm on may way to becoming competent at basic mORMot.   I would therefore also like to know if there are any better introductory materials other than the (very good) samples to get up to a workable knowledge with less time and effort spent.  If this learning curve problem is not solved then mORMot will not flourish with new adopters. Is that what everyone wants?  TMS Aurelus, TPiOF etc are viable, if lesser alternatives.   

As an additional point, there is huge scope for someone to build a GUI designer for mORMot to allow graphical RAD style construction of an enterprise  level business solution for any company to adopt without the learning curve or the need even for Pascal developers.  Like what Wordpress is for templated website construction, but for an enterprise IT infrastructure instead.  This is just crying out to be done - to leverage the excellent technology in mORMot to non coding company business analysts, start up founders, and many more use cases.  It's a product which would be awesome, but without the need for technical expertise and high level coding skills.    Why hasn't this been done yet?

Cheers,

Martin

#5 Re: mORMot 1 » Converting Sample 28 REST ORM Server from Postgre to Firebird Server » 2018-02-06 07:58:51

OK fixed it -

In RestServer.pas on ln 63 as the sevrer sets up the TPerson table, changed

aRestServer.CreateMissingTables;

to

aRestServer.CreateMissingTables(0, [itoNoIndex4ID, itoNoIndex4TID]);

So no ID or TID primary field index is created at all. Actually Firebird always creates an index for the primary key field anyway, so mORMot odes not need to create a new one.   

Is this OK, or have i missed something? 

But what does the first parameter user_version = 0 mean?   Is this OK? 

Cheers,


Martin

#6 Re: mORMot 1 » Converting Sample 28 REST ORM Server from Postgre to Firebird Server » 2018-02-06 06:18:54

Hi Esteban,

The table was created from nothing by mORMot and this was fine on the first run, but then on a second run of the mORMot server in Sample 28, it has tried to overwrite its own primary key field and index in its own database file.  Surely it should automatically check which fields, including the primary key indexed fields are already present and not try to recreate them?  Also having no data in the table should not be a problem either and I should not have to write a datum with an external database GUI to get mORMot working.  Will look at it again tomorrow and see how VirtualTableExternalMap set options can be relevant, and also trace through the mORMot code to where it checks for pre-existing fields and indexes.
   
Cheers,

Martin

#7 Re: mORMot 1 » Converting Sample 28 REST ORM Server from Postgre to Firebird Server » 2018-02-05 11:51:23

Thx for the info camu72.   But I need to have an empty table remain functional as table creation is part of the ORM use case so would like to fix this.   How and where is this occurring.  Any ideas Arnaud?

#8 Re: mORMot 1 » Converting Sample 28 REST ORM Server from Postgre to Firebird Server » 2018-02-04 10:00:49

Hi Arnaud,

Thanks for clarifying that the SynDBFirebird.pas unit was non functional.   

The SynDBZeos.pas unit is working now. 

But my success was short lived.  On running the server again I get a Firebird SQL error "unsuccessful metadata update STORE RDB$INDEX_5 Error code: -607. can't format message 13:393 - message file ....SQL: CREATE UNIQUE DESC INDEX NDXPersonID on PersonID"

i.e. its trying to set up again the index for the Person table, and of course there can not be more than one index set up per table per field, the field ID in this case.

How to fix this?  I have isolated the problem to the call aRestServer.CreateMissingTables; which as you might imaging will try to do what it says.   But if the table is already there then why is it trying to recreate it, or try to make a replacement index for it?  In CreateMissingTables in MormotSQLLite3.pas at line 1032 one can set  Options: TSQLInitializeTableOptions which are declared in Mormot.pas at line 6807 as...

  TSQLInitializeTableOption = (
    itoNoAutoCreateGroups, itoNoAutoCreateUsers,
    itoNoCreateMissingField,
    itoNoIndex4ID, itoNoIndex4UniqueField,
    itoNoIndex4NestedRecord, itoNoIndex4RecordReference,
    itoNoIndex4TID, itoNoIndex4RecordVersion);

but none of these seem to be appropriate as we do need an index on ID or TID database fields in the first run when first creating the database.    btw FlameRobin the Firebird open source database admin tools shows the Person table has been created, there is no data yet, but there are two indices on the ID field, one ascending and one descending.   The DDL is

SET STATISTICS INDEX NDXPERSONID
SET STATISTICS INDEX RDB$PRIMARY1
 
Any ideas  how to fix this database index error? Sorry to keep asking for help - I am determined to get mORMot up and running, so bear with me, and my time available is not enough with all these problems. 

Cheers,

#9 Re: mORMot 1 » Converting Sample 28 REST ORM Server from Postgre to Firebird Server » 2018-02-04 04:48:16

OK everyone,

Some progress 

I gave up on SynDBFirebird.pas, and have used SynDBZeos.pas

- I downloaded the Zeos database objects v 7.2 and put its directories and subdirectories in the Delphi 10.1.2 IDE path. I have not installed them in the Delphi IDE (Note that Zeos v 7.2 is 10 x faster than 7.1, says Arnaud in the docs)
- I put SynDBZeos in the users clause
- I changed aProps:   TSQLDBFirebirdConnectionProperties to TSQLDBZEOSConnectionProperties
- I declared ADBCon: TSQLDBConnection;
- I replaced my old fbclient.dll for Firebird 2.1 with the fbclient.dll for Firebird 3.01 (I know mORMot is designed and tested with Firebird 2.5 but v 3 still worked)
- I used the following to create and define the database connection 

  aProps := TSQLDBZeosConnectionProperties.Create(TSQLDBZEOSConnectionProperties.URI(dFirebird,ToUTF8(''),
  'fbclient.dll'),
  ToUTF8('C:\MG\MGSoftware\MORMOT\Source\mORMot-master\SQLite3\Samples\28 - Simple RESTful ORM Server\Data\TestFBDB.fdb'),
  ToUTF8('SYSDBA'), ToUTF8('masterkey'));

  ADBCon := aProps.NewConnection;

It worked in Sample 28.  It found the fbclient.dll library, it was compatible, and it then recognized my database file was not there, and created it, albeit spitting error messages all the way.   But it worked. 

Its taken me about 12 hours of work to get this far!!  Let's hope the mORMot learning curve isn't quite so steep from here on in...

Wonder if I can get it to work in Lazarus too?

Arnaud, is it that SynDBFirebird.pas is not yet functional? can it be used at all? 

Cheers,

Martin

#10 Re: mORMot 1 » Converting Sample 28 REST ORM Server from Postgre to Firebird Server » 2018-02-04 01:39:10

Good to hear Esteban.  I know that mORMot will be the best framework for my software as a service - just a question of the learning curve and getting it to work.   

Please tell me more, point me to relevant links.   So do you also need to use SynDBFirebird.pas as well as SynDBZeos.pas, or just one or the other?  Do you need to download anything from Zeos or is everything you need in the SynDBZeos.pas unit?    If using Zeos and if you do need to download Zeos files then do they need to be installed as components into the IDE for Delphi and Lazarus or are the Zeos directories just put in the IDE/project paths and the relevant pas put in the uses clause, as done with mORMot?  Zeos has an option of plain or not plan.  Which to use?   

Many thanks for your help. 

Martin

#11 mORMot 1 » Converting Sample 28 REST ORM Server from Postgre to Firebird Server » 2018-02-03 14:32:08

msgendodoc@gmail.com
Replies: 12

Hi,

Converting Sample 28 - REST ORM Server from Postgre to use the Firebird 2.1 Server with FBClient.dll 32 bit.  I am used to Firebird and want to use it.   

Using Delphi 10.1.2 with output exe a Win32 bit file, so bitness should match.  The Firebird server is running. 

OK, so I've worked out that the Postgre database type and set up parameters are set in the aProps: TSQLDBConnectionProperties;

I have found SynDBFirebrid, put it in the uses clause, and changed aProps to a TSQLDBFirebirdConnectionProperties class instead.  Is this the right thing to do? 

I have the following code in the RestServer.pas at about line 32

 

  aProps := TSQLDBFirebirdConnectionProperties.Create(ToUTF8('Firebird'),
  ToUTF8('C:\MG\MGSoftware\MORMOT\Source\mORMot-master\SQLite3\Samples\28 - Simple RESTful ORM Server\Data\MGTestDB\TestFBDB.fdb'),
  ToUTF8('SYSDBA'), ToUTF8('masterkey'));
  

instead of

//  aProps := TODBCConnectionProperties.Create('','Driver=PostgreSQL Unicode'+
//      {$ifdef CPU64}'(x64)'+{$endif}';Database=postgres;'+
//      'Server=localhost;Port=5433;UID=postgres;Pwd=postgresPassword','','');

I have converted the string st UTF8 type

I have given the database file path and filename - but of course this file has not yet been created. 

The code compiles and runs and the expected error that it can't find the fbclient.dll comes up as per the SynDBFirebird.pas line 1018 code -as this is not the embedded Firebird version.  But then it should look for the fbclient.dll as per line 1020.  But it does not and raises the further error that invalid gds32.dll and cant find the client library.    The fbclient.dll is in the project source directory alongside the server exe, which is also in the 

As a work around test I have tried the embedded Firebird (i.e. all the local Firebird embedded files in the project source directory, but with the same errors, it doesnt work either)

Any guidance?  What next to try?  How to provide the Firebird library file fbclient.dll to the mORMot sever?   

Many thanks,

Martin

#12 Re: mORMot 1 » Re: mORMot Sample 26 compiles in Delphi 10.1 not on Lazarus 1.8 » 2018-02-03 12:18:15

Thx Arnaud,

Including the Synopse.inc declaration (and also adding that file's path to the project options include files path) fixed it, so now the project compiles. 

Or equally making an explicit pointer declaration for the InBody field

 FileFromString(Ctxt.Call^.InBody, AFileName);   //  changed from FileFromString(Ctxt.Call.InBody, AFileName); 

also worked. 

Many thanks Arnaud

Martin

#13 mORMot 1 » Re: mORMot Sample 26 compiles in Delphi 10.1 not on Lazarus 1.8 » 2018-02-03 07:18:44

Hi All

I'm a newbie trying to understand the mORMot framework.   Working with Sample 26 - the RESTful sever and client.   

In RestServerClass.pas on ln 69 I get an error

procedure TNoteServer.Blob(Ctxt: TSQLRestServerURIContext);
var AFileName: TFileName;
begin
  if (Ctxt.Table = TSQLNoteFile) and (Ctxt.TableID<>0) then
  begin
    AFileName := fBlobFolder+UTF8ToString(OneFieldValue(TSQLNoteFile,'FileName',Ctxt.TableID));
    case Ctxt.Method of
    mGET:
      Ctxt.ReturnFile(AFileName);
    mPOST,mPUT:
      begin
      FileFromString(Ctxt.Call.InBody, AFileName);          // ln 69: MG  Ctxt.Call.InBody is an ""Illegal qualifier" error in Lazarus - why?  Its OK in Delphi
      Ctxt.Success;
    end;
    mDELETE:
      if DeleteFile(AFileName) then
        Ctxt.Success else
        Ctxt.Error('',HTTP_NOTFOUND);
    end;
  end;
end;                     

// ln 69: MG  Ctxt.Call.InBody is an ""Illegal qualifier" error in Lazarus - why?  Its OK in Delphi
I think I understand that this code is retrieving a filename from the ORM data table and if the HTTP request is an mPOST or mPUT then trying to save the BLOB data to file. 
InBody is the REST request's content presumably.   Please advise if this is the case and also why the error.  This code works in Delphi 10.1.2

Many thanks

Martin

#14 Re: mORMot 1 » Absolute newbie needs the basis explaining » 2018-01-28 12:37:42

Hi

OK so need to add

VirtualTableExternalRegister(M,TSQLRecordClass(R),ADBCon,'Pt_Info');  // links model to external database 

and do this before the server is created.

Will read more of the documentation and examples.  Will persevere as the framework offers what I need but there is much to learn first. 

I am in Melbourne, Australia.  Wondering if any mORMot users are here and could form a local users group?   

Thx

#15 mORMot 1 » Absolute newbie needs the basis explaining » 2018-01-28 09:02:55

Hi All,

Just joined the forum and am determined to get going with MORMOT, but the learning curve is daunting despite looking at the docs and taming the mormot.

Using both Lazarus 1.8 and Delphi 10.2.1 but working to get off Delphi at the crazy cost it is

Need to set up a class, a model and a server saving to a firebird database i.e an ORM.  Having trouble even with looking at the sample projects getting this coded. 

Can someone give links to / code for simple basic implementation of this   

My class is

  TSQLPatient = class(TSQLRecord)
  // NB:  All classes for the ORM have to be named beginning with TSQL  This was not clear at first

  private

  F_UR: Integer;
  F_Name: RawUTF8;
  F_DOB:  TTimeLog;
  F_Addr1: RawUTF8;

  published

  Property UR:    Integer  read F_UR    write F_UR;
  Property Name:  RawUTF8  read F_Name  write F_Name;
  Property DOB:   TTimeLog read F_DOB   write F_DOB;
  Property Addr1: RawUTF8  read F_Addr1 write F_Addr1;


  end;                                      

Need to then create a TSQLModel and TSQLRestServer

 TForm1.Button1Click(Sender: TObject); 
  var
  R: TSQLPatient;
  M: TSQLModel;
  Server:   TSQLRESTServerDB; 

  begin;   
  M := TSQLModel.create([TSQLPatient]); // The [] are an array of tables, in this case with just one table
  If M.AddTable(TSQLRecordClass(TSQLPatient)) = false then  beep;

  Server := TSQLRESTServerDB.Create(M);
  ADBCon := TSQLDBConnectionProperties.Create('','c:\mg\mgsoftware\Mormot\Dbase\Test.fdb','SYSDBA','masterkey');
  Server.createmissingtables;

  R := TSQLPatient.Create;
  R.Name := 'UR';
  R.UR := 1;
  R.DOB := TimeLogFromDateTime(Now);
  R.Addr1 := '123 Any Street';

  // So how to add a record to the model, to the server and then to the database?  

  FreeAndNil(M);
  FreeAndNil(R);
  FreeAndNil(Server);   

  end;  

Any help appreciated.   I'll get there..

Martin

Board footer

Powered by FluxBB