#1 Re: mORMot 2 » Error running docker container from ex\martin-doyle\07-HttpDockerORM » 2023-10-29 22:24:59

JD

I have a mORMot 1 server in a Docker container built from Alpine Linux in production, and it runs without problems. However, my server's Docker build is based on the FreePascal example https://wiki.freepascal.org/Docker_Containerization

I later discovered and tried the mORMmot 2 based 07-HttpDockerORM example in a Docker container, and it worked for me. No AV issues at all.

However, I have to clarify that my development environment is Linux Mint and I adopted Docker because I did not want to create Windows & Mac versions of my mORMot server.

JD

#2 Re: mORMot 1 » mORMot1 - Lazarus compile error in SynCrossPlatformREST.CallGetResult » 2023-08-06 09:46:01

JD

Hi there everyone,

In the end, I decided to rewrite the server app, making sure to remove the dependency on mormot_cross, and I'm pleased to say it now works as expected.

Cheers,

JD

#3 mORMot 1 » mORMot1 - Lazarus compile error in SynCrossPlatformREST.CallGetResult » 2023-08-01 15:15:49

JD
Replies: 1

Hi there ab,

I have an application that is a GUI application on Linux and a service on Windows. They both work very well.

I want to make a service/daemon on Linux using the same simple service source code that already works on Windows. But when I compile the program, I get the error below:

SynCrossPlatformREST.pas(2918,15) Error: Incompatible types: got "Variant" expected "TID"

/// marshall {result:...,id:...} and {result:...} body answers
function CallGetResult(const aCall: TSQLRestURIParams; var outID: TID): variant;
{$ifndef ISSMS}
var doc: TJSONVariantData;
    jsonres: string;
{$endif}
begin
  ...
  outID := doc.Value['id'];  // <---- Error ocurs here !
  {$endif}
end;           

Someone else has reported the error, but it was erroneously posted in the mORMot2 section here. However no solution to the problem was posted.

My environment
Lazarus; 2.2.6 x86_64-linux-gtk2
FPC; 3.2.2
mORMot; 1.186435

What I find strange is this only occurs when I try to compile the program as a service on Linux. There are no problems at all with the other cases.

Thanks a lot for your assistance.

Cheers,

JD

#4 Re: mORMot 1 » Implementing OAuth2 » 2022-07-28 19:05:26

JD
Prometeus wrote:
squirrel wrote:

Does anybody still have copies of these gists available? I need a mormot server with oauth authentication and was hoping this would be something to build on.  But the gists seem to be all gone already.

email sent

Hi there Prometheus,

Could you please send me the copies by email too?

Thanks a lot

JD

#5 Re: mORMot 1 » Routing requests to multiple database » 2022-04-07 18:49:45

JD

I have a similar Use Case and I manage it using PostgresSQL and its schemas. Each schema houses a different database belonging to different companies.

The REST call contains the name of the schema and that way a different select/insert/delete can be accessed depending on the schema in the REST call.

For example, I use this REST call to find out if my mORMot server is up and running:

http://localhost:8088/service/myapi/sayhello?schema=company_xyz

This will call the SayHello resource in the Company_XYZ schema.

I hope this helps a little.

Cheers,

JD

#6 Re: mORMot 1 » check parameters rules before processing at the service based app » 2021-04-11 10:46:22

JD
macfly wrote:

Another option is to create a TSQLRestRoutingREST to be used by the service and override the ExecuteSOAByInterface method to handle the error.

Using this approach, I can send a custom error and messagem on an interface-based service.

However, since you want to validate the type of data, it would be best to use method-based services.

@macfly

Would you mind sharing some code showing how you did this? I think it might be a solution for one of my use cases because I also use an interface based service.

THanks,

JD

#7 Re: mORMot 1 » REST Design problem: a function with many parameters for GET requests » 2021-04-08 18:01:05

JD
ab wrote:

Because there is already a REST/ORM layer in mORMot.


OK. I get it now. I had to bypass the ORM because I have a lot of legacy code (triggers, functions and procedures) in my PostgreSQL database.

Ignoring that and going full ORM is a mammoth task that cannot be undertaken at the moment. I'll have to do it very slowly to not break something in the system.

JD

#8 Re: mORMot 1 » REST Design problem: a function with many parameters for GET requests » 2021-04-05 19:12:40

JD
ab wrote:

IF you reinvent the wheel, you would rather not use an interface based service, but a method-based service.

Anyway, I am a "purist" so for me, you should better follow DDD or KDD parterns, and define a proper application level, not expose directly your customer objects.
That is, start from the end-user use cases, not the data.

Thanks for your reply & your suggestions ab.

However I do not understand why you think I am reinventing the wheel.

Please clarify.

Thanks a lot,

JD

#9 mORMot 1 » REST Design problem: a function with many parameters for GET requests » 2021-04-04 09:55:18

JD
Replies: 7

Hello there everyone,

I would like to know your opinions/experiences with designing and using a REST endpoint in mORMot that handles many parameters.

Currently my proposed function signature is like this

