How works UPDATE SQL from MASTER-DETAIL on TClientDataSets - DELPHI XE3 DATASNAP

490 views Asked by At

I'm creating a simple Master-Detail relationship with ClientDataSets on Delphi XE3 + SqlServer. I have configured Master-Detail through DatasetField at the client application and with the property MasterSource in the Detail TUniQuery at the server application. I'm using one DataSetProvider and one DataSource.

Server Application

**Master table**
object qyREMISION_COMPRA: TUniQuery        
Connection = DMBase.BD
SQL.Strings = (SELECT R.ID_REMISION_COMPRA, R.FECHA, R.FACTURA
               FROM REMISION_COMPRA R    
               WHERE R.ID_REMISION_COMPRA =:ID_REMISION_COMPRA)

object qyREMISION_COMPRAID_REMISION_COMPRA: TIntegerField
  AutoGenerateValue = arAutoInc
  FieldName = ID_REMISION_COMPRA
end

**Detail table**
object qyREMISION_COMPRA_PRODUCTO: TUniQuery     
Connection = DMBase.BD
SQL.Strings = (SELECT RP.ID_REMISION_COMPRA_PRODUCTO, RP.ID_REMISION_COMPRA, RP.ID_PRODUCTO
               FROM REMISION_COMPRA_PRODUCTO RP
               WHERE RP.ID_REMISION_COMPRA=:ID_REMISION_COMPRA
               ORDER BY RP.ID_REMISION_COMPRA_PRODUCTO)
SQLUpdate.Strings = (UPDATE REMISION_COMPRA_PRODUCTO
                     SET ID_REMISION_COMPRA = :ID_REMISION_COMPRA, ID_PRODUCTO = :ID_PRODUCTO
                     WHERE ID_REMISION_COMPRA_PRODUCTO = :Old_ID_REMISION_COMPRA_PRODUCTO)
MasterSource = datasetREMISION_COMPRA
MasterFields = ID_REMISION_COMPRA
DetailFields = ID_REMISION_COMPRA

**DataSetProvider**
object dspREMISION_COMPRA: TDataSetProvider
DataSet = qyREMISION_COMPRA
Options = [poCascadeDeletes, poCascadeUpdates, poPropogateChanges, poUseQuoteChar] end

Client Application

**Master ClientDataSet**
object cdsREMISION_COMPRA: TClientDataSet
ProviderName = 'dspREMISION_COMPRA'
RemoteServer = dmProvs.dspCompra
object cdsREMISION_COMPRAqyREMISION_COMPRA_PRODUCTO: TDataSetField
  FieldName = 'qyREMISION_COMPRA_PRODUCTO'
end 

**Detail ClientDataSet**
object cdsREMISION_COMPRA_PRODUCTO: TClientDataSet
DataSetField = cdsREMISION_COMPRAqyREMISION_COMPRA_PRODUCTO

To save the changes to the database, I only do for the master clientdataset cdsREMISION_COMPRA.ApplyUpdates(0)

When I do an insert works perfectly, but when I do an update I have problems with triggers in the database because the aplication execute the detail first and then the update of the master table. This is normal? I'm doing something wrong?

0

There are 0 answers