#1 Re: mORMot 1 » JsonGet and ID field problem on MariaDB(Firedac) » 2020-11-19 08:09:00

Thank you, with RowID it works as expected on both databases.

I should know its not a bug but only lack of my knowledge sad .

#2 mORMot 1 » JsonGet and ID field problem on MariaDB(Firedac) » 2020-11-18 19:52:07

BostjanZ
Replies: 2

Hello,

I'm trying to build a concept in which I could switch between SQLite and MySQL storage just with parameter and for standard fields everything works ok, but I have field Data which contains JSON object with some properties, which I would like to read separatly by internal parameters.

Model is defined like this:

TSQLTestTable = class(TSQLRecord)
    private
      FName:RawUTF8;
      FData:variant;
    published
      property Name:RawUTF8 read FName write FName;
      property Data:variant read FData write FData;
  end;

One record for test contains this content in Data field:

{"Param":{"Serial":"123abc"}}

I list records with:

var Table:TSQLTable;
     TmpFields:RawUTF8;
begin
  TmpFields:='ID,JsonGet(Data,'+QuotedStr('Param.Serial')+') as '+QuotedStr('Param.Serial');
  Table:=Database.MultiFieldValues(TSQLTestTable,TmpFields,'');
end;

When I use this code on SQLite database it works ok, but when I run the same code connected to MariaDB I get error:

exception class ESQLite3Exception with message 'Error SQLITE_ERROR (1) [SELECT ID, JsonGet(Data,'Param.Serial') as 'Param.Serial' FROM TestTable] using 3.33.0 - no such column: ID, extended_errcode=1

Problem is only with ID field. If I replace 'ID' with 'Name' which is also in model everything works ok.

I need ID field in result for record references, but I don't know if this is some kind of bug or limitation ?

Thank you for any info.

#3 Re: mORMot 1 » TDynArray.SaveToJSON bug ? » 2019-02-21 16:08:04

Thank you for your answer !

I solved my problem by changing record definiton, but since it was a simple case and I already wanted to try how custom serializer works, based on GutHub example (section 10.1.3.2.4. Text-based definition from SAD), I added this before SaveToJSON:

  TTextWriter.RegisterCustomJSONSerializerFromText(TypeInfo(TPosition),'FieldId integer Width integer');
  TmpJSON:=DAPositions.SaveToJSON();

but results were the same: [214748364801,644245094402].

I also tried:

'{FieldId integer Width integer}'; //error with registering

and

'A: record FieldId, Width: integer;'; //result: '[214748364801,644245094402]'

Is it required to register record (TPosition) or array serialization (TPositions) ?

#4 mORMot 1 » TDynArray.SaveToJSON bug ? » 2019-02-19 15:45:32

BostjanZ
Replies: 3

Hi,

I have found some strange behaviour with TDynArray conversion to JSON (or maybe I am missing something).

If I define array of record which has only integer fields in definition, conversion to JSON fails, but if I add an string to record everything works as expected.

I use XE6 and tested it also with 10.2 CE (both 32bit) and results were the same, I used lastest nightlybuild of mORMot for test.

Definition for array is as such:

type
  TPosition = packed record
    FieldId:integer;
    Width: integer;
//    DummyString:string;
  end;

type TPositions = array of TPosition;

In the following procedure content of TmpJSON is used as conversion target and I have added results in comments:

procedure TForm1.Button1Click(Sender: TObject);
var fPositions:TPositions;
    DAPositions: TDynArray;
    TmpPos:TPosition;
    TmpJSON:RawUTF8;
begin
  DAPositions.Init(TypeInfo(TPositions),fPositions);
  DAPositions.Clear;
  TmpPos.FieldId:=1;
  TmpPos.Width:=50;
  //test if record to JSON is ok
  TmpJSON:=RecordSaveJSON(TmpPos, typeInfo(TPosition));
  //OK we get TmpJSON='{"FieldId":1,"Width":50}'
  DAPositions.Add(TmpPos);
  TmpPos.FieldId:=2;
  TmpPos.Width:=150;
  DAPositions.Add(TmpPos);
  //test if array to JSON is ok
  TmpJSON:=DAPositions.SaveToJSON;
  //ERROR: we get TmpJSON='[214748364801,644245094402]'
  //
  //if we add DummyString:string; to TPosition definition
  //we get correct data: TmpJSON='[{"FieldId":1,"Width":50,"DummyString":""},{"FieldId":2,"Width":150,"DummyString":""}]'