function TRESTMethods.Customer(Params: UTF8): RawJSON;

In order to enable customer searches by firstname, lastname, age, sex, telephone, country, dateoffirstpurchase, dateoflastpurchase etc instead of using GET, I intend to use a POST to pass a JSON document with the parameters to the server for processing. However, I've seen some say online that one can use standard GET query but with optional parameters. How is this done?

This same function will handle customer creation (using POST), modification (using PUT), deletion (using DELETE) like this:

case Ctxt.Request.Method of
     mGET:
    { code for handling GET requests} 

     mPOST:
    { code for handling POST requests} 

     mPUT:
    { code for handling PUT requests} 

     mDELETE:
    { code for handling DELETE requests} 

end;

However, I've seen some purists say that a method like this is doing too much and that it is better to break it up into smaller bits. I agree that the Customer function will be very long if I continue like this especially with the INSERT and UPDATE SQL statements needed to create and update Customer data. This is where I would like your input. How should I break up the function? Is this what Microservices architecture tries to do?

Thanks for your kind assistance,

JD

#10 mORMot 1 » Returning standard REST API codes e.g 200, 201, 404 etc » 2021-04-04 09:13:30

JD
Replies: 1

Hello there everyone,

I need a little clarification concerning the way the mORMot framework returns the standard REST codes e.g 200, 202 , 204, 404 etc.

I want to look for these codes in the messages received from my mORMot server by the RESTful clients of my application (Java & Lazarus/FPC) and display appropriate messages to the users.

How do I implement this functionality in my mORMot server and where do I look for the codes in the messages sent by the server to my clients?


Thanks a lot for your kind assistance.

JD

#11 Re: mORMot 1 » [Solved] No variant method call dispatch error (occurs in Lazarus/FPC) » 2021-01-11 00:43:06

JD
Vitaly wrote:

I guess this code might be slightly better since it will get the pointer just one time:

  with _Safe(vJSON.id)^ do
    for intX := 1 to 10 do
      AddItem(intX);

or local variable can be also an option.
Anyway, these are just details, of course.

Yes that works also. Thanks a lot.

JD

#12 Re: mORMot 1 » [Solved] No variant method call dispatch error (occurs in Lazarus/FPC) » 2021-01-10 23:27:17

JD

Thanks a lot for your contributions. I found that this worked for me also:

procedure TForm1.Button3Click(Sender: TObject);
var
  vJSON: Variant;
  intX: integer;
begin
  vJSON := _Json('{"id":[]}');
  //
  for intX := 1 to 10 do
    _Safe(vJSON.id)^.AddItem(intX);
  ShowMessage(VariantToUTF8(vJSON));
end;

JD

#13 Re: mORMot 1 » [Solved] No variant method call dispatch error (occurs in Lazarus/FPC) » 2021-01-10 22:02:21

JD

That's very strange. I'm using Lazarus 2.1.0/FPC 3.2 (built with fpcupdeluxe) on Windows 10. It used to work perfectly but I only just noticed it failed 2 daya ago when I could no longer save new records to my database.

JD

#14 Re: mORMot 1 » [Solved] No variant method call dispatch error (occurs in Lazarus/FPC) » 2021-01-10 21:35:52

JD
Vitaly wrote:

I guess the error comes from

vJSON := _Json('{id:[]}');

Try

vJSON := _Json('{"id":[]}');

Also I think there is no need in

TDocVariant.New(vJSON);

Thanks for your reply but it still does not work. I still get the same error.

By the way, I used the same method at the example in https://synopse.info/files/html/Synopse … l#TITLE_39

There we have

var V: variant;
 ...
  V := _Json('{arr:[1,2]}');
  V.arr.Add(3);     // will work, since V.arr is returned by reference (varByRef)
  writeln(V);       // will write '{"arr":[1,2,3]}'

So even this example from the documentation does not work anymore.

JD

#15 mORMot 1 » [Solved] No variant method call dispatch error (occurs in Lazarus/FPC) » 2021-01-10 16:47:19

JD
Replies: 14

Hi there everyone,

I want to create a simple JSON object with a list of IDs like this: {id: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]}. I want to later loop over the array and save the IDs to a database.

This is the code I want to use to create the array is this:

// Create a JSON object like this:
// {id: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]}
//
procedure TForm1.Button1Click(Sender: TObject);
var
  vJSON: Variant;
  intX: integer;
begin
  //
  TDocVariant.New(vJSON);
  vJSON := _Json('{id:[]}');
  //
  for intX := 1 to 10 do
    vJSON.id.Add(intX);
end;

However, the code fails on

vJSON.id.Add(intX);

with the message No variant method call dispatch.

What am I doing wrong?

Thanks a lot,

JD

#16 Re: mORMot 1 » 2tier to 3tier migration. AdoDataset -> RestDataset solution » 2020-05-19 09:21:05

JD

@radexpol

Thanks for sharing your experience. I am quite interested in how you solved your problem. If you do go ahead and create a github repo, it will certainly be most welcome from people like me.

JD

