Suppress error dialog when process is already gone. Fixes issue #2362.

This commit is contained in:
Ansgar Becker
2011-06-09 17:24:15 +00:00
parent c5ac79f647
commit d3ea4111a3
2 changed files with 25 additions and 6 deletions

View File

@ -396,6 +396,7 @@ type
function GetThreadId: Cardinal; virtual; abstract; function GetThreadId: Cardinal; virtual; abstract;
function GetCharacterSet: String; virtual; abstract; function GetCharacterSet: String; virtual; abstract;
procedure SetCharacterSet(CharsetName: String); virtual; abstract; procedure SetCharacterSet(CharsetName: String); virtual; abstract;
function GetLastErrorCode: Cardinal; virtual; abstract;
function GetLastError: String; virtual; abstract; function GetLastError: String; virtual; abstract;
function GetServerVersionStr: String; function GetServerVersionStr: String;
function GetServerVersionInt: Integer; virtual; abstract; function GetServerVersionInt: Integer; virtual; abstract;
@ -450,6 +451,7 @@ type
property ConnectionUptime: Integer read GetConnectionUptime; property ConnectionUptime: Integer read GetConnectionUptime;
property ServerUptime: Integer read GetServerUptime; property ServerUptime: Integer read GetServerUptime;
property CharacterSet: String read GetCharacterSet write SetCharacterSet; property CharacterSet: String read GetCharacterSet write SetCharacterSet;
property LastErrorCode: Cardinal read GetLastErrorCode;
property LastError: String read GetLastError; property LastError: String read GetLastError;
property ServerOS: String read FServerOS; property ServerOS: String read FServerOS;
property ServerVersionUntouched: String read FServerVersionUntouched; property ServerVersionUntouched: String read FServerVersionUntouched;
@ -500,6 +502,7 @@ type
function GetThreadId: Cardinal; override; function GetThreadId: Cardinal; override;
function GetCharacterSet: String; override; function GetCharacterSet: String; override;
procedure SetCharacterSet(CharsetName: String); override; procedure SetCharacterSet(CharsetName: String); override;
function GetLastErrorCode: Cardinal; override;
function GetLastError: String; override; function GetLastError: String; override;
function GetServerVersionInt: Integer; override; function GetServerVersionInt: Integer; override;
function GetAllDatabases: TStringList; override; function GetAllDatabases: TStringList; override;
@ -528,6 +531,7 @@ type
function GetThreadId: Cardinal; override; function GetThreadId: Cardinal; override;
function GetCharacterSet: String; override; function GetCharacterSet: String; override;
procedure SetCharacterSet(CharsetName: String); override; procedure SetCharacterSet(CharsetName: String); override;
function GetLastErrorCode: Cardinal; override;
function GetLastError: String; override; function GetLastError: String; override;
function GetServerVersionInt: Integer; override; function GetServerVersionInt: Integer; override;
function GetAllDatabases: TStringList; override; function GetAllDatabases: TStringList; override;
@ -1566,6 +1570,18 @@ begin
end; 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 Return the last error nicely formatted
} }
@ -1584,7 +1600,7 @@ begin
Msg := Msg + CRLF + CRLF + Additional; Msg := Msg + CRLF + CRLF + Additional;
end; end;
rx.Free; rx.Free;
Result := Format(MsgSQLError, [mysql_errno(FHandle), Msg]); Result := Format(MsgSQLError, [LastErrorCode, Msg]);
end; end;
@ -1602,7 +1618,7 @@ begin
if rx.Exec(Msg) then if rx.Exec(Msg) then
Msg := rx.Match[1]; Msg := rx.Match[1];
rx.Free; rx.Free;
Result := Format(MsgSQLError, [E.NativeError, Msg]); Result := Format(MsgSQLError, [LastErrorCode, Msg]);
end; end;

View File

@ -4506,23 +4506,26 @@ var
t: Boolean; t: Boolean;
pid: String; pid: String;
Node: PVirtualNode; Node: PVirtualNode;
Conn: TDBConnection;
begin begin
t := TimerRefresh.Enabled; t := TimerRefresh.Enabled;
TimerRefresh.Enabled := false; // prevent av (ListProcesses.selected...) TimerRefresh.Enabled := false; // prevent av (ListProcesses.selected...)
Conn := ActiveConnection;
if MessageDialog('Kill '+IntToStr(ListProcesses.SelectedCount)+' Process(es)?', mtConfirmation, [mbok,mbcancel]) = mrok then if MessageDialog('Kill '+IntToStr(ListProcesses.SelectedCount)+' Process(es)?', mtConfirmation, [mbok,mbcancel]) = mrok then
begin begin
Node := GetNextNode(ListProcesses, nil, True); Node := GetNextNode(ListProcesses, nil, True);
while Assigned(Node) do begin while Assigned(Node) do begin
pid := ListProcesses.Text[Node, ListProcesses.Header.MainColumn]; pid := ListProcesses.Text[Node, ListProcesses.Header.MainColumn];
// Don't kill own process // 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.') LogSQL('Ignoring own process id #'+pid+' when trying to kill it.')
else try else try
ActiveConnection.Query('KILL '+pid); Conn.Query('KILL '+pid);
except except
on E:EDatabaseError do begin on E:EDatabaseError do begin
if MessageDialog(E.Message, mtError, [mbOK, mbAbort]) = mrAbort then if Conn.LastErrorCode <> 1094 then
break; if MessageDialog(E.Message, mtError, [mbOK, mbAbort]) = mrAbort then
break;
end; end;
end; end;
Node := GetNextNode(ListProcesses, Node, True); Node := GetNextNode(ListProcesses, Node, True);