end;

Kind regards,
Bostjan

#5 Re: mORMot 1 » TSQLModel with custom data (JSON encoded) » 2018-07-25 08:03:51

Now I think I get it, thank you (have also re-read DTO part of SAD smile )

Since I am only at begining and still finding right concepts, I will for now use this approach, because it is quicker for prototyping, but later I will upgrade it so that my existing TDocVariant structure (or maybe whole default form definition) will be persisted in DB and UI form will request it through some dedicated service like any other data and then render it.

Thanks,
Bostjan

#6 Re: mORMot 1 » TSQLModel with custom data (JSON encoded) » 2018-07-24 09:56:40

Thank you for your answer,

I tried TDocVariant instance, but I don't want it to be writen to DB, but to be part of TSQLModel.
Maybe if I clarify what I want to achieve: after I read through SAD, I made a decision to transform my old RAD based app to mORMot style DDD app and as a result I have more TSQLREST-s and also TSQLModel-s for each one.
My idea was that when I define Tables layout in model, I could also add default UI properties in JSON form which could be used for UI customisation.
For example if I have fields in TSQLRecord:

TSQLTable1 = class(TSQLRecord)
Name:RawUTF8;
LastName:RawUTF8;
Status:integer;
...

If I now generate user input form from TSQLRecord definition, I get all three fields on form, but Status is field that will be managed from code, so I don't want it on form.

In my current tests I define string constant just under TSQLRecord definitions, so that things are together:

const UIDefTable1:RawUTF8= '['
                             +'{"name":"Name","visible":true,"width":"40%"},'
                             +'{"name":"Status","visible":false}'
                             +']';

To add this data to TSQLModel I inherited from TSQLModel, added new field fCustomData and made new constructor:

constructor TSQLModelMy.Create(const Tables: array of TSQLRecordClass; const aRoot: RawUTF8; CustomData: RawUTF8);
begin
  inherited Create(Tables, aRoot);
  fCustomData:=CustomData;
end;

Now when I create model I add UI data like this:

function MyModelCreate:TSQLModelMy;
var TmpCustomData:variant;
begin
  TmpCustomData:=_Arr([_Obj(['table','Table1','data',_JSON(UIDefTable1)])]);
  TmpCustomData.Add(_Obj(['table','Table2','data',_JSON(UIDefTable2)]));

  result := TSQLModelMy.Create([TSQLTable1, TSQLTable2],'root',VariantSaveJson(TmpCustomData));
end;

So when I am creating my universal data entry form I have default UI data available, regardless to which TSQLRest am I connecting it through:

tmpCustomData:=(fRESTClient.Model as TSQLModelMy).fCustomData;

It is usable, but I don't know if this correct/smartest way to accomplish this ?

Thanks,
Bostjan

#7 mORMot 1 » TSQLModel with custom data (JSON encoded) » 2018-07-23 13:49:36

BostjanZ
Replies: 6

Hi,

I am exploring mORMot features and trying to connect all things together and currently trying to build my version of UI auto generator for one record (I know there is included ribonUI, but it is not exactly what I need).

I get field info runtime with:

fRESTClient.Model.Table['testtable'].RecordProps.Fields.Items[FieldCnt].NameDisplay

but I would also like to include with model some custom default data for fields like visibility, default value, different caption,...:

const UItesttable:RawUTF8= '[{"visible":false, "default":3},{"visible":true, "default":0}]';

so I could access them like:

fRESTClient.Model.Table['testtable'].CustomData

or

fRESTClient.Model.CustomData

I guess I could make interface based service which would return this data for the model or write them in some TSQLRibbonTabParameters field, but maybe there is another more direct way for doing it ?

Thanks,
Bostjan

Board footer

Powered by FluxBB