Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2022-11

SQLDBRestBridge

14 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

duilio foschi

I could get client and server talk each other.

For the future, it would be nice to have the server (when in debug mode) write a log of commands and data exchanged with the client.

Both inbound and outbound commands/data are needed.

I have a hard time figuring out where to insert my code.

Any help?

Thank you

Peppe

Reply by email

Michael Van Canneyt
to duilio foschi
duilio foschi wrote
I could get client and server talk each other. For the future, it would be nice to have the server (when in debug mode) write a log of commands and data exchanged with the client.

This exists already. TRestDispatcherLogOption gives you this.

In fact, there are 2 properties:

     // Logging options
     Property LogOptions : TRestDispatcherLogOptions Read FLogOptions write FLogOptions default DefaultDispatcherLogOptions;
     // SQL Log options. Only for connections managed by RestDispatcher
     Property LogSQLOptions : TDBEventTypes Read FDBLogOptions write FDBLogOptions default DefaultLogSQLOptions;

And add a OnLog event handler.

If you think some extra option is needed, let me know and I will see what I can do.

Michael.

Reply by email

duilio foschi
to Michael Van Canneyt

Hi Michael,

I was able to log the info shown in this pic
https://i.ibb.co/f4MJQFJ/1.jpg

(I used a rough writeln for now).

This is fine when you want to verify the behaviour of the application itself.

1.
==
Is there a way to have the server log HTTP commands received from the client?

Like:
http://localhost:3000/EXPENSES?fmt=buf&humanreadable=1

2.
==
Is there a way to have the server log the data returned to the client?

This data will be very valuable when trying to debug a client developed by 3th parties that misbehave (what is my condition now).

The alternative will be to use a HTTP proxy.

Thank you

Peppe

AM Michael Van Canneyt wrote 30 lines
On Thu, 3 Nov 2022, duilio foschi via lazarus wrote: > I could get client and server talk each other. > > For the future, it would be nice to have the server (when in debug > mode) write a log of commands and data exchanged with the client. This exists already. TRestDispatcherLogOption gives you this. In fact, there are 2 properties: // Logging options Property LogOptions : TRestDispatcherLogOptions Read FLogOptions write FLogOptions default DefaultDispatcherLogOptions; // SQL Log options. Only for connections managed by RestDispatcher Property LogSQLOptions : TDBEventTypes Read FDBLogOptions write FDBLogOptions default DefaultLogSQLOptions; And add a OnLog event handler. If you think some extra option is needed, let me know and I will see what I can do. Michael. -- _______________________________________________ lazarus mailing list https://lists.lazarus-ide.org/listinfo/lazarus

Reply by email

Michael Van Canneyt
to duilio foschi
duilio foschi wrote 15 lines
Hi Michael, I was able to log the info shown in this pic https://i.ibb.co/f4MJQFJ/1.jpg (I used a rough writeln for now). This is fine when you want to verify the behaviour of the application itself. 1. == Is there a way to have the server log HTTP commands received from the client? Like: http://localhost:3000/EXPENSES?fmt=buf&humanreadable=1

Yes.

Please look at the intercept example. You can register an interceptor (a kind of middleware) and log all URLs.

Show quoted text 8 lines
2. == Is there a way to have the server log the data returned to the client? This data will be very valuable when trying to debug a client developed by 3th parties that misbehave (what is my condition now). The alternative will be to use a HTTP proxy.

Same here: you can register an interceptor for this, use the iaAfter to indicate that the interceptor takes place after the request was handled.

The content should still be available in the response.content or response.contentstream.

Michael.

Reply by email

duilio foschi
to Michael Van Canneyt
Please look at the intercept example

could you please expand on this?

Where do I find the intercept example?

Thank you

Peppe

PM Michael Van Canneyt wrote 48 lines
On Thu, 3 Nov 2022, duilio foschi wrote: > Hi Michael, > > I was able to log the info shown in this pic > https://i.ibb.co/f4MJQFJ/1.jpg > > (I used a rough writeln for now). > > This is fine when you want to verify the behaviour of the application itself. > > 1. > == > Is there a way to have the server log HTTP commands received from the client? > > Like: > http://localhost:3000/EXPENSES?fmt=buf&humanreadable=1 Yes. Please look at the intercept example. You can register an interceptor (a kind of middleware) and log all URLs. > 2. > == > Is there a way to have the server log the data returned to the client? > > This data will be very valuable when trying to debug a client > developed by 3th parties that misbehave (what is my condition now). > > The alternative will be to use a HTTP proxy. Same here: you can register an interceptor for this, use the iaAfter to indicate that the interceptor takes place after the request was handled. The content should still be available in the response.content or response.contentstream. Michael. -- _______________________________________________ lazarus mailing list https://lists.lazarus-ide.org/listinfo/lazarus

