#1 2021-05-15 20:53:35

wxinix
Member
Registered: 2020-09-07
Posts: 121

Help! mORMot2 migration problem

I have a fairly new project in the past month using mORMot 1.18.

I tried to migrated it to mORMot 2, today, following @ab advice.

The code update was pretty smooth, and the code built fine.

Then the exception showed up, when calling TRestServerDB.CreateMissingTables:  Exception class EZSQLException with message 'SQL Error: ERROR:  relation "some_table" already exists
ERROR 42P07relation "some_table" already exists

Shouldn't CreateMissingTables only try to create tables when "missing"?  But it seemed it tried to create existing tables?

What is the catch here?

Last edited by wxinix (2021-05-15 20:55:07)

Offline

#2 2021-05-16 12:11:02

wxinix
Member
Registered: 2020-09-07
Posts: 121

Re: Help! mORMot2 migration problem

I use Postgresql connection class.  It seems that mormot.db.sql.zeos, the following  method doesn't work properly?

 procedure TSqlDBZeosConnectionProperties.GetFields(const aTableName: RawUtf8;
  out Fields: TSqlDBColumnDefineDynArray);

Line 696

res := meta.GetColumns('', sSchema,
      meta.AddEscapeCharToWildcards(sTableName), '');

always returns EMPTY, thus the returned

out Fields: TSqlDBColumnDefineDynArray 

is always empty.  On the other hand,  however, from the backend PostgreSQL server log, I can see that the server is queried with correctly generated SQL, which indeed returned the list of fields.

Because returned Fields is always empty, CreateMissingTables will always try to recreate existing tables because of the empty Fields returned.

Is this a bug of mORMot2, or I am doing something wrong somewhere?

Last edited by wxinix (2021-05-16 12:20:37)

Offline

#3 2021-05-16 13:14:20

wxinix
Member
Registered: 2020-09-07
Posts: 121

Re: Help! mORMot2 migration problem

OK.

I believe there is a bug of mORMot2

mormot.db.sql.zeos, line 694

    sTableName := meta.AddEscapeCharToWildcards(sTableName);  // <---- this line should be removed, because AddEscapeCharToWildcards is called TWICE!
    // do not escape https://synopse.info/forum/viewtopic.php?pid=34896#p34896
    res := meta.GetColumns('', sSchema,
      meta.AddEscapeCharToWildcards(sTableName), '');

Last edited by wxinix (2021-05-16 13:15:23)

Offline

#4 2021-05-17 08:57:19

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

Re: Help! mORMot2 migration problem

I have fixed TSqlDBZeosConnectionProperties.GetFields as you proposed.

About https://github.com/synopse/mORMot2/issues/33 please see my remark.
By design, GetJsonField() does not support JSON objects or arrays.
It only parses simple values.
I don't understand what is your use case of JsonToObject.
Could you please show a class definition which has problem be parsed?

Offline

Board footer

Powered by FluxBB