You are not logged in.
Hi,
I'm testing the mORMot, and am finding fantastic! A great job!
To be blunt, I wonder if I use the units in a crossplatform client project written in FPC,
it is possible to consume objects (TSQLRecord) and a mORMot server services?
I did the following test:
ORM Classes:
TUnidade = class(TSQLRecord)
private
FDescricao: RawUTF8;
FSigla: RawUTF8;
FDecimais: Integer;
published
property Descricao: RawUTF8 read FDescricao write FDescricao;
property Sigla: RawUTF8 read FSigla write FSigla;
property Decimais: Integer read FDecimais write FDecimais;
end;
TProduto = class(TSQLRecord)
strict private
FCodigo: RawUTF8;
FDescricao: RawUTF8;
FUnidade: TUnidade;
published
property Codigo: RawUTF8 read FCodigo write FCodigo;
property Descricao: RawUTF8 read FDescricao write FDescricao;
property Unidade: TUnidade read FUnidade write FUnidade;
end;
In mORMot server:
TForm1 = class(TForm)
public
Props: TSQLDBFireDACConnectionProperties;
Model: TSQLModel;
DBServer: TSQLRestServerDB;
HttpServer: TSQLHttpServer;
end;
procedure TForm1.ConfigurarAppServer;
begin
Props := TSQLDBFireDACConnectionProperties.Create(FIREDAC_PROVIDER[dMySQL]+
'?Server=127.0.0.1;Port=3306', 'mormot', 'root', 'ROOT');
TProduto.AddFilterOrValidate(TProdutoFieldName.Codigo, TProdutoCodigoValidate.Create);
Model := TSQLModel.Create([TProduto, TUnidade], 'mormot');
VirtualTableExternalRegisterAll(Model, Props);
DBServer := TSQLRestServerDB.Create(Model, ':memory:', False);
DBServer.CreateMissingTables;
HttpServer := TSQLHttpServer.Create('8080', [DBServer], '+', useHttpApiRegisteringURI);
HttpServer.AccessControlAllowOrigin := '*';
end;
In FPC client:
TForm1 = class(TForm)
public
Model: TSQLModel;
ClientHTTP: TSQLRestClientHTTP;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Model := TSQLModel.Create([TProduto, TUnidade], 'mormot/');
ClientHTTP := TSQLRestClientHTTP.Create('127.0.0.1', 8080, Model);
if (ClientHTTP.Connect) then
Label1.Caption := 'Client Connected - Port 8080';
end;
At first a simple test... But the operations of the ORM could not make it work...
See the call, Did not return anything in Prod... And the record exists in the database.
I also wrote a client in Delphi, and this usually worked, Performing the operations of the correct ORM...
procedure TForm1.Button1Click(Sender: TObject);
var
Prod: TProduto;
begin
Prod := TProduto.Create(ClientHTTP, 3, False);
ShowMessage(Prod.Descricao);
end;
Could you help me to write an client in FPC? If possible...
Offline
Compile RegressionTests.dpr with Delphi.
Then put the RegressionTests.exe in one folder.
And run RegressionTests.exe without quitting it (do not press Enter).
Compile RegressionTests.dpr with FPC.
Then run the generated exe.
Does it work for you?
Offline
I did what you showed, and all tests were successful ..
So reading the sources I saw: heheheh
/ / For testing FPC, RegressionTests.exe run locally compiled with Delphi on Windows
There is one thing I could not do, call the JSONToObject, Written as follows:
var
People, People1, People2: TSQLRecordPeople;
Json: String;
People1 := TSQLRecordPeople.CreateAndFillPrepare(ClientHTTP,
'', 'ID=?', [ID]);
Json := People1.FillTable.JSON;
People2 := TSQLRecordPeople.Create;
JSONToObject(People2, Json);
ShowMessage(People2.FirstName +' '+ People2.LastName);
Above People2 is empty, But doing as is the example LCLMain.pas works:
var
People, People1, People2: TSQLRecordPeople;
Json: String;
Table: TJSONTableObject;
People1 := TSQLRecordPeople.CreateAndFillPrepare(ClientHTTP,
'', 'ID=?', [ID]);
Json := People1.FillTable.JSON;
People2 := TSQLRecordPeople.Create;
Table := TJSONTableObject.Create(Json);
Table.StepObject(People2);
ShowMessage(People2.FirstName +' - '+ People2.LastName);
What is the correct way? I can not use direct JSONToObject?
Thanks for your attention!
Offline
No, JSONToObject() works with a JSON object, whereas the ORM server with CreateAndFillPrepare() returns a JSON array with one JSON object.
Take a look at the JSON content returned.
Just use TSQLRecord.Create(ClientHTTP,ID) to retrieve the content of one record by ID.
Offline
Compile RegressionTests.dpr with Delphi.
Then put the RegressionTests.exe in one folder.
And run RegressionTests.exe without quitting it (do not press Enter).Compile RegressionTests.dpr with FPC.
Then run the generated exe.
Does it work for you?
Why is Delphi involved ? Server or client not compatible with FPC ? What if one wants to test Kylix instead of FPC ? Could you elaborate ?
Offline
Server is only working with Delphi yet.
The cross-platform units are only for writing clients, not servers.
So you run RegressionTests.exe to have the Delphi server part.
Then the RegressionTests.exe compiled with FPC will test the client part.
Offline
Many thanks for your efforts and comments !
Offline