You are not logged in.
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
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
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