#1 2020-11-20 04:11:19

Prometeus
Member
From: USA
Registered: 2020-11-20
Posts: 42

Error accessing an external Firebird database

Hello,

I begin using the Mormot framework and my primary interest in it is as a REST server. I read some docs about how to do for Mormot to access external databases (Firebird in this case), including the Mormot manual related, and I created a small test, but it is raising an error when I call 'CreateMissingTables'. The code and the error message generated are at https://gist.github.com/PrometeusRec/c4 … 68732fbd9f

I am using the latest 'Zeos' version and compiling for Delphi 10.3.3

I am trying to fix this basic thing for two days, but I can't understand what is wrong with it. The 'TEST.FDB' database has just two raws but looks like the 'ID' field is not being really created in the 'CreateMissingTables' call, but it thinks that it was, and then the error message raised. Am I missing something for this test work?

Thanks for any help.

Offline

#2 2020-11-20 12:54:06

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

Re: Error accessing an external Firebird database

Is the table non existing when you try CreateMissingTables?

Online

#3 2020-11-20 17:11:23

Prometeus
Member
From: USA
Registered: 2020-11-20
Posts: 42

Re: Error accessing an external Firebird database

The test table already exists. I created a fresh Firebird database with just one table and two fields only to begin to understand and learn the Mormot framework. I was expecting that the "CreateMissingTables" call create the 'ID' field on that table. However, that is not happening and, according to the error posted, "CreateMissingTables" is trying to read that field, when the error occurs.

Offline

#4 2020-11-20 17:31:06

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

Re: Error accessing an external Firebird database

Has the test table a ID column?

CreateMissingTables won't create the ID column.
Because this ID column should be populated with unique ID numbers, which is not handled yet, because it does not make sense for an existing table.

New columns are generated by CreateMissingTables only if they are not primary keys.

Online

#5 2020-12-03 17:51:47

igors233
Member
Registered: 2012-09-10
Posts: 234

Re: Error accessing an external Firebird database

So you have some existing Firebird DB and you want to serve data from it though REST server?
Note that in such case I would skip altogether defining TSQLModel with existing tables and using FB as external DB. Write interface service that would connect to database (with zeos for example), get data as json and return it to client.

Offline

#6 2020-12-03 18:52:54

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

Re: Error accessing an external Firebird database

Online

#7 2020-12-04 02:39:28

Prometeus
Member
From: USA
Registered: 2020-11-20
Posts: 42

Re: Error accessing an external Firebird database

igors233 wrote:

So you have some existing Firebird DB and you want to serve data from it though REST server?
Note that in such case I would skip altogether defining TSQLModel with existing tables and using FB as external DB. Write interface service that would connect to database (with zeos for example), get data as json and return it to client.

Thank you for the suggestion. I already got my application test working as expected and using the 'standard' way with TSQLModel. I have included in my tests Mormot secure authentication and it worked too, and now I am trying to have it working with SSL. Is there a real advantage for using interface services, like more speed in the JSON response, for instance? I still didn't study this part of Mormot documentation, but anyway I am already glad about the results that I am getting. Mormot framework is the most impressive piece of code for Delphi in this area that I have seen, and I wonder why I didn't hear about it before.

Offline

#8 2020-12-04 02:40:40

Prometeus
Member
From: USA
Registered: 2020-11-20
Posts: 42

Re: Error accessing an external Firebird database


  Thank you AB, I'll take a look at it!

Offline

#9 2020-12-05 23:10:40

igors233
Member
Registered: 2012-09-10
Posts: 234

Re: Error accessing an external Firebird database

> Is there a real advantage for using interface services, like more speed in the JSON response, for instance? I still didn't study this part of Mormot

No, speed is same, I say it's easier to maintain. I've started too with SQLModel for existing FB that's used outside of my app and I've transitioned to interface based approach, following sqlmodel proved too restrictive especially since I need data from several tables.

Offline

#10 2020-12-07 16:49:37

Prometeus
Member
From: USA
Registered: 2020-11-20
Posts: 42

Re: Error accessing an external Firebird database

igors233 wrote:

No, speed is same, I say it's easier to maintain. I've started too with SQLModel for existing FB that's used outside of my app and I've transitioned to interface based approach, following sqlmodel proved too restrictive especially since I need data from several tables.

The applications use the FB database, and now it will be accessed by a mobile application as well. I am really impressed with SQLite 3 performance, and I thought about converting the FB database to it, but I am concerned about SQLite issues with simultaneous writing. I don't know SQLite well, but I am aware of its limitation when dealing with concurrency writings, so I will stick with an external database for while.

I already followed Mormot documentation about SSL, and I am trying to test it using Chrome or Firefox. Despite Chrome not liking my "Dev Certification Authority" and showing it as "Not Secure" (For Firefox it is ok), I am doing simple tests using a browser, and after that build the client-side. After the SLL all set, I am trying accessing the REST API with SSL enabled (the source above was updated):

'https://localhost:8043/root/test/1'

and I am receiving:

{
"errorCode":403,
"errorText":"Authentication Failed: Invalid signature (0)"
}

Googling a little, I found that this message is related to a problem in authenticating. However, I am setting 'aHandleUserAuthentication' to 'false', at first. 'AUTHGROUP' and 'AUTHUSER' tables were created by Mormot when I was testing authenticating without SSL (I guess that they are only used if 'aHandleUserAuthentication' is set to 'true', right?), but I want to have the REST API accessing working with SSL without authentication first, then with it.

After fixing this issue (accessing the REST API through a browser or AJAX client) can the right above input using authentication like this?

'https://localhost:8043/root/test/1?user=User&password=synopse'

Offline

#11 2020-12-07 16:53:47

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

Re: Error accessing an external Firebird database

No, the default authentication has a specific signature computed for each URI.
Check the documentation about it.

What you can do is use a JWT instead.

Online

#12 2020-12-07 17:00:27

Prometeus
Member
From: USA
Registered: 2020-11-20
Posts: 42

Re: Error accessing an external Firebird database

ab wrote:

No, the default authentication has a specific signature computed for each URI.
Check the documentation about it.

What you can do is use a JWT instead.

Thank you for the prompt answer. I think you are talking about my second question when I try to access the REST API using authentication, but my current test (using SSL) is not using authentication (I did it without SSL and it worked according to documentation), so the signature computed for a URI should not be used in this case, right? What is the cause of the "Authentication Failed: Invalid signature (0)" message?

Offline

#13 2020-12-07 17:11:48

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

Re: Error accessing an external Firebird database

There may be several explanations.
One may be that authentication is still required on the server.
Please debug your server side code.

Online

Board footer

Powered by FluxBB