Edit records of a clientdataset of fields coming from a join

2

I have a simple example, but in three layers, with sqldataset + datasetprovider + clientdataset. I do not load any fields in the sqldataset. In the datasetprovider I leave the updatemode in upwherekeyonly.

In the datasetprovider I leave allowcommandtext to true to be able to receive commandtext from the client side via clientdataset. On the client side I load the fields with Select * ... and during the execution time I send the commandtext with a join so that it brings only the fields already loaded. When I try to edit some registry and give the applyupdates in the onreconcileerror event I get:

Unable to Find Record. No Key especified

Use xe5 + dbexpress + mysql. The question is how do I configure the components to edit and update records from a command with join?

SUMMARY DISCUSSION

You can leave all the default delphi settings, the only thing you need to do is put the name of the table to update in the OnGetTablename event of the datasetprovider, this resolved all my problems.

    
asked by anonymous 24.02.2015 / 07:06

1 answer

2

Artur, this is because the DataSet understands that all fields belong to the same table.

To fix the problem, you should configure which fields are not table data fields, what is the key, and what table to update.

Configure the fields correctly

One way to do this is by setting the ProviderFlags / a> to empty, stating that the field should not appear in Where and should not be updated ( pfInWhere, pfInUpdate ).

CampoA.ProviderFlags := [];

Or by changing the FieldKind to < strong> fkInternalCalc .

CampoA.FieldKind := fkInternalCalc;
Another important thing is to set the primary key field to ensure that the provider correctly identifies the key to be used, and for this you must set the ProviderFlag to pfInKey

CampoChave.ProviderFlags := CampoChave.ProviderFlags + [pfInKey];

or     FieldChave.ProviderFlags: = [pfInUpdate, pfInKey];

Define the name of the table to be updated

In addition, it is recommended to implement the TDataSetProvider onGetTableName event , so that it knows in which table give update.

procedure DataSetProvider.onGetTableName(Sender: TObject);
begin
    Result := 'NomeDaTabelaASerAtualizada';
end;
    
24.02.2015 / 13:35