From d3ea4111a3b142a98868d65b3f05a3553716454c Mon Sep 17 00:00:00 2001 From: Ansgar Becker Date: Thu, 9 Jun 2011 17:24:15 +0000 Subject: [PATCH] Suppress error dialog when process is already gone. Fixes issue #2362. --- source/dbconnection.pas | 20 ++++++++++++++++++-- source/main.pas | 11 +++++++---- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/source/dbconnection.pas b/source/dbconnection.pas index 2783e024..b9e9fd97 100644 --- a/source/dbconnection.pas +++ b/source/dbconnection.pas @@ -396,6 +396,7 @@ type function GetThreadId: Cardinal; virtual; abstract; function GetCharacterSet: String; virtual; abstract; procedure SetCharacterSet(CharsetName: String); virtual; abstract; + function GetLastErrorCode: Cardinal; virtual; abstract; function GetLastError: String; virtual; abstract; function GetServerVersionStr: String; function GetServerVersionInt: Integer; virtual; abstract; @@ -450,6 +451,7 @@ type property ConnectionUptime: Integer read GetConnectionUptime; property ServerUptime: Integer read GetServerUptime; property CharacterSet: String read GetCharacterSet write SetCharacterSet; + property LastErrorCode: Cardinal read GetLastErrorCode; property LastError: String read GetLastError; property ServerOS: String read FServerOS; property ServerVersionUntouched: String read FServerVersionUntouched; @@ -500,6 +502,7 @@ type function GetThreadId: Cardinal; override; function GetCharacterSet: String; override; procedure SetCharacterSet(CharsetName: String); override; + function GetLastErrorCode: Cardinal; override; function GetLastError: String; override; function GetServerVersionInt: Integer; override; function GetAllDatabases: TStringList; override; @@ -528,6 +531,7 @@ type function GetThreadId: Cardinal; override; function GetCharacterSet: String; override; procedure SetCharacterSet(CharsetName: String); override; + function GetLastErrorCode: Cardinal; override; function GetLastError: String; override; function GetServerVersionInt: Integer; override; function GetAllDatabases: TStringList; override; @@ -1566,6 +1570,18 @@ begin end; +function TMySQLConnection.GetLastErrorCode: Cardinal; +begin + Result := mysql_errno(FHandle); +end; + + +function TAdoDBConnection.GetLastErrorCode: Cardinal; +begin + Result := FAdoHandle.Errors[FAdoHandle.Errors.Count-1].NativeError; +end; + + {** Return the last error nicely formatted } @@ -1584,7 +1600,7 @@ begin Msg := Msg + CRLF + CRLF + Additional; end; rx.Free; - Result := Format(MsgSQLError, [mysql_errno(FHandle), Msg]); + Result := Format(MsgSQLError, [LastErrorCode, Msg]); end; @@ -1602,7 +1618,7 @@ begin if rx.Exec(Msg) then Msg := rx.Match[1]; rx.Free; - Result := Format(MsgSQLError, [E.NativeError, Msg]); + Result := Format(MsgSQLError, [LastErrorCode, Msg]); end; diff --git a/source/main.pas b/source/main.pas index d35819d6..e0ef92e9 100644 --- a/source/main.pas +++ b/source/main.pas @@ -4506,23 +4506,26 @@ var t: Boolean; pid: String; Node: PVirtualNode; + Conn: TDBConnection; begin t := TimerRefresh.Enabled; TimerRefresh.Enabled := false; // prevent av (ListProcesses.selected...) + Conn := ActiveConnection; if MessageDialog('Kill '+IntToStr(ListProcesses.SelectedCount)+' Process(es)?', mtConfirmation, [mbok,mbcancel]) = mrok then begin Node := GetNextNode(ListProcesses, nil, True); while Assigned(Node) do begin pid := ListProcesses.Text[Node, ListProcesses.Header.MainColumn]; // Don't kill own process - if pid = IntToStr(ActiveConnection.ThreadId) then + if pid = IntToStr(Conn.ThreadId) then LogSQL('Ignoring own process id #'+pid+' when trying to kill it.') else try - ActiveConnection.Query('KILL '+pid); + Conn.Query('KILL '+pid); except on E:EDatabaseError do begin - if MessageDialog(E.Message, mtError, [mbOK, mbAbort]) = mrAbort then - break; + if Conn.LastErrorCode <> 1094 then + if MessageDialog(E.Message, mtError, [mbOK, mbAbort]) = mrAbort then + break; end; end; Node := GetNextNode(ListProcesses, Node, True);