#1 2020-09-22 05:34:07

annlinux
Member
Registered: 2020-09-22
Posts: 1

TSQLRecord always uses SQLite or memory and not external database

procedure TForm2.LoadItem;
var I:Integer;ItemList:TSQLItems;
begin
  ItemList := TSQLItems.CreateAndFillPrepare(rest,'');
  while ItemList.FillOne do
    begin
      Logs.Lines.Add(IntToStr(ItemList.ID)+':'+
                     ItemList.Part_No+':'+ItemList.Part_Name);
    end;
  ItemList.free;
end;

   try
      Uri    := TSQLDBZEOSConnectionProperties.Uri(dFirebird,'127.0.0.1:3050','',false);
      dbp    := TSQLDBZEOSConnectionProperties.Create(uri,'C:\ERP\ERP.FDB','SYSDBA','masterkey');
      Items  := TSQLItems.Create;
      Cards  := TSQLITEMS_CARD.Create;
      Model  := TSQLModel.Create([TSQLITEMS,TSQLITEMS_CARD],'root');
      VirtualTableExternalRegister(Model,[TSQLItems,TSQLITEMS_CARD],dbp);
      Logs.Lines.Add('Create Model / DB ok');
   except
   end;
   try
      Rest := TSQLRestServerDB.CreateWithOwnModel([TSQLITEMS,TSQLITEMS_CARD],':memory:');
      Logs.Lines.Add('Create REST/back-end..ok');
   except
   end;
   try
      HttpServer  := TSQLHttpServer.Create('8080',[Rest]);
      Logs.Lines.Add('Start HTTP Server..ok');
   except
   end;

   HttpServer.AccessControlAllowOrigin := '*'; //allow redirect from any URL proxy
   try
     rest.CreateMissingTables;
     Logs.Lines.Add('Registered ORM with DB');
   except
   end;
   LoadItem;

Offline

#2 2020-09-22 07:40:47

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

Re: TSQLRecord always uses SQLite or memory and not external database

1. Welcome.

2. Please follow the forum rules and don't post extensive code in the forum thread.
So post a reproducible example e.g. on gist.

3. And don't forget to state what is the problem you face.

Anyway, your code is incorrect because you don't use the Model in the Rest server, but call CreateWithOwnModel.
It is easy to find out the problem if you compare with existing sample and documentation.

Offline

Board footer

Powered by FluxBB