Reply by email

Michael Van Canneyt
to duilio foschi
duilio foschi wrote
> Please look at the intercept example could you please expand on this?

In the http request router, you can register global handlers which are executed for every request. You can choose if the handler is executed before or after the normal handler for the request.

Where do I find the intercept example?

https://gitlab.com/freepascal.org/fpc/source/-/blob/main/packages/fcl-web/examples/intercept/simpleserver.pas

This example shows both kind of handlers, before and after request. The before request handler just logs the URL, just what you need.

Michael.

Reply by email

duilio foschi
to Michael Van Canneyt

Hi Michael,

I am digging into your SQLDBRestBridge component. Very useful code.

I could fix and run both the server part and the client part (I used the BufDataset client).

My code (with very few changes applied to the original one) can be downloaded from this link:
https://mega.nz/file/Gxx3FBya#LbvDvuFnH5rUDVAdPoGyuUCnkNE761A62SZ1MYX8oFQ

I hope it be helpful for somebody.

I have 2 questions:

1. the client needs to know the name of the primary key (PK) of each table. Is there a way to ask the server for the name of the PK of table A? Or to have the PK listed in the metadata?

2. the client needs to periodically refresh the visible rows in the event that another client applied changes to the DB. How is this done? I reckon that the client will remember the last command like
BASEURL/resourcename?limit=10&Offset=50
and reissue it. Right?

Thank you

Peppe

AM Michael Van Canneyt wrote 23 lines
On Thu, 3 Nov 2022, duilio foschi wrote: >> Please look at the intercept example > > could you please expand on this? In the http request router, you can register global handlers which are executed for every request. You can choose if the handler is executed before or after the normal handler for the request. > > Where do I find the intercept example? https://gitlab.com/freepascal.org/fpc/source/-/blob/main/packages/fcl-web/examples/intercept/simpleserver.pas This example shows both kind of handlers, before and after request. The before request handler just logs the URL, just what you need. Michael.

Reply by email

Michael Van Canneyt
to duilio foschi
duilio foschi wrote 20 lines
Hi Michael, I am digging into your SQLDBRestBridge component. Very useful code. I could fix and run both the server part and the client part (I used the BufDataset client). My code (with very few changes applied to the original one) can be downloaded from this link: https://mega.nz/file/Gxx3FBya#LbvDvuFnH5rUDVAdPoGyuUCnkNE761A62SZ1MYX8oFQ I hope it be helpful for somebody. I have 2 questions: 1. the client needs to know the name of the primary key (PK) of each table. Is there a way to ask the server for the name of the PK of table A? Or to have the PK listed in the metadata?

Normally the server has this info, and the primary key is retrieved when exposing a database. It is part of fieldinfo, but not yet exposed in the metadata, I think. I will add it, this is easy to do.

Show quoted text 6 lines
2. the client needs to periodically refresh the visible rows in the event that another client applied changes to the DB. How is this done? I reckon that the client will remember the last command like BASEURL/resourcename?limit=10&Offset=50 and reissue it. Right?

Yes, but you need to program this yourself.

Michael.

Reply by email

duilio foschi
to Michael Van Canneyt

I fixed the code in Lazarus and got a client based on BufDataClient that successfully talks with a restbridge server.

As a next step, I'd like to connect to the same server from a TWebForm of TMS Web Core library.

I started with a slow step. There is only a TWebHttpRequest in the form (which has the same functions of a TFPHTTPClient) and it issues a GET to URL
http://localhost:3000/metadata/?fmt=json&humanreadable=0

This command works ok in the windows client.

Here, I get the errors shown in pic
https://i.ibb.co/dpsjfQQ/1.jpg

The message (a CORS error) is attached below.

Weird enough, the message is there even after changing the server code in this way:

original code:
   FDisp.DispatchOptions:=FDisp.DispatchOptions+[rdoCustomView,rdoHandleCORS];
new code
    FDisp.DispatchOptions:=FDisp.DispatchOptions+[rdoCustomView];

Is there a way to tell the server to ignore CORS errors?

Or there a way to sweet-talk the server to accept the requests from a TMS Web form? :)

Thank you

Peppe

project1.html:1 Access to XMLHttpRequest at
'http://localhost:3000/metadata/?fmt=json&humanreadable=0' from origin 'http://localhost:8000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
project1.js:263 Uncaught {fMessage: 'HTTP request error @http://localhost:3000/metadata/?fmt=json&humanreadable=0'} cb @ project1.js:263
error (async)
Execute$2 @ project1.js:12331
Execute @ project1.js:12316
btnClick @ project1.js:12649
cb @ project1.js:241
Click @ project1.js:6631
HandleDoClick @ project1.js:6120
cb @ project1.js:241
project1.js:12356 GET
http://localhost:3000/metadata/?fmt=json&humanreadable=0 net::ERR_FAILED
Execute$2 @ project1.js:12356
Execute @ project1.js:12316
btnClick @ project1.js:12649
cb @ project1.js:241
Click @ project1.js:6631
HandleDoClick @ project1.js:6120
cb @ project1.js:241

