#1 2025-07-21 13:42:22

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

Error in 'CreateMissingTables' because of a certain kind of 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 class 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 class was named 'TOrmOrder'. When I changed the name to something different, like 'TOrmOrdera' or 'TOrmAnOrder', the error disappeared. Could this be a mORMot bug?

Last edited by Prometeus (2025-08-01 15:59:00)

Offline

#2 2025-07-21 19:26:18

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

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

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

Offline

#3 2025-07-21 20:37:44

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

Re: Error in 'CreateMissingTables' because of a certain kind of 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 2025-07-21 22:15:17

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

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

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

Just rename the class "TOrmOrders".

Offline

#5 2025-07-21 22:39:39

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

Re: Error in 'CreateMissingTables' because of a certain kind of 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 2025-07-21 22:43:15

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

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

Yes because TAbcOrder will generate a ABCORDER table.

This is as expected and documented.

Offline

#7 2025-07-25 16:58:02

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

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

I have added an explicit check to trigger an exception sooner.

https://github.com/synopse/mORMot2/commit/07540ac1b

Offline

#8 2025-07-25 17:11:28

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

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

ab wrote:

I have added an explicit check to trigger an exception sooner.

https://github.com/synopse/mORMot2/commit/07540ac1b

Great, thanks!

Offline

Board footer

Powered by FluxBB