#1 Yesterday 13:42:22

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

Error in 'CreateMissingTables' because of a certain table name

I encountered a strange SQLite error when calling 'CreateMissingTables' for a model with several tables, but the error was specific to one table. I checked for mistakes in that table's record fields declaration, but found nothing wrong. Then I realized that mORMot had created a table named 'ORDER', which I didn't have as a table with that name. The corresponding record was named 'TOrmOrder'. When I changed the name to something different, like 'TOrmOrdera' or 'TOrmAnOrder', the error disappeared. Could this be a mORMot bug?

Offline

#2 Yesterday 19:26:18

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 15,094
Website

Re: Error in 'CreateMissingTables' because of a certain table name

What is the exact SQL error and the executed SQL statement?

Offline

#3 Yesterday 20:37:44

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

Re: Error in 'CreateMissingTables' because of a certain table name

You can try the code from this gist: https://gist.github.com/PrometeusRec/68 … b04e17a1ab

The error message is: ESqlite3Exception: Error SQLITE_ERROR (1) [CREATE TABLE Order(ID INTEGER PRIMARY KEY AUTOINCREMENT, field_d TEXT COLLATE SYSTEMNOCASE, field_e FLOAT, field_f TEXT COLLATE ISO8601);] using 3.46.1 - near "Order": syntax error

This is because mORMot doesn't like the name 'TOrmOrder'. If you change this name to something else, it works

Offline

#4 Yesterday 22:15:17

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 15,094
Website

Re: Error in 'CreateMissingTables' because of a certain table name

"order" is a reserved SQL keyword  so should not be used for a table name.

Just rename the class "TOrmOrders".

Offline

#5 Yesterday 22:39:39

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

Re: Error in 'CreateMissingTables' because of a certain table name

ab wrote:

"order" is a reserved SQL keyword  so should not be used for a table name.

Just rename the class "TOrmOrders".

I just tested that it will happen with any other SQL reserved word, but only if the class name starts with 'TOrm'. I used to name all my ORM classes with 'TOrm'  + the_name_of_data, but now I'll take care with reserved SQL words. If you use 'TAbcOrder', for example, it does not raise an error.

Offline

#6 Yesterday 22:43:15

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 15,094
Website

Re: Error in 'CreateMissingTables' because of a certain table name

Yes because TAbcOrder will generate a ABCORDER table.

This is as expected and documented.

Offline

Board footer

Powered by FluxBB