Recent

Author Topic: External: SIGSEGV while closing an application (debugging)  (Read 5509 times)

wht244

  • Jr. Member
  • **
  • Posts: 79
External: SIGSEGV while closing an application (debugging)
« on: July 06, 2010, 10:08:21 am »
i have code:
Quote
unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, OracleConnection, sqldb, FileUtil, LResources, Forms,
  Controls, Graphics, Dialogs, StdCtrls, Spin;

type

  { TForm1 }

  TForm1 = class(TForm)
    ApplicationProperties1: TApplicationProperties;
    btnPolacz: TButton;
    btnAnuluj: TButton;
    edtAdres: TEdit;
    edtUser: TEdit;
    edtHaslo: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    conn: TOracleConnection;
    sql: TSQLQuery;
    transaction: TSQLTransaction;
    procedure ApplicationProperties1Exception(Sender: TObject; E: Exception);
    procedure btnAnulujClick(Sender: TObject);
    procedure btnPolaczClick(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  Form1: TForm1;

implementation

{ TForm1 }

procedure TForm1.btnAnulujClick(Sender: TObject);
begin
  if conn.Connected then
    conn.Close;
  Close;
end;

procedure TForm1.ApplicationProperties1Exception(Sender: TObject; E: Exception);
begin
  ShowMessage('Błąd: ' + E.Message);
end;

procedure TForm1.btnPolaczClick(Sender: TObject);
var
  tex: boolean;
begin
  conn.HostName := edtAdres.Text;
  conn.UserName := edtUser.Text;
  conn.Password := edtHaslo.Text;
  try
    conn.Open;
    tex := false;
    sql.SQL.Text := 'SELECT COUNT(*) FROM all_tables WHERE table_name = ''OSVC_PRACOWNICY''';
    try
      sql.Open;
      if sql.FieldByName('COUNT(*)').AsInteger > 0 then
      begin
        tex := true;
        if MessageDlg('', 'Tabela OSVC_PRACOWNICY już istnieje. Czy chcesz ją usunąć?', mtConfirmation, mbYesNo, 0) =
          mrYes then
        begin
          sql.Close;
          sql.SQL.Text := 'DROP TABLE OSVC_PRACOWNICY';
          sql.ExecSQL;
          tex := false;
        end;
      end;
    finally
      sql.Close;
    end;
    if not tex then
    begin
      sql.SQL.Text := 'CREATE TABLE OSVC_PRACOWNICY (' +
        'prac_id INT NOT NULL PRIMARY KEY, ' +
        'imie VARCHAR(20) NOT NULL, ' +
        'nazwisko VARCHAR(40) NOT NULL)';
      sql.ExecSQL;
    end;
    sql.SQL.Text := 'CREATE SEQUENCE IN NOT EXISTS prac_id_inc INCREMENT BY 1 START WITH 1';
    sql.ExecSQL;
  finally
    conn.Close;
  end;
end;

initialization
  {$I unit1.lrs}

end.
if i put an invalid query in place of
Quote
sql.SQL.Text := 'CREATE SEQUENCE IN NOT EXISTS prac_id_inc INCREMENT BY 1 START WITH 1';
i get an database error. but thats not a problem. the problem is: when i try to close the application after that error, i get "External: SIGSEGV" in the debugger. what's wrong with that?

Ñuño_Martínez

  • Hero Member
  • *****
  • Posts: 1206
    • Burdjia
Re: External: SIGSEGV while closing an application (debugging)
« Reply #1 on: July 27, 2010, 12:21:13 pm »
Just wondering:

You've put a "conn.Close" inside the FINALLY block. May be you shouldn't close the connection on error because it's closed somewhere else and it fails because it's closed yet. Actually I don't know but may be.
Are you interested in game programming? Join the Pascal Game Development community!
Also visit the Game Development Portal

JimBeam

  • New Member
  • *
  • Posts: 36
Re: External: SIGSEGV while closing an application (debugging)
« Reply #2 on: July 30, 2010, 01:40:40 pm »
Finally something a newb like me is starting to understand:
I think Ñuño is correct: if the conn.Open fails and generates an exception, the finally block will execute and try to close the conn object which is not open.
That will in turn generate an error.
Solution: move the conn.open statement out of the try..finally block.

Similar thing for the sql.open statement you've got with the sql.close in the finally block.

 

TinyPortal © 2005-2018