PM Michael Van Canneyt wrote 45 lines
On Sun, 6 Nov 2022, duilio foschi wrote: > Hi Michael, > > I am digging into your SQLDBRestBridge component. Very useful code. > > I could fix and run both the server part and the client part (I used > the BufDataset client). > > My code (with very few changes applied to the original one) can be > downloaded from this link: > https://mega.nz/file/Gxx3FBya#LbvDvuFnH5rUDVAdPoGyuUCnkNE761A62SZ1MYX8oFQ > > I hope it be helpful for somebody. > > > > I have 2 questions: > > 1. the client needs to know the name of the primary key (PK) of each > table. Is there a way to ask the server for the name of the PK of > table A? Or to have the PK listed in the metadata? Normally the server has this info, and the primary key is retrieved when exposing a database. It is part of fieldinfo, but not yet exposed in the metadata, I think. I will add it, this is easy to do. > 2. the client needs to periodically refresh the visible rows in the > event that another client applied changes to the DB. How is this done? > I reckon that the client will remember the last command > like > BASEURL/resourcename?limit=10&Offset=50 > and reissue it. Right? Yes, but you need to program this yourself. Michael. -- _______________________________________________ lazarus mailing list https://lists.lazarus-ide.org/listinfo/lazarus

Reply by email

Michael Van Canneyt
to duilio foschi
duilio foschi wrote 5 lines
I fixed the code in Lazarus and got a client based on BufDataClient that successfully talks with a restbridge server. As a next step, I'd like to connect to the same server from a TWebForm of TMS Web Core library.

Normally, TMS Web Core contains a dataset component that handles SQLDBRest connections?.

I wrote it myself for them.

Show quoted text 12 lines
I started with a slow step. There is only a TWebHttpRequest in the form (which has the same functions of a TFPHTTPClient) and it issues a GET to URL http://localhost:3000/metadata/?fmt=json&humanreadable=0 This command works ok in the windows client. Here, I get the errors shown in pic https://i.ibb.co/dpsjfQQ/1.jpg The message (a CORS error) is attached below.

Aaaahhh... Welcome to CORS hell... :/

Show quoted text 9 lines
Weird enough, the message is there even after changing the server code in this way: original code: FDisp.DispatchOptions:=FDisp.DispatchOptions+[rdoCustomView,rdoHandleCORS]; new code FDisp.DispatchOptions:=FDisp.DispatchOptions+[rdoCustomView];

This is the exact opposite of what you should do.

The rdoHandleCORS option must be there, or CORS will not be handled at all.

Is there a way to tell the server to ignore CORS errors?

The CORS errors are from the browser, not from the server.

Or there a way to sweet-talk the server to accept the requests from a TMS Web form? :)

Yes, you must add localhost as an allowed origin in CORSAllowedOrigins.

FDisp.CORSAllowedOrigins:='localhost:3000'
If you are not using authentication, as an alternative, you can try
FDisp.CORSAllowedOrigins:='*'

Michael.

Reply by email

duilio foschi
to Michael Van Canneyt

I am puzzled by TMS Software.

1. there is one demo specific for SQLDBRestBridge, but the application is obviously bugged, as you see from the following screenshot
https://i.ibb.co/m4wVGtM/2.jpg

as a start, the code for the login and logout button is the same, what cannot be

2. the support will deny even under torture the idea that TMS code can have bugs. The fault is always yours. You did not read the manual carefully (666 pages) or did not study CORS carefully or have knowledge gaps. All true in my case... but I can see a bug when I meet one :)

3. in the end, they will suggest you buy their bridge solution, called XData, as they cannot waste their time with a bridge server they did not write (verbatim) :)

Probably (I reckon) they are not very interested in the Lazarus market, as they gain most income from the Delphi market.

As a matter of fact, I find their support not
dont help you to solve your problem: they will deny that a problem exists or will pretend that you will be able to solve your problem after a few months' study of technical documentation :)

I bought TMS Web Core months ago with the idea of quickly write web applications in Lazarus, with a special aim at their TWebGridComponent, but I can say today that it was no wise purchase :)

Thank you

Peppe

