#1 mORMot 1 » TSQLRecord always uses SQLite or memory and not external database » 2020-09-22 05:34:07

annlinux
Replies: 1

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;

Board footer

Powered by FluxBB