#17 Re: mORMot 1 » Problematic FetchAllAsJSON using mORMot 1.18.5963/ZeosLib r6478 » 2020-04-29 08:19:50

JD
mpv wrote:

To check is the problem in Zeos itself or in SynDBZeos you can debug a TSQLDBZEOSStatement.ColumnsToJSON function. Here in line 1278 there is a condition define. Depends on it either Zeos serialization or Syn is used. In case of Syn serialization you can check is date returned correctly from Zeos layer.

The line

fResultSet.ColumnsToJSON(WR,fJSONComposeOptions);

is disabled for me because

{.$DEFINE USE_SYNCOMMONS} //enable JSON content support by using SynCommons.pas from Synopse project

is disabled in line 70 of Zeos.inc.

When I enabled it to try the ColumnsToJSON function, I get the following error messages in SynDBZeos and the compilation fails

Compile Project, Mode: Debug, Target: C:\....\Serveur.exe: Exit code 1, Errors: 5
SynDBZeos.pas(334,26) Error: Identifier not found "TZJSONComposeOptions"
SynDBZeos.pas(334,46) Error: Error in type definition
SynDBZeos.pas(413,34) Error: Identifier not found "TZJSONComposeOptions"
SynDBZeos.pas(414,15) Error: Property cannot have a default value
SynDBZeos.pas(414,16) Error: Identifier not found "jcoEndJSONObject"

This happens ONLY after I uncomment/enable line 70 of Zeos.inc

JD

#18 Re: mORMot 1 » Problematic FetchAllAsJSON using mORMot 1.18.5963/ZeosLib r6478 » 2020-04-29 07:56:42

JD
EgonHugeist wrote:

@JD
Which complier are you using? And which compile target(platform)?

Try to comment line

{$DEFINE INTEL_ASM} //allow intel syntax assembler

in \src\Zeos.inc. I didn't change many things lately in Postgres except switching procedure Revers4Bytes and Reverse8Bytes to asm. Maybe this fails. I'm not a asm guru.. It perfectyl works on Windows even with 64Bit..

Regards, Michael

Hello Michael,

I am using Lazarus 2.1/FPC 3.2rc1 Win32 svn 62815 running on Windows 10 Professional (x64). I only create Win32 executables.

I tried your suggestion and it did not work, unfortunately. The problem remains.

JD

#19 Re: mORMot 1 » Problematic FetchAllAsJSON using mORMot 1.18.5963/ZeosLib r6478 » 2020-04-28 17:14:57

JD
ttomas wrote:

Can you change some date to day<13, all bad dates have day > 12(months) just a hint

The constraints take care of bad dates so that is not the problem. Querying the database directly or using SynDBPostgres/FetchAllAsJSON gives me the right results; Zeos/FetchAllAsJSON does not.

#20 Re: mORMot 1 » Problematic FetchAllAsJSON using mORMot 1.18.5963/ZeosLib r6478 » 2020-04-28 15:26:00

JD
mpv wrote:

@JD - Postgres have many "date" types. You can help a Zeos maintainer ( @EgonHugeist on this forum ) if you provide exactly a type of column (as it visible in DBeaver or pgAdmin).
BTW ODBC will be definitely slower compared to Zeos or SynDBPostgres - they both use a direct libpq binding, while ODBC adds one more layer.

The column is just "DATE". The same table has two "TIMESTAMPZ" columns to track record creation & modification that don't have this problem.

I know about the "slow" ODBC. That is why I very rarely use it. It is often my last resort if nothing else exists/works.

Isn't Zeos the fastest method for accessing external databases? I've been using it since my Delphi days and it is one of the first things I install in Lazarus/FPC. It has always been very reliable.
The last time I had a problem with it was in 2016 https://zeoslib.sourceforge.io/viewtopi … 40&t=41785 (due to my inexperience with PostgreSQL back then when switching from Firebird) and curiously it was SynDBPostgres that saved the day back then too.

This time I think I will keep Zeos & SynDBPostgres options going forward.

Do you think I should post this problem on the Zeos forums also or is it unnecessary since EgonHugeist is here as well?

Thanks,

JD

#21 Re: mORMot 1 » Problematic FetchAllAsJSON using mORMot 1.18.5963/ZeosLib r6478 » 2020-04-28 12:03:25

JD

ODBC is proving a pain to set up. Is what I've done below correct because my mORMot server refuses to start after I compile?

    // https://www.connectionstrings.com/postgresql-odbc-driver-psqlodbc/
    // Driver={PostgreSQL UNICODE};Server=IP address;Port=5432;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
    fDbProps := TODBCConnectionProperties.Create('','Driver=PostgreSQL Unicode'+
        {$ifdef CPU64}'(x64)'+{$endif}';Database=testdb;'+
        'Server=localhost;Port=5432;UID=testdb;Pwd=testpwd','','');
    // To prevent PostgreSQL from hitting the default maximum connection limit of 100
    // and after rejecting subsequent connections
    TODBCConnectionProperties(fDbProps).ThreadingMode := tmMainConnection;

Thanks

JD