AM Michael Van Canneyt wrote 68 lines
On Mon, 7 Nov 2022, duilio foschi wrote: > I fixed the code in Lazarus and got a client based on BufDataClient > that successfully talks with a restbridge server. > > As a next step, I'd like to connect to the same server from a TWebForm > of TMS Web Core library. Normally, TMS Web Core contains a dataset component that handles SQLDBRest connections?. I wrote it myself for them. > > I started with a slow step. There is only a TWebHttpRequest in the > form (which has the same functions of a TFPHTTPClient) and it issues a > GET to URL > http://localhost:3000/metadata/?fmt=json&humanreadable=0 > > This command works ok in the windows client. > > Here, I get the errors shown in pic > https://i.ibb.co/dpsjfQQ/1.jpg > > The message (a CORS error) is attached below. Aaaahhh... Welcome to CORS hell... :/ > > Weird enough, the message is there even after changing the server code > in this way: > > original code: > FDisp.DispatchOptions:=FDisp.DispatchOptions+[rdoCustomView,rdoHandleCORS]; > > new code > FDisp.DispatchOptions:=FDisp.DispatchOptions+[rdoCustomView]; This is the exact opposite of what you should do. The rdoHandleCORS option must be there, or CORS will not be handled at all. > > Is there a way to tell the server to ignore CORS errors? > The CORS errors are from the browser, not from the server. > Or there a way to sweet-talk the server to accept the requests from a > TMS Web form? :) Yes, you must add localhost as an allowed origin in CORSAllowedOrigins. FDisp.CORSAllowedOrigins:='localhost:3000' If you are not using authentication, as an alternative, you can try FDisp.CORSAllowedOrigins:='*' Michael. -- _______________________________________________ lazarus mailing list https://lists.lazarus-ide.org/listinfo/lazarus

Reply by email

Michael Van Canneyt
to duilio foschi
duilio foschi wrote
I am puzzled by TMS Software.

You are not alone. Your story is recognizable.

[snip]

I bought TMS Web Core months ago with the idea of quickly write web applications in Lazarus, with a special aim at their TWebGridComponent, but I can say today that it was no wise purchase :)

What can I say ?

We cooperated with them, we have made pas2js available to them, we provide quick bugfixes and improvements of pas2js, but we have no control over what they do with it or how their helpdesk functions.

As for the grid component:
In my daily work development environment we switched to using datatables.net. I can recommend it, just as bootstrap-table. It has all you need.

It's perfectly usable with pas2js and the import units are available with pas2js.

Michael.

Reply by email

duilio foschi
to Michael Van Canneyt
we switched to using datatables.net

very interesting.

Is any sample code available for its use with pas2js? .

Thank you

Peppe

PM Michael Van Canneyt wrote 34 lines
On Tue, 8 Nov 2022, duilio foschi wrote: > I am puzzled by TMS Software. You are not alone. Your story is recognizable. [snip] > I bought TMS Web Core months ago with the idea of quickly write web > applications in Lazarus, with a special aim at their > TWebGridComponent, but I can say today that it was no wise purchase :) What can I say ? We cooperated with them, we have made pas2js available to them, we provide quick bugfixes and improvements of pas2js, but we have no control over what they do with it or how their helpdesk functions. As for the grid component: In my daily work development environment we switched to using datatables.net. I can recommend it, just as bootstrap-table. It has all you need. It's perfectly usable with pas2js and the import units are available with pas2js. Michael. -- _______________________________________________ lazarus mailing list https://lists.lazarus-ide.org/listinfo/lazarus

Reply by email

Michael Van Canneyt
to duilio foschi
duilio foschi wrote 5 lines
> we switched to using datatables.net very interesting. Is any sample code available for its use with pas2js? .

Hm. I just noticed this was not migrated from our old SVN repo to the Git repo :-/

Luckily I kept a copy of the SVN repos :-)

I added the code and an example to git:

See
packages/datatables
demo/datatables

or

https://gitlab.com/freepascal.org/fpc/pas2js/-/tree/main/packages/datatables https://gitlab.com/freepascal.org/fpc/pas2js/-/tree/main/demo/datatables

Should something still be missing, let me know.

Michael.

Show quoted text 42 lines
Thank you Peppe On Wed, Nov 9, 2022 at 1:08 PM Michael Van Canneyt via lazarus wrote: > > > > On Tue, 8 Nov 2022, duilio foschi wrote: > >> I am puzzled by TMS Software. > > You are not alone. Your story is recognizable. > > [snip] > >> I bought TMS Web Core months ago with the idea of quickly write web >> applications in Lazarus, with a special aim at their >> TWebGridComponent, but I can say today that it was no wise purchase :) > > What can I say ? > > We cooperated with them, we have made pas2js available to them, > we provide quick bugfixes and improvements of pas2js, > but we have no control over what they do with it or how their helpdesk > functions. > > As for the grid component: > In my daily work development environment we switched to using datatables.net. > I can recommend it, just as bootstrap-table. It has all you need. > > It's perfectly usable with pas2js and the import units are available with pas2js. > > Michael. > -- > _______________________________________________ > lazarus mailing list > > https://lists.lazarus-ide.org/listinfo/lazarus

Reply by email