#1 2025-11-21 16:21:20

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

Obtaining the correct Type of Field from JSON data

Let's suppose we have the following types:

type ENum01 = (val_01, val_02, val_03);
     ENum02 = (val_04, val_05, val_06);

     TOrmOneClass = class(TOrm)
       private
         Ffield_01 : Integer;
         Ffield_02 : TDateTime;
         Ffield_03 : TDateTime;
         Ffield_04 : RawUtf8;
         Ffield_05 : TEnum01;
         Ffield_06 : TEnum02;
       published
         property field_01 : Integer read Ffield_01 write Ffield_01;
         ...
    end; 

So, after mORMot creates all SQLite fields, I can see, using 'SQLiteStudio' the 'OrmOneClass' table with the following types:
   

      ID       : INTEGER;
      field_01 : INTEGER;
      field_02 : TEXT;
      field_03 : TEXT;
      field_04 : TEXT;
      field_05 : INTEGER;
      field_06 : INTEGER; 

         
In some part of my system I need to obtain the field types using the following code:

var ADataSet : TOrmTableDataSet; 
    JsonData : RawUtf8;
    count    : Integer;	 

ADataSet := TOrmTableDataSet.CreateFromJson(nil, JSonData); 

If I check the type of each field of 'ADataSet' with 'ADataSet.Fields[count].DataType', I have the following results:

      ID       : ftLargeInt;
      field_01 : ftWideString;
      field_02 : ftWideString;
      field_03 : ftWideString;
      field_04 : ftWideString;
      field_05 : ftWideString;
      field_06 : ftWideString;

'ID' is as expected, but:

1) Why do ALL other fields become 'ftWideString'?

2) What is the proper way to obtain the correct field types of a 'TOrmTableDataSet' created from JSON?

Last edited by Prometeus (2025-11-21 16:48:42)

Offline

#2 2025-11-21 17:08:01

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

Re: Obtaining the correct Type of Field from JSON data

My guess is that your JSON data, as supplied to TOrmTableDataSet, is incorrect.

BTW which version of Delphi are you using?

Offline

#3 2025-11-21 17:36:43

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

Re: Obtaining the correct Type of Field from JSON data

ab wrote:

BTW which version of Delphi are you using?

Delphi 13

Last edited by Prometeus (2025-11-22 13:31:40)

Offline

Board footer

Powered by FluxBB