#22 Re: mORMot 1 » Problematic FetchAllAsJSON using mORMot 1.18.5963/ZeosLib r6478 » 2020-04-28 08:36:50

JD
mpv wrote:

What is the type of date_sanction columnus in database? Is SynDBPostgres works as expected ?

The "date_sanction" column is a simple date column.

I just tested SynDBPostgres and it works as expected. All dates were in the JSON result.

But soon as I changed back to a Zeos connection, I lost all but the first date. So the problem may be from Zeos.

I will try ODBC as soon as I can and report my findings.

JD

#23 Re: mORMot 1 » Problematic FetchAllAsJSON using mORMot 1.18.5963/ZeosLib r6478 » 2020-04-27 13:43:32

JD
ab wrote:

Which database are you using?

Did you try with another provider (e.g. ODBC)?

PostgreSQL 11.7 and I have not tried ODBC yet. I will do so and let you know my findings.

#24 mORMot 1 » Problematic FetchAllAsJSON using mORMot 1.18.5963/ZeosLib r6478 » 2020-04-27 11:05:49

JD
Replies: 18

Hi there everyone,

I just noticed a wierd behavior relating to dates with the FetchAllAsJson function. When I run a query I get a JSON array result where only the first object has dates. All the other objects have empty date values. Here is a sample JSON result I got from my query.

{
    "result": [
        [
            {
                "numero_sanction": 5,
                "numero_accueilli": 43,
                "date_sanction": "2019-07-07",
                "type_sanction": "Avertissement écrit",
            },
            {
                "numero_sanction": 4,
                "numero_accueilli": 43,
                "date_sanction": "",
                "type_sanction": "Mise à pied",
            },
            {
                "numero_sanction": 1,
                "numero_accueilli": 23,
                "date_sanction": "",
                "type_sanction": "Avertissement écrit",
            },
            {
                "numero_sanction": 2,
                "numero_accueilli": 23,
                "date_sanction": "",
                "type_sanction": "Avertissement écrit",
            },
            {
                "numero_sanction": 3,
                "numero_accueilli": 23,
                "date_sanction": "",
                "type_sanction": "Avertissement écrit",
            }
        ]
    ],
    "id": 9
}

This is not correct because it is impossible to save the records without a valid date. This was confirmed when I queried the PostgreSQL 11.7 database directly getting the expected result below:

numero_sanction|numero_accueilli|date_sanction|type_sanction      |
---------------|----------------|-------------|-------------------|
              5|              43|   2019-07-07|Avertissement écrit|
              4|              43|   2020-01-21|Mise à pied        |
              1|              23|   2018-03-21|Avertissement écrit|
              3|              23|   2018-08-28|Avertissement écrit|
              2|              23|   2018-08-28|Avertissement écrit|

This is the same for all my queries not just this one and this behaviour is recent. It was never like this before. I don't know if the problem is from mORMot or from ZeosLib.

Any assistance with resolving this problem will be appreciated.

Thanks,

JD

#25 Re: mORMot 1 » [SOLVED] Problem connecting to server with latest mORMot » 2020-04-24 15:40:34

JD

Hi there ab,

Sorry for the late reply. I have to apologize because I found the cause of the problem. It was a compiler directive that I disabled and had forgotten about in one of the source files. The end result was that the client and server were not using the same protocols. Everything now works perfectly.

Thank you very much for your time and for the suggestions you gave me.

JD

#27 Re: mORMot 1 » [SOLVED] Problem connecting to server with latest mORMot » 2020-04-23 09:45:05

JD
ab wrote:

Did you try to disable Compression := [hcSynShaAes] ?

I just tried it. It did not work either. Can I upload the Heaptrc dump images? There are just 2 of them.

JD

#28 Re: mORMot 1 » [SOLVED] Problem connecting to server with latest mORMot » 2020-04-22 23:03:49

JD

Hi ab,

This is what I did

fHTTPServer := TSQLHttpServer.Create(AnsiString(fServerSettings.Port), [fRestServer], '+', {HTTP_DEFAULT_MODE} useHttpSocket, 32, TSQLHttpServerSecurity.secSynShaAes);
THttpServer(fHTTPServer.HttpServer).WaitStarted();

It didn't work.

I can call my interface based services using my browser or an application like Postman but I can no longer connect to the server using a Lazarus client. This is what was happening even before the addition of THttpServer.WaitStarted.

JD

#29 Re: mORMot 1 » [SOLVED] Problem connecting to server with latest mORMot » 2020-04-22 22:31:49

JD

Hi there ab,

I ran TestSQL3 and some assertions failed. Here are the relevant messages:

 1.2. Low level types:
  - RTTI: 1,340 assertions passed  1.71ms
  - Url encoding: 200 assertions passed  1.31ms
  - Encode decode JSON: 429,322 assertions passed  2.47s
  - Wiki markdown to html: 56 assertions passed  492us
  - Variants: 88 assertions passed  386us
  - Mustache renderer: 153 assertions passed  1.03s
  - TDocVariant: 91,785 assertions passed  235.03ms
