View Issue Details

IDProjectCategoryView StatusLast Update
0036089FPCDatabasepublic2019-09-20 10:40
ReporterZdravko GabrovskiAssigned ToMichael Van Canneyt 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
PlatformallOSallOS Versionall
Product Version3.3.1Product Buildtrunk 
Target VersionFixed in Version3.3.1 
Summary0036089: AV on TCustomSQLQuery.InternalInitFieldDefs
DescriptionWhen I try to add a fields to a TSQLQuery object, that is NOT OPEN(Active=false) inside Lazarus IDE with fields collection editor (see attached .png files), I received a AV exception.
This cause IDE to crash and need to restart. The Only way to add a fields is to check "Actibe=true" before start a collection editor.
After deep investigation and debug I found, that the problem comes from InternalInitFieldDefs method (sqldb.pp, line 3063), because the funcion call result "Cursor" called at line 3070 SQLConnection.AddFieldDefs(Cursor,FieldDefs); return an empty value (nil).
It takes a TCustomSQLStatement FStatement Cursor variable, which is not initializied if TSQQuery obkect is not activated (Active=true).
I did the following fix:
At line 3070 in sqldb.pp I insert a code
    if Not Assigned (Cursor) Then
      FStatement.Prepare;

Which prepares a statment and allocate cursor.
This avoid AV message and IDE crash.


Steps To ReproduceAs described above.
To simulate, please use attached project, use the "Test Update List" button.
Please, point a TIBconnection to your favor firebird server and fb database.
TagsNo tags attached.
Fixed in Revision43037
FPCOldBugId
FPCTarget4.0.0
Attached Files
  • lazscreen.png (206,556 bytes)
    lazscreen.png (206,556 bytes)
  • lazscreen1.png (18,812 bytes)
    lazscreen1.png (18,812 bytes)
  • testlookup.lpi (2,070 bytes)
  • testlookup.lpr (391 bytes)
  • utestmain.lfm (3,823 bytes)
  • utestmain.pas (1,467 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;
        Button3: TButton;
        Button4: 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);
        procedure Button3Click(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.Button3Click(Sender: TObject);
    begin
      if Sender=Button4 then
        SQLQuery1.open;
      SQLQuery1.FieldDefs.Update;
      SQLQuery1.Close;
      SQLTransaction1.Active := False;
      IBConnection1.Close;
    
    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,467 bytes)

Activities

Zdravko Gabrovski

2019-09-19 20:00

reporter  

lazscreen.png (206,556 bytes)
lazscreen.png (206,556 bytes)
lazscreen1.png (18,812 bytes)
lazscreen1.png (18,812 bytes)
testlookup.lpi (2,070 bytes)
testlookup.lpr (391 bytes)
utestmain.lfm (3,823 bytes)
utestmain.pas (1,467 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;
    Button3: TButton;
    Button4: 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);
    procedure Button3Click(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.Button3Click(Sender: TObject);
begin
  if Sender=Button4 then
    SQLQuery1.open;
  SQLQuery1.FieldDefs.Update;
  SQLQuery1.Close;
  SQLTransaction1.Active := False;
  IBConnection1.Close;

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,467 bytes)

Michael Van Canneyt

2019-09-20 10:34

administrator   ~0118133

This was fixed by another means, see rev r43037.

Zdravko Gabrovski

2019-09-20 10:40

reporter   ~0118134

It works fine, thanks for a great work!

Issue History

Date Modified Username Field Change
2019-09-19 20:00 Zdravko Gabrovski New Issue
2019-09-19 20:00 Zdravko Gabrovski File Added: lazscreen.png
2019-09-19 20:00 Zdravko Gabrovski File Added: lazscreen1.png
2019-09-19 20:00 Zdravko Gabrovski File Added: testlookup.lpi
2019-09-19 20:00 Zdravko Gabrovski File Added: testlookup.lpr
2019-09-19 20:00 Zdravko Gabrovski File Added: utestmain.lfm
2019-09-19 20:00 Zdravko Gabrovski File Added: utestmain.pas
2019-09-19 23:28 Michael Van Canneyt Assigned To => Michael Van Canneyt
2019-09-19 23:28 Michael Van Canneyt Status new => assigned
2019-09-20 10:34 Michael Van Canneyt Status assigned => resolved
2019-09-20 10:34 Michael Van Canneyt Resolution open => fixed
2019-09-20 10:34 Michael Van Canneyt Fixed in Version => 3.3.1
2019-09-20 10:34 Michael Van Canneyt Fixed in Revision => 43037
2019-09-20 10:34 Michael Van Canneyt FPCTarget => 4.0.0
2019-09-20 10:34 Michael Van Canneyt Note Added: 0118133
2019-09-20 10:40 Zdravko Gabrovski Status resolved => closed
2019-09-20 10:40 Zdravko Gabrovski Note Added: 0118134