#1 2021-05-08 08:59:34

tbo
Member
Registered: 2015-04-20
Posts: 339

mORMot2 Error: TOrm... has too many fields

mORMot2 (GitHub commit 1341), SQLite, Delphi 10.4.2 with all patches

I create an ORM object with 29 published properties. When I start the server the database is not created. But no error message is displayed in the console. When I access the database for the first time, the following error message is displayed:

EModelException {Message:"TOrmArticle has too many fields: 67>=64"}

If I comment out a published property, everything works without problems. There are then 29 fields in the created database. The 28 published properties and the ID field. If I exceed 28 published properties and this also applies to other objects, the error occurs again. When I turn on the definition MAX_SQLFIELDS_128, it also runs with 29 properties. But the description says 64 fields as default.

/// maximum number of fields in a database Table
// - default is 64,

Can anyone else reproduce this behavior?

With best regards
Thomas

Offline

#2 2021-05-10 09:22:16

tbo
Member
Registered: 2015-04-20
Posts: 339

Re: mORMot2 Error: TOrm... has too many fields

I think I have found the error why mORMOt2 does not work. You can understand it very easily with example 04-InterfacedBasedServices by Martin Doyle.

I have made the following changes: First change the server to useHttpSocket. If you change the ORM object as follows it works as expected. Create published properties from Test4 to Test63.

TOrmCustomSample = class(TOrm)
private
  FName: RawUTF8;
  FQuestion: RawUTF8;
  FTime: TModTime;
  FTest: RawUtf8;
published
  property Name: RawUTF8 read FName write FName;
  property Question: RawUTF8 read FQuestion write FQuestion;
  property Time: TModTime read FTime write FTime;
  property Test4: RawUtf8 read FTest write FTest;
  property Test5: RawUtf8 read FTest write FTest;
  ...
  property Test62: RawUtf8 read FTest write FTest;
  property Test63: RawUtf8 read FTest write FTest;
end;

But when you derive the ORM object, you always have to subtract the published properties from the previous objects that it still works.

TOrmCustomSample = class(TOrm)
private
  FName: RawUTF8;
  FQuestion: RawUTF8;
  FTime: TModTime;
published
  property Name: RawUTF8 read FName write FName;
  property Question: RawUTF8 read FQuestion write FQuestion;
  property Time: TModTime read FTime write FTime;
end;

TOrmSample = class(TOrmCustomSample)
private
  FTest: RawUtf8;
published
  property Test4: RawUtf8 read FTest write FTest;
  property Test5: RawUtf8 read FTest write FTest;
  ...
  property Test59: RawUtf8 read FTest write FTest;
  property Test60: RawUtf8 read FTest write FTest;
end;  

In this case, you can only use up to property Test60, with more it crashes.

I have a deeply branched object structure in my program, so I can only use 28 properties. I have not read this behavior yet. Have I missed something so far?

With best regards
Thomas

Last edited by tbo (2021-05-10 09:25:06)

Offline

#3 2021-05-10 09:33:54

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

Re: mORMot2 Error: TOrm... has too many fields

Perhaps there was some trouble with the ClassFieldCountWithParents() function.

I have just used a slower but perhaps safer version - this function is seldom used, so here performance is not mandatory.

Offline

#4 2021-05-10 10:03:55

tbo
Member
Registered: 2015-04-20
Posts: 339

Re: mORMot2 Error: TOrm... has too many fields

ab wrote:

Perhaps there was some trouble with the ClassFieldCountWithParents() function.

In both the test and my program, the fix worked. WOW. The fix was available so quickly. I wasn't even sure if I described the bug precisely enough, already it was fixed. Thank you so much for this.

With best regards
Thomas

Offline

Board footer

Powered by FluxBB