Recent

Author Topic: DBGrid causes Segmentation Fault  (Read 2914 times)

Paul Reeves

  • New member
  • *
  • Posts: 8
Re: DBGrid causes Segmentation Fault
« Reply #15 on: March 13, 2019, 04:05:36 pm »
If there is a circular reference between the query object and the datasource that should be caught, perhaps at design time, shouldn't it? I'm trying to imagine how that could be a feature, especially in this case when the original query takes no parameters.
It is for TSQLQuery impossible to detect if the datasource component is for results or for paramater values.

It is possible for TSQLQuery to detect a circular reference. TDataset has an 'IsLinkedTo' method. If it returns true there is a circular reference and an error should be thrown. An example of how this is done can be found in IBX2:

Code: Pascal  [Select]
  1. procedure TIBCustomDataSet.SetDataSource(Value: TDataSource);
  2. begin
  3.   if IsLinkedTo(Value) then
  4.     IBError(ibxeCircularReference, [nil]);
  5.   if FDataLink <> nil then
  6.     FDataLink.DataSource := Value;
  7. end;                              
  8.  

TSQLQuery tries to detect the circular reference, but seems to fail:

Code: Pascal  [Select]
  1. procedure TCustomSQLQuery.SetDataSource(AValue: TDataSource);
  2. Var
  3.   DS : TDataSource;
  4. begin
  5.   DS:=DataSource;
  6.   If (AValue<>DS) then
  7.     begin
  8.     If Assigned(AValue) and (AValue.Dataset=Self) then
  9.       DatabaseError(SErrCircularDataSourceReferenceNotAllowed,Self);
  10.     If Assigned(DS) then
  11.       DS.RemoveFreeNotification(Self);
  12.     FStatement.DataSource:=AValue;
  13.     end;
  14. end;


valdir.marcos

  • Hero Member
  • *****
  • Posts: 795
Re: DBGrid causes Segmentation Fault
« Reply #16 on: March 14, 2019, 07:20:31 am »
If there is a circular reference between the query object and the datasource that should be caught, perhaps at design time, shouldn't it? I'm trying to imagine how that could be a feature, especially in this case when the original query takes no parameters.
It is for TSQLQuery impossible to detect if the datasource component is for results or for paramater values.

It is possible for TSQLQuery to detect a circular reference. TDataset has an 'IsLinkedTo' method. If it returns true there is a circular reference and an error should be thrown. An example of how this is done can be found in IBX2:

Code: Pascal  [Select]
  1. procedure TIBCustomDataSet.SetDataSource(Value: TDataSource);
  2. begin
  3.   if IsLinkedTo(Value) then
  4.     IBError(ibxeCircularReference, [nil]);
  5.   if FDataLink <> nil then
  6.     FDataLink.DataSource := Value;
  7. end;

TSQLQuery tries to detect the circular reference, but seems to fail:

Code: Pascal  [Select]
  1. procedure TCustomSQLQuery.SetDataSource(AValue: TDataSource);
  2. Var
  3.   DS : TDataSource;
  4. begin
  5.   DS:=DataSource;
  6.   If (AValue<>DS) then
  7.     begin
  8.     If Assigned(AValue) and (AValue.Dataset=Self) then
  9.       DatabaseError(SErrCircularDataSourceReferenceNotAllowed,Self);
  10.     If Assigned(DS) then
  11.       DS.RemoveFreeNotification(Self);
  12.     FStatement.DataSource:=AValue;
  13.     end;
  14. end;
Paul, I've a made and attached a small example, as simple and educative as I could think of, on how to use TSQLQuery.DataSource.

I've managed to code all settings instead of using Object Inspector.

If you still believe you have found a bug, please attach another small sample with it.
« Last Edit: March 14, 2019, 02:50:41 pm by valdir.marcos »