View Issue Details

IDProjectCategoryView StatusLast Update
0036086FPCDatabasepublic2019-09-19 10:43
ReporterZdravko GabrovskiAssigned ToMichael Van Canneyt 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
PlatformallOSallOS Versionall
Product Version3.3.1Product Buildtrunk 
Target VersionFixed in Version3.3.1 
Summary0036086: AV on lookup field with an empty lookup dataset
DescriptionSymptoms: A TBufDataSet descendant, with a ID Field (from a database), and lookup field (NAME), which point to other TBufDataset descendant with a two fields: FID and FNAME.

When there is no data on the second dataset (empty result set), when you try to open first one, it crashes wit AV,

The reason is metghod call InternalGotoBookMark(pointer(bm)); in bufdataset.pas, line # 3859.

Bm points to a null pointer, which causes a AV.

Solution:

Just add

  if IsEmpty Then
    Exit;

at line 3851.

This will avoid crash.
Steps To ReproducePlease, check the sample project attached.
Just point IBConnection to any of your firebird databases.

TagsNo tags attached.
Fixed in Revision43034
FPCOldBugId
FPCTarget3.2.0
Attached Files
  • testlookup.lpi (2,070 bytes)
  • testlookup.lpr (391 bytes)
  • utestmain.lfm (3,438 bytes)
  • utestmain.pas (1,151 bytes)
    unit utestmain;
    
    {$mode objfpc}{$H+}
    
    interface
    
    uses
      Classes, SysUtils, IBConnection, SQLDB, DB, Forms, Controls, Graphics,
      Dialogs, DBGrids, StdCtrls;
    
    type
    
      { TForm1 }
    
      TForm1 = class(TForm)
        Button1: TButton;
        Button2: TButton;
        DataSource1: TDataSource;
        DBGrid1: TDBGrid;
        IBConnection1: TIBConnection;
        SQLQuery1: TSQLQuery;
        SQLQuery1ID: TLongintField;
        SQLQuery2: TSQLQuery;
        SQLQuery2FID: TLongintField;
        SQLQuery2FNAME: TStringField;
        SQLTransaction1: TSQLTransaction;
        StringField1: TStringField;
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
      private
    
      public
    
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.lfm}
    
    { TForm1 }
    
    procedure TForm1.Button2Click(Sender: TObject);
    begin
      SQLQuery1.Close;
      SQLQuery2.Close;
      SQLQuery2.SQL[ 2 ] := ' Where 1=1';
      SQLQuery2.Open;
      sqlQuery1.open
    
    end;
    
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      SQLQuery1.Close;
      SQLQuery2.Close;
      SQLQuery2.SQL[ 2 ] := ' Where 1=0';
      SQLQuery2.Open;
       sqlQuery1.open
    
    end;
    
    end.
    
    
    utestmain.pas (1,151 bytes)

Activities

Zdravko Gabrovski

2019-09-19 09:03

reporter  

testlookup.lpi (2,070 bytes)
testlookup.lpr (391 bytes)
utestmain.lfm (3,438 bytes)
utestmain.pas (1,151 bytes)
unit utestmain;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, IBConnection, SQLDB, DB, Forms, Controls, Graphics,
  Dialogs, DBGrids, StdCtrls;

type

  { TForm1 }

  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    DataSource1: TDataSource;
    DBGrid1: TDBGrid;
    IBConnection1: TIBConnection;
    SQLQuery1: TSQLQuery;
    SQLQuery1ID: TLongintField;
    SQLQuery2: TSQLQuery;
    SQLQuery2FID: TLongintField;
    SQLQuery2FNAME: TStringField;
    SQLTransaction1: TSQLTransaction;
    StringField1: TStringField;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private

  public

  end;

var
  Form1: TForm1;

implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.Button2Click(Sender: TObject);
begin
  SQLQuery1.Close;
  SQLQuery2.Close;
  SQLQuery2.SQL[ 2 ] := ' Where 1=1';
  SQLQuery2.Open;
  sqlQuery1.open

end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  SQLQuery1.Close;
  SQLQuery2.Close;
  SQLQuery2.SQL[ 2 ] := ' Where 1=0';
  SQLQuery2.Open;
   sqlQuery1.open

end;

end.

utestmain.pas (1,151 bytes)

Michael Van Canneyt

2019-09-19 09:36

administrator   ~0118114

Fixed as suggested, please test and close if OK.
Thanks for reporting !

Zdravko Gabrovski

2019-09-19 10:43

reporter   ~0118115

It works perfect, many thanks for the quick responce!!

Issue History

Date Modified Username Field Change
2019-09-19 09:03 Zdravko Gabrovski New Issue
2019-09-19 09:03 Zdravko Gabrovski File Added: testlookup.lpi
2019-09-19 09:03 Zdravko Gabrovski File Added: testlookup.lpr
2019-09-19 09:03 Zdravko Gabrovski File Added: utestmain.lfm
2019-09-19 09:03 Zdravko Gabrovski File Added: utestmain.pas
2019-09-19 09:36 Michael Van Canneyt Assigned To => Michael Van Canneyt
2019-09-19 09:36 Michael Van Canneyt Status new => resolved
2019-09-19 09:36 Michael Van Canneyt Resolution open => fixed
2019-09-19 09:36 Michael Van Canneyt Fixed in Version => 3.3.1
2019-09-19 09:36 Michael Van Canneyt Fixed in Revision => 43034
2019-09-19 09:36 Michael Van Canneyt FPCTarget => 3.2.0
2019-09-19 09:36 Michael Van Canneyt Note Added: 0118114
2019-09-19 10:43 Zdravko Gabrovski Status resolved => closed
2019-09-19 10:43 Zdravko Gabrovski Note Added: 0118115