#1 2023-10-18 13:32:24

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 430

exception in Torm.GetJsonValues

I am trying to use the following code:
var b:boolean=true;
bi:TFieldBits=ALL_FIELDS;
ee:TormMyclass
begin
ee.GetJsonValues(true,b,bi);


I am getting exception in TResultsWriter.AddColumns(aKnownRowsCount: integer);
in line 2824:
      len := PStrLen(PAnsiChar(c^) - _STRLEN)^; // ColNames[] <> ''
Colnames is:
('"RowID":', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 'yid', 'erid', 'dat', 'rid', 'xxID', 'typ', 'person', 'sim', 'pd', 'uvd', 'aym', 'ser', 'endata', 'uFdata', 'user')


Thank you in advance

Offline

#2 2023-10-18 14:54:58

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

Re: exception in Torm.GetJsonValues

Too many fields. You have to define MAX_SQLFIELDS_128.

With best regards
Thomas

Offline

#3 2023-10-18 15:01:33

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 430

Re: exception in Torm.GetJsonValues

Empty fields are not mine.
MAX_SQLFIELDS_128 is set for other torms

Offline

#4 2023-10-19 06:18:55

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

Re: exception in Torm.GetJsonValues

It seems that the column result names are void.
Whereas they should not.

Which DB are you using?

What is the data returned by the DB when the ORM retrieved the column names?

Offline

#5 2023-10-19 07:11:53

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 430

Re: exception in Torm.GetJsonValues

Mariadb is used as database
ID, 'yid', 'erid', 'dat', 'rid', 'xxID', 'typ', 'person', 'sim', 'pd', 'uvd', 'aym', 'ser', 'endata', 'uFdata', 'user' are correctly the published TormMyclass's properties, the same for table's fields
the ee object has ok its data resulting from a Torm.retrieve
I believe the problem is in mormot.orm.base TOrmPropertiesAbstract.SetJsonWriterColumnNames(W: TOrmWriter;  KnownRowsCount: integer);
n := ord(W.withID); produces a n with value 64

Offline

#6 2023-10-19 07:16:36

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 430

Re: exception in Torm.GetJsonValues

procedure TOrmPropertiesAbstract.SetJsonWriterColumnNames(W: TOrmWriter;  KnownRowsCount: integer);
var
  i, n, nf: PtrInt;
begin
  // set col names
  nf := Length(W.Fields);  -->15
  n := ord(W.withID);   -->64
  SetLength(W.ColNames, nf + n); 
  if W.withID then
    W.ColNames[0] := ROWID_TXT; // works for both normal and FTS3 records
  for i := 0 to nf - 1 do   -->
  begin
    W.ColNames[n] := Fields.List[W.Fields[i]].Name;
    inc(n);
  end;
  // write or init field names for appropriate JSON Expand
  W.AddColumns(KnownRowsCount);  -->KnownRowsCount=0
end;

At the end n=79
I have above the values, the variables get

Offline

#7 2023-10-19 18:04:23

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 430

Re: exception in Torm.GetJsonValues

Changing
n := ord(W.withID);
to
n := ord(integer(W.withID)<>0);
works OK

Delphi 11.3 32bit

Offline

#8 2023-10-20 08:24:32

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 430

Re: exception in Torm.GetJsonValues

The problem was finally in my code. The provided variable b content was the problem
Apologies for the trouble

Last edited by dcoun (2023-10-20 08:49:43)

Offline

#9 2023-10-20 13:37:17

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

Re: exception in Torm.GetJsonValues

dcoun wrote:

The problem was finally in my code. The provided variable b content was the problem
Apologies for the trouble

Can you please describe exactly what you did wrong and how you solved it, so that other readers can find a solution here if they have the same problem. You can also learn from mistakes and you don't have to make them all yourself. I have no idea what exactly went wrong for you.

With best regards
Thomas

Offline

#10 2023-10-20 14:34:15

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 430

Re: exception in Torm.GetJsonValues

Sure, it was very stupid of myself
b is a local variable inside a rest function. b is used in a TOrmmyclass.OrmProps.FieldBitsFromCsv(bity,bi,b) to set what fields will be retrieved.
In one special case inside the algorithm b was not initialized and for a reason I can not understand all the times the function was used, it got the value 64.
The above value as boolean was shown as true and only if you try to transform it to integer, this value is shown
Finding this case's missing initialization, and set the initial value to true, it was fixed.

Offline

#11 2023-10-20 19:21:54

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

Re: exception in Torm.GetJsonValues

Even if the problem rooted in your code, the framework should be able to manage wrong input.

See https://github.com/synopse/mORMot2/commit/ca8e4b08

Offline

Board footer

Powered by FluxBB