#1 2013-05-14 02:01:39

warleyalex
Member
From: Sete Lagoas-MG, Brasil
Registered: 2013-01-20
Posts: 250

Iterate through all properties of TSQLSampleRecord

DBGrid with mORMot

In my little experiment with mORMot and RAD aproach, the easiest way to load data into DBGrid is using TSQLTableToDataSet. I would like to update the grid remotely using BatchUpdate. I can both insert and delete in the DBGrid and write back to database, but I would like to perform updates only modified data. The idea is put dataset Delta back to TSQLRecord class. But how?

a) Static BatchUpdate

  Rec := TSQLSampleRecord.Create;
  Rec.Question := 'My Question';
  Rec.Address_ := 'My Address is 123';
  Rec.postalCode := '1234AA';
  Rec.City := 'warleyalex';

b) Dynamic BatchUpdate
The idea is iterate through the fieldnames and finds out which one is null. If it finds no column which is null, it returns empty string. And assign modified data to TSQLRecord.

Is it possible to:

- iterate through the fields (loop thru all properties of TSQLSampleRecord) and assign each property to the other property, something like:

Rec.RecordProps.Fields.Items[i].Name := DeltaDS.Fields[i].Value;
   or
Rec.Fields[i] := DeltaDS.Fields[i].Value;
   or
Rec.getFieldNames(Rec.RecordProps.Fields.Items[i].Name)  := DeltaDS.Fields[i].Value;

I can't find one method to realize it.

Offline

#2 2013-05-14 10:03:30

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

Re: Iterate through all properties of TSQLSampleRecord

Yes, TSQLTableToDataSet is read-only, from the mORMot point of view.

Your request sounds like the corresponding "BriefCase" item in the roadmap.

Offline

#3 2013-05-15 20:48:22

warleyalex
Member
From: Sete Lagoas-MG, Brasil
Registered: 2013-01-20
Posts: 250

Re: Iterate through all properties of TSQLSampleRecord

Hi, Thank you for replying.
In a DBGrid, a row where:

ID      Question            Address             PostalCode
--------------------------------------------------------------------
100     This is a question  My Address is 123    60500 

I would like to update the published property "Address" and preserve unmodified data.
Rec.Address_ = 'My Address is not 123';

If I perform the batch Updates, NULL are added for others published properties.

ID      Question     Address                PostalCode
---------------------------------------------------------
100                  My Address is not 123    

Any idea to change this default behavior?

Offline

#4 2013-05-16 08:01:35

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

Re: Iterate through all properties of TSQLSampleRecord

You have to use a FillPrepare() to retrieve the list and specify the corresponding fields in aCustomFieldsCSV optional parameter.

    ...
      - aCustomFieldsCSV can be used to specify which fields must be retrieved
        (default is to retrieve all table fields, but you may need to access only
        one or several fields, and will save remote bandwidth by specifying the
        needed fields): notice that you should not use this optional parameter
        if you want to Update the retrieved record content later, since the
        missing fields will be left with previous values - but BatchUpdate() will
        set only ID, TModTime and mapped fields }
    constructor CreateAndFillPrepare(aClient: TSQLRest; const aSQLWhere: RawUTF8;
      const aCustomFieldsCSV: RawUTF8=''); overload;

Then BatchUpdate() will call TSQLRecordFill.SetMappedFieldsExpandedJSONWriter() to only send the updated fields.

Offline

Board footer

Powered by FluxBB