"Datasource makes a circular link" exception when assign datasource to nil

The offical for ZeosLib 7.3 Report problems, ask for help, post proposals for the new version of Zeoslib 7.3/v8
Quick Info:
-We made two new drivers: odbc(raw and unicode version) and oledb
-GUID domain/field-defined support for FB
-extended error infos of Firebird
-performance ups are still in queue
In future some more feature will arrive, so stay tuned and don't hassitate to help
Post Reply
omurolmez
Fresh Boarder
Fresh Boarder
Posts: 6
Joined: 04.06.2022, 21:55

"Datasource makes a circular link" exception when assign datasource to nil

Post by omurolmez »

Hello everyone. I have a strange problem with Zeos.

In both way :
* Select "(none)" for DataSource in IDE
* ZQuery3.DataSource := nil; in code and run

I get "Datasource makes a circular link" exception in here.
{ZAbstractRODataSet.pas}procedure TZAbstractRODataset.SetDataSource(Value: TDataSource);
begin
  {$IFNDEF FPC}
  if IsLinkedTo(Value) then
  {$ELSE}
  if Value.IsLinkedTo(Self) then
  {$ENDIF}
    raise EZDatabaseError.Create(SCircularLink);
  DataLink.DataSource := Value;
end;
{datasource.inc} Function TDataSource.IsLinkedTo(ADataset: TDataSet): Boolean;

var
  DS: TDataSource;

begin
  Result:=False;
  Repeat
    DS:=aDataset.GetDataSource;
    Result:=(DS=Self);
    if Assigned(DS) then
      aDataSet := DS.DataSet
    else
      aDataSet := Nil;
  Until Result or (aDataset=Nil)
end;
ZQuery3:TZQuery SQL is empty.
Lazarus 2.2.2 Fpc 3.2.2 Zeos 7.2.14.0

---- Edit ----
Put on a datamodule
two TZQuery as ZQuery2 and ZQuery3
two TDataSource as DataSource2 and DataSource3
make these assigments by using IDE
DataSource2.DataSet :=ZQuery2;
DataSource3.DataSet :=ZQuery3;
keep both queries' SQL property empty.
Set ZQuery3.DataSource :=DataSource2 by using IDE
Set ZQuery3.DataSource :=(none) by using IDE or
ZQuery3.DataSource :=nil; by programmatically. In both way, you get the exception.
I tried same with TIBQuery components from Firebird page, I got no exception.
You do not have the required permissions to view the files attached to this post.
marsupilami
Platinum Boarder
Platinum Boarder
Posts: 1939
Joined: 17.01.2011, 14:17

Re: "Datasource makes a circular link" exception when assign datasource to nil

Post by marsupilami »

The problem should be fixed in Zeos 7.2 now too. Could you please check the current SVN version?
omurolmez
Fresh Boarder
Fresh Boarder
Posts: 6
Joined: 04.06.2022, 21:55

Re: "Datasource makes a circular link" exception when assign datasource to nil

Post by omurolmez »

Hello,

First of all, thank you for your help and very quick action.
I applied the patched version. I have two issues:

1. First issue
Should we apply same patch to ifNdef(FPC) path or not ?
I mean. Isn't it should be
  {$IFNDEF FPC}
  if Assigned(Value) and IsLinkedTo(Value) then
  {$ELSE}
  if Assigned(Value) and Value.IsLinkedTo(Self) then
  {$ENDIF}
    raise EZDatabaseError.Create(SCircularLink);
  DataLink.DataSource := Value;
rather than
  {$IFNDEF FPC}
  if IsLinkedTo(Value) then
  {$ELSE}
  if Assigned(Value) and Value.IsLinkedTo(Self) then
  {$ENDIF}
    raise EZDatabaseError.Create(SCircularLink);
  DataLink.DataSource := Value;
?

-----------------------------------

Anyway, in my environment, code goes through (define FPC)
if Assigned(Value) and Value.IsLinkedTo(Self)
and I updated minimum code for second issue.

2. Second issue:
This code runs without any exception (Did I miss something ?) !
  DataSource1.DataSet :=ZQuery1;
  DataSource2.DataSet :=ZQuery2;
  ZQuery1.DataSource :=DataSource2;
  ShowMessage('2 (I should see this)');
  ZQuery1.DataSource :=nil;
  ShowMessage('3 (I should see this)');
  ZQuery1.DataSource :=DataSource1;
  ShowMessage('4 (I shoud not see this)');
You do not have the required permissions to view the files attached to this post.
marsupilami
Platinum Boarder
Platinum Boarder
Posts: 1939
Joined: 17.01.2011, 14:17

Re: "Datasource makes a circular link" exception when assign datasource to nil

Post by marsupilami »

