#1 2018-07-02 05:01:46

dualarrow
Member
From: Australia
Registered: 2018-06-28
Posts: 21

Looking for guidance on implementing a new TSQLVirtualTable

Hi,

I've been spending the last few days looging over the documentation for mORMot and the source files. I have widened my reading to include the sqlite virtual table too.

Theres a lot of reading to start to get a minimal idea on how the inner workings of mORMot relates to virtual tables, but from what I have been able to determine so far is the following (please comment on whether or not I have understood correctly)

TSQLVirtualTable is an abstract class that performs some of the interface into the sqlite engine. You need to create a class that inherits off it and fill in a few methods (sounds simple but in reality I expect this to be the hardest part).

To use ORM, register your tables with Model.VirtualTableRegister(TSQLRecordYourRecord,TSQLVirtualTableYourTable);

All the work that mORMot requires to execute SQL will go to the virtual table implementation which will need to process the sqlite details and return an appropriate reposnse. This will be done from the looks of the sqlite documentation, on a table by table basis. ie the implementation of the TSQLVirtualTable does not need to be concerned with joins and even the SQL being used, it just needs to process the details on the table being processed at that instant. That table may or may not be part of a join.

If the above is "mostly" correct, then I think I have finally started to understand some of the internals of mORMot.

I now want to start looking at trying to implement a virtual table to work with Faircom's CTree server (From what I have understood, I won't even need the SQL version as sqlite will do that part).

If anyone has suggestions on order to tackle this or any other pointers I'd appreciate hearing them.

Hopefully someone will be able to conform that I have either understood this part or not.

TIA Andrew

Offline

#2 2018-07-02 20:35:08

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

Re: Looking for guidance on implementing a new TSQLVirtualTable

Virtual Tables are a SQLite3 feature, in fact.
See https://www.sqlite.org/vtab.html for more information about how it works.

From it, you could indeed add Faircom's CTree server to the SQlite3 engine, therefore to the ORM...
The most complete sample of Virtual Table is the one included in mORMotDB.pas, which link the main SQLite3 engine into external SynDB-related items.

Offline

#3 2018-07-03 06:04:18

dualarrow
Member
From: Australia
Registered: 2018-06-28
Posts: 21

Re: Looking for guidance on implementing a new TSQLVirtualTable

Hi ab, thanks for the info. I'm having trouble getting the virtual table to get prepared using the mORMot code.

Initialising the system I have used code like the following

  GModel := TSQLModel.Create([TSQLBaby], ROOT_NAME);
  GModel.VirtualTableRegister(TSQLBaby, TSQLVirtualTableCtree);


  GServer := TSQLRestServerDb.Create(GModel);
  GServer.ServiceDefine(TServiceCalculator, [ICalculator], sicShared);
  GServer.ServiceDefine(TServiceSuburb, [ISuburb], sicShared);
  GHTTPServer := TMyServer.Create(PORT_NAME, [GServer], '+', useHttpApiRegisteringURI);

  GHTTPServer.AccessControlAllowOrigin := '*';
  GHTTPServer.DomainHostRedirect('127.0.0.1:888','service/html');


  lBaby := TSQLBaby.Create(GServer,1);

I have stepped through the VirtualTableRegister and a number of the routines in the source that I suspected was on the leadup to the registration, but I cant seem to get the virtual table to get registered. With the example above, it raises an exception saying the table Baby doesnt exist, but as its not in a table (other than the virtual table) its not found.

Do you have a code fragment that could get me started please.

Offline

#4 2018-07-03 17:53:43

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

Re: Looking for guidance on implementing a new TSQLVirtualTable

You need to call GServer.CreateMissingTables to actually initialize the virtual table in the SQLite3 engine.

Offline

Board footer

Powered by FluxBB