1. Important Notice: ALWAYS login to your account using Board4all.biz - we do not own or run any other websites so please make sure you are connected to our official domain, and that you see the secure connection padlock before entering your login details.

FireDAC Error Master-Detail with CachedUpdates

Discussion in 'HelpDesk' started by adrianoquintino, Nov 27, 2017.

  1. ad

    adrianoquintino Registered User

    Joined:
    Apr 24, 2014
    Messages:
    15
    Likes Received:
    242
    Hi,

    I'm using Delphi Tokyo up1 and I have a problem in the master-detail with cachedupdate.

    After Append master table, I append and post detail table in cachedupdate and after terminate this, I execute applyupdates in master and detail tables, but details itens erase.

    How solve this ?

    Thanks
     
  2. ap

    apol_guerra Registered User

    Joined:
    Jun 16, 2011
    Messages:
    48
    Likes Received:
    56
    Temporary soluction for this problem in cached updates as described in the Embarcadero Quality Portal

    in RSP-16574:

    I have set an example to make it easier to understand.

    1) Delete the Subdetail Dataset records.

    2) Without applying the updates, go to the registry 2 of the Detail Dataset.
    3) Without applying the updates, return to record 1 of the Detail Dataset. All the erased log returned.
    4º) If you apply the updates and give a refresh, the records have disappeared.
    Example:

    https://www.dropbox.com/s/5yx29zbds7gc43s/MD%20CombinedMode.rar?dl=1

    and in RSP-16247 , is described a temporary solution for the case - Change the procedure CheckDetailRecords:

    The unit FireDAC.Comp.DataSet.pas, exising in the C:\Program Files (x86)\Embarcadero\Studio\17.0\source\data\firedac
    folder which must be changed as shown below and included in your project to be compiled


    Code:
    procedure TFDDataSet.CheckDetailRecords(AEnforce: Boolean);
    
    function HasDeleted: Boolean; //Added
    begin //Added
    FilterChanges := [rtDeleted]; //Added
    Result := (RecordCount > 0); //Added
    FilterChanges := [rtUnmodified, rtModified, rtInserted]; //Added
    end; //Added
    
    function FetchDetails(AAll: Boolean): Boolean;
    begin
    Result := False;
    if DoIsSourceOnline and (
    DoMasterParamDependent(FMasterLink.Fields) and
    DoMasterParamChanged(FMasterLink.Fields) or
    ((FTable = nil) or (FTable.Rows.Count = 0))
    ) then begin
    if not (fiDetails in FetchOptions.Cache) then
    DoClearBeforeRefetch;
    DoCloseSource;
    DoMasterParamSetValues(FMasterLink.Fields);
    FSourceEOF := False;
    FUnidirRecsPurged := 0;
    FRecordCount := -1;
    DoOpenSource(True, False, (FTable = nil) or (FTable.Columns.Count = 0));
    InternalFetchRows(AAll, False);
    Result := True;
    end;
    end;
    
    var
    lChanged: Boolean;
    begin
    lChanged := False;
    if DataSetField = nil then begin
    if AEnforce or
    not MasterSource.DataSet.IsEmpty and
    not (MasterSource.DataSet.State in [dsInsert, dsSetKey]) then begin
    if fiDetails in FetchOptions.Cache then begin
    if not Active or (FSourceView = nil) or ((FSourceView.Rows.Count = 0) and (not HasDeleted)) then //Modified

    attention:
    That workaround seems to try to solve the case when you have deleted recors, but the problem also exists if some master records have no details since the beginning. I think that maybe Firedac could need a property like RecordsAlreadyRecovered to avoid trying to recover the same data repeatedly.
     
    Last edited: Jan 11, 2018
    adrianoquintino likes this.
  3. ad

    adrianoquintino Registered User

    Joined:
    Apr 24, 2014
    Messages:
    15
    Likes Received:
    242


    Thank you very much apol_guerra, your solution is very good, but my problem is too when append more that one record to detail and applyupdate using TFDSchemaAdapter without information in IndexFieldNames property in the tables Details and subDetails
     
    Last edited: Jan 13, 2018
    CyberKnight likes this.