Pergunta

I am using an SQLite database in a Datasnap Client - Server scenario..To avoid using a dbnavigator to apply updates to a clientset,I was wondering if there's an alternative. Is this a good alternative ? :

procedure TForm2.ClientDataSet1AfterPost(DataSet: TDataSet);
begin
ClientDataSet1.ApplyUpdates(0);
end;

I was reasoning that after post happens when you insert or update a record so it would be a good place to insert the code to avoid using the dbnavigator for the purpose. Is this reasoning OK? An alternative option? Or is it better in case of Datasnap to use dbnavigator?

Foi útil?

Solução

It is a totaly valid approach to apply any changes immediately to the database calling ApplyUpdates inside the AfterPost event. You should do the same for AfterDelete, though.

BTW, you don't have to use the DBNavigator to call ApplyUpdates. There might be points in you program where this is suitable (e.g. FormClose).

Outras dicas

As already said, it is indeed completely valid to call TClientDataset.ApplyUpdates after posts and deletes, but have in mind that by doing that you will be increasing the roundtrips between the client and the server. In some cases, this can generate performance issues.

Particularly I prefer to let the user do many operations in a form and apply them all in a single roundtrip. In order to do this I usually have a submit or save button connected to a particular Action that is enabled when the <clientDataset>.State in [dsEdit, dsInsert] or <clientDataset>.ChangeCount>0.

It´s just a matter of preference, but it seems to me that this is a good metaphore for the user and gives him/her the chance to build a batch of operations (inserts, deletes and updates) to save in a single moment.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top