#1 2013-01-17 18:56:18

Roberto Schneiders
Member
From: Santa Catarina, Brazil
Registered: 2012-09-19
Posts: 127
Website

Is there something like the ClientDataSet.ApplyUpdates in mORMot?

Please do not crucify me for write the ClientDataSet word. I know that it is prohibited here smile. I have not found a better way to ask that.

I am creating a class (TcxCustomDataSource) to use DevExpress grids using mORMot ORM.

I'm using a TSQLTable (TSQLRecord.FillTable) to provide the data to the grid.

function TmORMotCustomDataSource.GetValue(ARecordHandle: TcxDataRecordHandle;
  AItemHandle: TcxDataItemHandle): Variant;
begin
  Result := Table.GetVariant(Integer(ARecordHandle)+1, Integer(AItemHandle), self);
end;

When information is changed on the grid I make changes in the database (Client.Update) and then I use the command Client.UpdateFromServer to update the grid.
This is the code:

procedure TmORMotCustomDataSource.SetValue(ARecordHandle: TcxDataRecordHandle; AItemHandle: TcxDataItemHandle;
  const AValue: Variant);
var
  ARecord: TSQLRecord;
  Changed: Boolean;
begin
  inherited;

  ARecord := FRecord.Create;
  FRecord.FillRow(Integer(ARecordHandle)+1, ARecord); // FRecord is a TSQLRecord (a list of People) created by CreateAndFillPrepare
  aRecord.SetFieldVariant(Table.GetS(0, Integer(AItemHandle)) ,AValue);
  FClient.Update(ARecord);

  fClient.UpdateFromServer([FRecord.FillTable],Changed, Pointer(Integer(ARecordHandle)+1));

  Self.DataChanged; // This make the grid reload all information
end;

This works perfectly, but I need to work differently in some cases.

This way, when some information is changed in the Grid, it is immediately applied to the database.

I need to have the option to only apply changes to the database later. Trough a Save button, usually.

With DBExpress did this by placing the ApplyUpdates on the Save button. How I do this using mORMot?

Last edited by Roberto Schneiders (2013-01-17 18:57:14)

Offline

#2 2013-01-17 19:10:43

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

Re: Is there something like the ClientDataSet.ApplyUpdates in mORMot?

By using a BATCH client sequence?

Offline

#3 2013-01-17 19:16:05

Roberto Schneiders
Member
From: Santa Catarina, Brazil
Registered: 2012-09-19
Posts: 127
Website

Re: Is there something like the ClientDataSet.ApplyUpdates in mORMot?

If I use BATCH. When running the UpdateFromServer command he will return the changed data? Because the grid must contain the changes.

Offline

#4 2013-01-17 19:22:01

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

Re: Is there something like the ClientDataSet.ApplyUpdates in mORMot?

You have to make the changes locally, since BATCH process is just a client-side JSON buffer containing all data to be sent to the server.

The easiest is to maintain a list of RawUTF8 buffers for the modified values, and update the PUTF8Char pointers in the TSQLTable array.

Then BatchSend() will commit everything to the server, and you will call UpdateFromServer() after the commit.

Offline

#5 2013-01-17 19:29:22

Roberto Schneiders
Member
From: Santa Catarina, Brazil
Registered: 2012-09-19
Posts: 127
Website

Re: Is there something like the ClientDataSet.ApplyUpdates in mORMot?

I do not know if I understand correctly.

From what I know the TSQLTable is readonly, right?
I do not understand exactly what you mean by "update the PUTF8Char pointers in the TSQLTable array".  You mean simply overwrite the existing records pointers? If I need to add a new record?

Had some example?

Thanks Arnaud.

Offline

#6 2013-01-18 15:35:00

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

Re: Is there something like the ClientDataSet.ApplyUpdates in mORMot?

Adding a new record will need to add some PUTF8Char pointers.

It should better be implemented as standard in TSQLTable class itself, I suppose.
There is an item in the roadmap explicitly about this feature request.

Offline

Board footer

Powered by FluxBB