Page 1 of 1

TZAbstractCachedResultSet.DisposeCachedUpdates

Posted: 04.12.2014, 14:10
by fischer1983
Hello everyone,

I'm going through the following situation, I wonder if it's a problem or is it something I can change through parameter or setting.

In TZAbstractDataset.Commit method, before the Commit, runs the THack_ZAbstractDataset method (FDatasets ). DisposeCachedUpdates. This is causing me problems.

Code: Select all

procedure TZAbstractConnection.Commit;
var
  ExplicitTran: Boolean;
  i: Integer;
begin
  CheckConnected;
  CheckNonAutoCommitMode;

  ExplicitTran := FExplicitTransactionCounter > 0;
  if FExplicitTransactionCounter < 2 then
  //when 0 then AutoCommit was turned off, when 1 StartTransaction was used
  begin
    ShowSQLHourGlass;
    try
      try
        for i := 0 to FDatasets.Count -1 do
          if Assigned(FDatasets[i]) then
            if TObject(FDatasets[i]) is TZAbstractDataset then
              THack_ZAbstractDataset(FDatasets[i]).DisposeCachedUpdates;
        FConnection.Commit;
      finally
        FExplicitTransactionCounter := 0;
        if ExplicitTran then
          AutoCommit := True;
      end;
    finally
      HideSQLHourGlass;
    end;
    DoCommit;
  end
  else
    Dec(FExplicitTransactionCounter);
end;
Here's an example: I have two entries. Each has its TZQuery, one is with CachedUpdates property = True.I'm with two open entries. If I do Commit in the register that the CachedUpdates = false, and have unsaved data in TZQuery standing with CachedUpdates = True, this TZQuery to be recorded raises the exception: 0 record (s) updated. only one
record shouldnt Have Been updated. That is, the Commit method, any change that is in Cache is removed. And in my case it could not be this way.

Code: Select all

procedure TZAbstractCachedResultSet.DisposeCachedUpdates;
begin
  while FInitialRowsList.Count > 0 do
  begin
    OldRowAccessor.RowBuffer := PZRowBuffer(FInitialRowsList[0]);
    NewRowAccessor.RowBuffer := PZRowBuffer(FCurrentRowsList[0]);

    if NewRowAccessor.RowBuffer.UpdateType <> utDeleted then
    begin
      NewRowAccessor.RowBuffer.UpdateType := utUnmodified;
      if (FSelectedRow <> nil)
        and (FSelectedRow.Index = NewRowAccessor.RowBuffer.Index) then
          FSelectedRow.UpdateType := utUnmodified;
    end;

    { Remove cached rows. }
    OldRowAccessor.Dispose;
    FInitialRowsList.Delete(0);
    FCurrentRowsList.Delete(0);
  end;
end;
How could I solve this?

I am grateful for the attention of anyone who can help, and sorry for my bad English.

Re: TZAbstractCachedResultSet.DisposeCachedUpdates

Posted: 10.12.2014, 22:59
by EgonHugeist
Can you attach a template application, please?`Something to work with and a create-script would be nice!

Re: TZAbstractCachedResultSet.DisposeCachedUpdates

Posted: 11.12.2014, 16:46
by fischer1983
Hi EgonHugeist

Thank you for your attention.

Are attached to the application and Firebird database to simulate the test.

In cometary are descriptions.

Any questions I am available.

Once again thank you.

Re: TZAbstractCachedResultSet.DisposeCachedUpdates

Posted: 22.12.2014, 12:24
by fischer1983
Hi EgonHugeist,

Sorry to be upsetting, but I have any news about my problem?

Thanks for attention.

Re: TZAbstractCachedResultSet.DisposeCachedUpdates

Posted: 24.12.2014, 11:44
by EgonHugeist
@hagahood

thanks for the fix! Did apply your suggested code. Patch done R3563 /testing-7.2

To be honest:
This bug was introduced by my selves long times ago. Thinking about it a bit more .... a commit or rollback shouldn't automatically dispose the pending updates. Therefor CommitUpdates was made. So i'll change this code on 7.3. The user should decide to free the pending updates.

@fischer1983

Sorry for the delay. Actually i'm running FB3.0 and my clientlib expects another file-format. So it !was! on my todo list, but i was out of time to fix it, sorry.

Re: TZAbstractCachedResultSet.DisposeCachedUpdates

Posted: 06.01.2015, 08:42
by alexs75
Fixed error when using TZReadOnlyQuery and TZConnection.Commit

Re: TZAbstractCachedResultSet.DisposeCachedUpdates

Posted: 06.01.2015, 11:12
by fischer1983
Hello alex75.

Thanks for your reply. But did not understand what that meant using TReadOnlyQuery solve the problem, and it is read-only, not writing.

Thank you for your attention.

Re: TZAbstractCachedResultSet.DisposeCachedUpdates

Posted: 06.01.2015, 11:19
by alexs75
UpdatesPending not in TReadOnlyQuery. Therefore, an error occurs when calling. I put the test before calling. Previously the test was after the call to UpdatesPending.

Re: TZAbstractCachedResultSet.DisposeCachedUpdates

Posted: 06.01.2015, 16:31
by EgonHugeist
Thanks Alex, you are right!

Patch applied R3590 /testing-7.2 (SVN)

@fischer1983

can you please test the fixes? Propose you switch to SVN.