omurolmez wrote: 03.08.2022, 19:23 First of all, thank you for your help and very quick action.
1. First issue
Should we apply same patch to ifNdef(FPC) path or not ?
No - it isn't fixed like this in FPC 8.0. So it most probably isn't necessary.
omurolmez wrote: 03.08.2022, 19:23 2. Second issue:
This code runs without any exception (Did I miss something ?) !

Code: Select all

  DataSource1.DataSet :=ZQuery1;
  DataSource2.DataSet :=ZQuery2;
  ZQuery1.DataSource :=DataSource2;
  ShowMessage('2 (I should see this)');
  ZQuery1.DataSource :=nil;
  ShowMessage('3 (I should see this)');
  ZQuery1.DataSource :=DataSource1;
  ShowMessage('4 (I shoud not see this)');
Honestly I have no clue. I will have to check it as soon as I have time.
Nenunikat
Fresh Boarder
Fresh Boarder
Posts: 1
Joined: 11.02.2023, 10:29

Re: "Datasource makes a circular link" exception when assign datasource to nil

Post by Nenunikat »

(Sorry on my english.)

I have also a problem with "Datasource makes a circular link" - but with ZTable1.MasterSource.

I have a similar problem, but with MasterSource.
When I assign the value nil to MasterSource, I also get the error message "Datasource makes a circular link".
I did not have this problem under Lazarus 2.06 with FPC 3.0.4 yet.
The reason seems to be a change from FPC 3.0.4 to FPC 3.2.2.

Error example:

Code: Select all

...
DataModule1.ZTable2.Active := false;
DataModule1.ZTable2.FilterOptions := [foCaseInsensitive];
DataModule1.ZTable2.Filter := 'BEREICH = 1 and BEREICHSID = 0';
DataModule1.ZTable2.Filtered := true;
DataModule1.ZTable2.MasterSource := nil;
DataModule1.ZTable2.LinkedFields := 'BNUMMER';
DataModule1.ZTable2.MasterFields := 'MNUMMER';
DataModule1.ZTable2.MasterSource := DataModule1.DataSource1;
DataModule1.ZTable2.Active := true;
...
The error occurs with
DataModule1.ZTable2.MasterSource := nil;

It works with:
X:\Users\Username\AppData\Local\lazarus\onlinepackagemanager\packages\zeosdbo\src\component\zabstractrodataset.pas

Code: Select all

...
procedure TZAbstractRODataset.SetMasterDataSource(Value: TDataSource);
begin
  {$IFNDEF FPC}
  if IsLinkedTo(Value) then
  {$ELSE}
  if Value.IsLinkedTo(Self) then
  {$ENDIF}
    raise EZDatabaseError.Create(SCircularLink);
  MasterLink.DataSource := Value;
  RereadRows;
end
...
In the TZAbstractRODataset.SetMasterDataSource function the IsLinkedTo() function is used.
Up to version FPC 3.0.4 this function had the following content:

Code: Select all

Function TDataSource.IsLinkedTo(ADataset: TDataSet): Boolean;

begin

 Result:=False;

end;
In the current version FPC 3.2.2 it has the following content:

Code: Select all

Function TDataSource.IsLinkedTo(ADataset: TDataSet): Boolean;

var
  DS: TDataSource;

begin
  Result:=False;
  Repeat
    DS:=aDataSet.GetDataSource;
    Result:=(DS=Self);
    if Assigned(DS) then
      aDataSet := DS.DataSet
    else
      aDataSet := Nil;
  Until Result or (aDataSet=Nil)
end;
On the one hand, we work here partly with aDataSet and partly with ADataSet. (Which should not lead to an error with Pascal, because without distinction between upper and lower case).
On the other hand, another - still largely empty - function GetDataSource is referred to:

Code: Select all

function TDataSet.GetDataSource: TDataSource;
begin
  Result:=nil;
end;
The IsLinkedTo() function does not work properly in the context of assigning the value nil and leaves any assignment like
DataModule1.ZTable1.MasterSource := nil; result in the above error.

In the meantime I'm thinking about recompiling either zabstractrodataset.pas with deactivation of IsLinkedTo() or working with a copy of ZTable1 (without assignment to MasterSource). However, this results in a lot of unnecessary resources and instructions.

Is it not better here to skip or replace IsLinkedTo() until it works in FPC?
marsupilami
Platinum Boarder
Platinum Boarder
Posts: 1939
Joined: 17.01.2011, 14:17

Re: "Datasource makes a circular link" exception when assign datasource to nil

Post by marsupilami »

Hello Nenunikat,

this problem was fixed in the 8.0 version of Zeos but for some reason the fix didn't make it into Zeos 7.2. I fixed Zeos 7.2 in the SVN now too. The changes should be available on Github tomorrow. I am not sure when we will release a new official Zeos 7.2 version that will make it into OPM.

Basically I think this is a problem in FPC and should be reported there.

With best regards,

Jan
Post Reply