!  - TDecimal128: 22 / 17,446 FAILED  21.26ms
  - BSON: 245,068 assertions passed  18.98ms
     100000 TBSONObjectID.ComputeNew in 8.79ms i.e. 11,372,682/s, aver. 0us
  - TSynTableStatement: 221 assertions passed  8.40ms
  - TSynMonitorUsage: 1,202 assertions passed  3.26ms
  Total failed: 22 / 786,881  - Low level types FAILED  3.82s
.........
.........
Windows 10 64bit (10.0.18363) (cp1252)
    4 x Intel(R) Core(TM) i3-3240 CPU @ 3.40GHz (x86)
Using mORMot 1.18.5960
    TSQLite3LibraryStatic 3.31.0 with internal MM
Generated with: Free Pascal 3.2 32 bit compiler

Time elapsed for all tests: 3m25
Performed 2020-04-23 00:26:57 by JD on DESKTOP-NPLKN1D

Total assertions failed for all test suits:  22 / 44,408,725
! Some tests FAILED: please correct the code.

JD

#30 mORMot 1 » [SOLVED] Problem connecting to server with latest mORMot » 2020-04-22 18:17:36

JD
Replies: 10

Hi there everyone,

I just updated to the latest version of mORMot dated 22/04/2020. I recompiled my principal mORMot project and to my surprise, I can no longer connect to the Lazarus server from a Lazarus client.

My code is as follows:

Client side:

fClient := TSQLHttpClient.Create(AnsiString(fClientSettings.HostOrIP), AnsiString(fClientSettings.Port), fModel, false, '', '', fConnectionSettings.SendTimeout, fConnectionSettings.ReceiveTimeout, fConnectionSettings.ConnectTimeout);
TSQLHttpClient(fClient).Compression := [hcSynShaAes];

The values above are:
fConnectionSettings.SendTimeout = 15000
fConnectionSettings.ReceiveTimeout = 15000
fConnectionSettings.ConnectTimeout = 20000

Server side:

fHTTPServer := TSQLHttpServer.Create(AnsiString(fServerSettings.Port), [fRestServer], '+', {HTTP_DEFAULT_MODE} useHttpSocket, 32, TSQLHttpServerSecurity.secSynShaAes);
THttpServer(fHTTPServer.HttpServer).ServerKeepAliveTimeOut := CONNECTION_TIMEOUT;

This code works perfectly with older versions of mORMot. It is patterned after the example of George, in the list of mORMot examples. I have no idea why it no longer works.

I would appreciate any help in the resolution of this problem.


By the way, I am using Lazarus 2.1/fpc 3.2 rc1 Win32.

Cheers,

JD

#32 mORMot 1 » SynDBZeos compilation err: identifier idents no member "StartTransacti » 2020-04-20 09:02:48

JD
Replies: 4

Hi there everyone,

I just updated my mORMot version yesterday (19/04/2020) & I want to upgrade my two projects using mORMot. However as I tried to recompile one of the projects, I got an error in the SynDBZeos file on line 886 saying Error: identifier idents no member "StartTransaction". The compilation messages relating to only SynDBZeos.pas are shown below:

.....
.....
SynDBZeos.pas(707,30) Hint: Variable "Tables" of a managed type does not seem to be initialized
SynDBZeos.pas(734,64) Hint: Variable "Fields" of a managed type does not seem to be initialized
SynDBZeos.pas(886,13) Error: identifier idents no member "StartTransaction"
SynDBZeos.pas(962,17) Hint: Local variable "ndx" does not seem to be initialized

Any ideas what I can do to correct this problem?

Thanks a lot in advance for your assistance

JD

PS: I am using Lazarus 2.0.7/fpc 3.2 svn 62681 (Win 32) on Windows 10 Professionnal (x64)

#33 Re: mORMot 1 » Problems handling spaces (Java strings to FreePascal strings) » 2019-11-11 23:20:26

JD

Thanks a lot for the tip Esteban. It works properly now.

JD

#34 mORMot 1 » Problems handling spaces (Java strings to FreePascal strings) » 2019-11-11 20:25:28

JD
Replies: 2

Hi there everyone,

I have a mORMot REST server and I'm trying to send requests to it from a Java application.

Java strings are UTF16 by default and I want to get a list of users from the backend database by
sending query parameters in JSON format to the REST server.

I send a JSON string like this to the mORMot server:

{"etat":"Comptes activés"}

The mORMot server truncates the JSON string as follows:

{"etat":"Comptes

I made some changes and I noticed that the JSON string is not truncated when I send the
string with an underscore between the two words as follows:

{"etat":"Comptes_activés"}

The mORMot REST method looks like this

function TRESTMethods.Utilisateurs(Params: RawUTF8): RawJSON;
var
  Res: ISQLDBRows;
  Ctxt: TServiceRunningContext;
  vParams: Variant;
begin
  // Get the parameters - Java strings are UTF-16 by default so a convertion to
  // UTF-8 is necessary here
  vParams := _JsonFast(StringToUTF8(Params));

  // NOTE vParams is empty when I send {"etat":"Comptes activés"} but it is OK
  // when I send {"etat":"Comptes_activés"} with an underscore between 'Comptes'
  // and 'activés'

  // Set the current service context
  Ctxt := CurrentServiceContext;

  //
  try
    // more code here
  finally
    Res := nil;
  end;
end;

Can anybody please help me resolve this problem.

Thanks a lot,

JD

#35 Re: mORMot 1 » Minimal SessionID implementation » 2018-11-22 12:52:44

JD
ab wrote:

Why are you marshaling by hand the parameters?

Because at one time, the values sent by the client did not seem to be getting to the server. Why? I don't know. So I inserted all the UrlDecodeValue code to test it and I kind of left it like that. It works OK now though.

JD

#36 Re: mORMot 1 » Minimal SessionID implementation » 2018-11-21 20:40:24

JD

Hi there ab,

I am interested in this also. How do I implement it? I am not using any authentication at all and my REST server is a memory server like this

fModel     := TSQLModel.Create([], ROOT_NAME);
fRestServer := TSQLRestServerFullMemory.Create(fModel, false);

In addition, my interface methods have the following format:

function TRESTMethods.Partenaires(ID, List, DTO, Mfd, ContentType: RawUTF8): RawJSON;
var
  Res: ISQLDBRows;
  aObj: TSQLPartenaire;
  Ctxt: TServiceRunningContext;
begin
  Result := '';
  //
  if aServer.fDBProps = nil then
    raise Exception.Create(SQLCONNECTIONINACTIVE);
  // Set the current service context
  Ctxt := CurrentServiceContext;
  // Get/set the parameter values
  UrlDecodeValue(Ctxt.Request.Parameters, 'id=', ID);
  UrlDecodeValue(Ctxt.Request.Parameters, 'list=', List);
  if List = EmptyStr
    then List := 'Y';
  UrlDecodeValue(Ctxt.Request.Parameters, 'dto=', DTO);
  UrlDecodeValue(Ctxt.Request.Parameters, 'mfd=', Mfd);  
  if Mfd = EmptyStr
    then Mfd := 'Non';

  // REST OF THE CODE HERE
end;

Thanks a lot in advance.

JD

#37 Re: mORMot 1 » Solve Generics Error compiling ThirdPartyDemos\George\REST-tester » 2018-10-30 16:47:29

JD

Thanks for the tip. I was wondering why it was no longer possible to compile the sample as it was in the past versions of mORMot.

#39 mORMot 1 » Where is the DateTimeToSQL function? » 2018-10-02 13:56:33

JD
Replies: 2

Hi there everyone,

I'm trying to compile some old code that requires the use of the DateTimeToSQL function. I thought it was in SynCommons.pas but it no longer seems to be the case.

Where is this function located now?

Thanks,

JD

#40 Re: mORMot 1 » Problems encoding JSON array in URL for sending to PostgreSQL server » 2018-09-25 11:53:38

JD

I finally got it to work. This time I stopped encoding the JSON array before sending it to the REST server and it now works in the Lazarus clients as well as when I call the function from an SQL tool or even from my browser.

Thanks a lot,

JD

#41 mORMot 1 » Problems encoding JSON array in URL for sending to PostgreSQL server » 2018-09-23 18:08:49

JD
Replies: 1

Hi there everyone,

(a) BACKGROUND
I've been struggling with this problem for a couple of days. I have a mORMot REST interface application server in front of a PostgreSQL 10.5 server. It is working very well for a while now.

I just wrote a function in the PostgreSQL server that generates and returns work/planning schedules as a JSON text output to clients. The PostgreSQL function has the following signature:

CREATE OR REPLACE FUNCTION public.agg_planning_json(id_json text, date_debut date, date_fin date)

The function expects the id_json parameter to have the following format:

{"ID": [20,19]}

I have tested this function directly in the PostgrSQL server and it works well. I can even call the function from any browser or REST client after encoding the JSON input parameter like this

http://localhost:8088/service/myapi/rapportplanning?schema=public&idlist=%7B%22ID%22%3A%20%5B19%2C20%5D%7D&datedebut='2018-01-01'&datefin='2018-04-30'

and it works.

The mORMot REST server code that handles these requests looks like this:

Res := aServer.fDbProps.Execute(Format('select * from %s.agg_planning_json(%s, %s, %s)',
   [Schema, QuotedStr(IDList), QuotedStr(DateDebut), QuotedStr(DateFin)]), []);
while Res.Step do
   Result := Res.ColumnUTF8('agg_planning_json');

(b) THE PROBLEM
My problem is with the Lazarus clients. I send the request to the server after encoding the JSON array as follows:

ARestThread.Post(sqlPlanningSalarie, '', '', [UrlEncode(strIDList), SQLDate(dtDateDebut.Date), SQLDate(dtDateFin.Date)]);

This ALWAYS fails with the error below:

Project server raised exception class 'Unknown' with message
SQL Error: ERREUR: syntaxe en entrée invalide pour le type json
DETAIL: le jeton << % >> n'est pas valide
CONTEXT: données JSON, ligne %1 : %...
instruction SQL << SELECT * FROM json_array_elements_text(id_json::json -> 'ID') >>
.....

The PostgreSQL function seems to be complaining about the format of the JSON parameter. I noticed that the Lazarus client sends the parameters to the server with each parameter in double quotes " ". Could this be the source of the problem? Is this normal? How do I correct this problem?

Thanks a lot for your assistance,

JD

#42 Re: mORMot 1 » Latest mORMot.pas does not compile under latest FPC. » 2018-09-20 08:57:00

JD
pvn0 wrote:

Do you guys use fpcupdeluxe? I have never been able to install anything with that, I always do it manually.

I use fpcupdeluxe to test trunk builds and sometimes to install NewPascal. I did not use it in my most recent install because FPC trunk is now 3.3.1 and some have said in this thread that it does not compile the latest mORMot.

That is why I chose to install Lazarus 1.9/FPC 3.2.0 Beta instead which is more recent than NewPascal and does not seem to have the problem associated with FPC trunk.

JD

#43 Re: mORMot 1 » Latest mORMot.pas does not compile under latest FPC. » 2018-09-18 11:50:47

JD

I had the same problem. I keep two versions of Lazarus: NewPascal (with FPC 3.1.1) and Lazarus 1.8.4/FPC 3.0.4 stable on my system. This was OK for me until the Lazarus 1.8.4/FPC 3.0.4 could no longer handle the new TypeInfo changes in the latest version of mORMot (SynFPCTypInfo.pas).

Luckily, I saw on the Lazarus forum a new package Lazarus 1.9/FPC 3.2.0 Beta.

http://forum.lazarus-ide.org/index.php/ … ajilg0#new

https://sourceforge.net/projects/lazaru … ndow%2032/
https://sourceforge.net/projects/lazaru … ndow%2064/

I installed this and it compiled the latest mORMot releases flawlessly; I guess because the FPC compiler is more recent and so has the RTTI changes that NewPascal was created to handle. It also compiled the old code I was keeping Lazarus 1.8.4/FPC 3.0.4 around for.

So it looks like I may move ALL my projects to Lazarus 1.9/FPC 3.2.0 Beta and get rid of my existing NewPascal & Lazarus 1.8.4/FPC 3.0.4 combo.

I encourage you to try it. It may be the solution to your problem.

I can confirm that the line

Line 56267:             ParamName := @VMP^.Name;  

is compiled properly

Cheers,

JD

#44 Re: mORMot 1 » SynFPCTypInfo.pas(92,26) Error: Identifier not found "PRecInitData" » 2018-09-10 13:47:10

JD

I have the same problem. My server is developed using NewPascal BUT the client was developed using Lazarus/FPC 1.8.4; I have to do that because NewPascal cannot compile certain components that I'm using client-side.

NewPascal compiles the newest mORMot but Lazarus/FPC 1.8.4 does not because of the new typeinfo code

type
  /// some type definition to avoid inclusion of TypInfo in main SynCommons.pas
  PRecInitData = TypInfo.PRecInitData;

Is there any way to use say {$define} to smartly get around this constraint.

Thanks a million,

JD

#45 Re: mORMot 1 » Learning mORMot, information overload » 2018-06-13 11:59:01

JD

I fully understand where you all are coming from. There is so much to learn in mORMot and I started toying with it in 2015. mORMot has the largest user documentation I've ever encountered outside of PostgreSQL user documentation. It took me over a year before I was able to build a mORMot application. I only know about 40% of mORMot. I completely ignored the ORM/SQLite part and my mORMot server talks to a PostgreSQL database using Zeos.

I was finally able to get going thanks to George's Third Party demo
https://github.com/synopse/mORMot/tree/ … EST-tester

That in addition to the demos referenced by edwinsn in earlier in this thread helped me build my application. My requirements were simple; I wanted

a) an interface based application
b) service oriented architecture (SOA)
b) working over HTTP
c) using JSON to move data from the server to the clients
d) my PostgreSQL database handles user authentication (I don't use the ORM authentication part of mORMot OR any ORM features at all)

These requirements helped me streamline my research and I now have a working application thanks also to the wonderful advice I got from this forum. I still have work to do because I have not succeeded in encrypting the JSON data in transit. I can compress it but I have not yet fathomed how to move from HTTP to WebSockets.

So I would advice you to start small, streamline your needs and let them guide your research. You'll discover that it will be worth your efforts in the long run because I've discovered that using SOA with mORMot allows me to add new functionalities/services very quickly without breaking existing services. That is a very important issue for me. So, all the best.


Cheers,

JD

#46 Re: mORMot 1 » NewPascal 1.9 cannot compile mORMot programs » 2018-05-08 10:05:29

JD
EgonHugeist wrote:

Hi JD,

{$if defined(ZEOS73UP) and defined(USE_SYNCOMMONS)}
  fResultSet.ColumnsToJSON(WR);
  {$ELSE}
...

as Arnaud wrote: the IZResultSet.ColumnsToJSON is part of Zeos, defined in ZDbcIntfs.pas.
It skips the interface calling chain and brings best performance per driver to write the JSON contents.

I wonder about your regression. As the define shows, you can use the procedure only if both defines are enabled.
The ZEOS73UP define is located in Zeos.inc (included in SynDBZeos.pas) and available only in the 7.3 branches. 
Secondary define is your choice to define it in your Project.

Check old revisions of zeos on your computer. It looks to me like your mixing old files somewhere. Check the USE_SYNCOMMONS define too. 

@hnb
great news for Zeos, thank to all.


Hi there Michael,

I am talking about 3 separate computers here. My Windows 7 laptop has the newest NewPascal, mORMot and Zeos, that is the one on which I am trying to get ColumnsToJSON to work.

My Windows 7 desktop has older versions of all three, all is well over there as it does not use ColumnsToJSON (I checked it) smile. On my desktop the line 61 of Zeos.inc was undefined by default.

I have a third Linux laptop with older versions where compilation is OK there too.

I still persist in saying I did not define USE_SYNCOMMONS in line 61 of Zeos.inc of the Zeos version I downloaded this morning.

Cheers,

JD

EDIT: Sorry I reported your post by mistake smile

#47 Re: mORMot 1 » NewPascal 1.9 cannot compile mORMot programs » 2018-05-08 08:33:24

JD
hnb wrote:

This was some time ago, when I was part of FPC core team and NewPascal was almost integrated with official FPC page... Now I have ban in FPC core mailing list and I don't have access to trunk anymore - there is no rational reason for my banishment... I am not able to provide any updates, bug fixes nor new features into FPC trunk. Political decision and revenge of one person in core team...

Anyway still nothing wrong with using FPC trunk instead of NewPascal - individual decision smile.

I read what you posted on the Lazarus forum and I was not happy. We are a small community and we need each other so that the project can move forward and stay alive.

Maybe you should accept Thaddy's offer of mediation so that we can get over this speedbump and move forward.

JD

#48 Re: mORMot 1 » NewPascal 1.9 cannot compile mORMot programs » 2018-05-08 08:29:21

JD
ab wrote:

ColumnsToJSON is part of Zeos, not mORMot.
You enabled it by defining the conditional.

As side effect, it will be faster, since Zeos will directly generate the JSON for you.

Hi there ab,

I did not define the conditional. It was defined in the most recent version of Zeos that I downloaded from NewPascal GitHub. I have an older version of Zeos 7.3 alpha where it was undefined. I just verified that.

So what do I do now, I like the extra speed gains ColumnsToJSON will bring to my server? smile

Should we bring EgonHugeist/Michael into the picture?

Cheers,

JD

#49 Re: mORMot 1 » NewPascal 1.9 cannot compile mORMot programs » 2018-05-08 08:01:42

JD
hnb wrote:

Probably you need latest Zeos (I am not sure here), you can download proper/newest version of Zeos here : https://github.com/newpascal-ccr/zeos

Zeos will be part of next release of NewPascal like mORMot smile .

There is still a problem somewhere. I did as you suggested and got Zeos from the link you provided but the result was the same.

I got the following error message as before in SynDBZeos.pas:

SynDBZeos.pas(1248,14) Error: identifier idents no member "ColumnsToJSON"

The line with the problem is as follows:

  {$if defined(ZEOS73UP) and defined(USE_SYNCOMMONS)}
  fResultSet.ColumnsToJSON(WR);
  {$ELSE}

However, when I edited line 61 of Zeos.inc and undefined USE_SYNCOMMONS like this:

{.$DEFINE USE_SYNCOMMONS} //enable JSON content support by using SynCommons.pas from Synopse project

I was then able to compile my project. So it looks like the problem comes from how Zeos 7.3 and above are supposed to use SynCommons.pas.

I was unable to locate the method ColumnsToJSON in SynCommons.pas so where is this method located?

Ideally, I would prefer to be able to export resultsets to JSON using ColumnsToJSON as expected.

While this "workaround" enabled me to compile my project, what are the side-effects in terms of speed of the REST server's
handling of queries?

Cheers,

JD

#50 Re: mORMot 1 » NewPascal 1.9 cannot compile mORMot programs » 2018-05-07 10:07:35

JD

Hi all,

I'm going with NewPascal option 2 for the moment.

a) I used fpcupdeluxe to download and build NewPascal (07/05/2018)
b) I got a new version of mORMot from GitHub (07/05/2018)
c) I set everything up and compiled TestSQL3 successfully
d) I now went back to my project and tried to recompile it

I got the following error message in SynDBZeos.pas:

SynDBZeos.pas(1248,14) Error: identifier idents no member "ColumnsToJSON"

The line with the problem is as follows:

  {$if defined(ZEOS73UP) and defined(USE_SYNCOMMONS)}
  fResultSet.ColumnsToJSON(WR);
  {$ELSE}

The OPM tells me I'm using Zeos 7.3. How do I correct this problem?

Cheers,

JD

Board footer

Powered by FluxBB