mirror of
https://github.com/HeidiSQL/HeidiSQL.git
synced 2025-08-06 18:24:26 +08:00
someone at MySQL...
... would have my balls for breakfast if he/she saw this ;-) Fulfills rfe #383.
This commit is contained in:
@ -180,6 +180,7 @@ type
|
|||||||
procedure Connect; virtual;
|
procedure Connect; virtual;
|
||||||
procedure Disconnect; virtual;
|
procedure Disconnect; virtual;
|
||||||
procedure Reconnect;
|
procedure Reconnect;
|
||||||
|
procedure CancelQuery; virtual;
|
||||||
function Ping: Boolean; virtual;
|
function Ping: Boolean; virtual;
|
||||||
function GetAffectedRowsFromLastPost: Int64;
|
function GetAffectedRowsFromLastPost: Int64;
|
||||||
function GetThreadId: Cardinal;
|
function GetThreadId: Cardinal;
|
||||||
@ -671,6 +672,15 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
{**
|
||||||
|
Cancel a query running in another thread.
|
||||||
|
}
|
||||||
|
procedure TZConnection.CancelQuery;
|
||||||
|
begin
|
||||||
|
if (FConnection <> nil) then FConnection.CancelQuery;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
{**
|
{**
|
||||||
Sends a ping to the server.
|
Sends a ping to the server.
|
||||||
}
|
}
|
||||||
|
@ -173,6 +173,7 @@ type
|
|||||||
procedure Open; virtual;
|
procedure Open; virtual;
|
||||||
procedure Close; virtual;
|
procedure Close; virtual;
|
||||||
function IsClosed: Boolean; virtual;
|
function IsClosed: Boolean; virtual;
|
||||||
|
procedure CancelQuery; virtual;
|
||||||
function Ping: Boolean; virtual;
|
function Ping: Boolean; virtual;
|
||||||
function GetAffectedRowsFromLastPost: Int64; virtual;
|
function GetAffectedRowsFromLastPost: Int64; virtual;
|
||||||
function GetThreadId: Cardinal; virtual;
|
function GetThreadId: Cardinal; virtual;
|
||||||
@ -778,6 +779,14 @@ begin
|
|||||||
Result := FClosed;
|
Result := FClosed;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{**
|
||||||
|
Cancels a running query in another thread.
|
||||||
|
}
|
||||||
|
procedure TZAbstractConnection.CancelQuery;
|
||||||
|
begin
|
||||||
|
raise Exception.Create('CancelQuery() is unsupported by this particular DB driver.');
|
||||||
|
end;
|
||||||
|
|
||||||
{**
|
{**
|
||||||
Returns true if a network ping to the database server succeeds.
|
Returns true if a network ping to the database server succeeds.
|
||||||
@return true if a network ping to the database server succeeds
|
@return true if a network ping to the database server succeeds
|
||||||
|
@ -243,6 +243,7 @@ type
|
|||||||
procedure Open;
|
procedure Open;
|
||||||
procedure Close;
|
procedure Close;
|
||||||
function IsClosed: Boolean;
|
function IsClosed: Boolean;
|
||||||
|
procedure CancelQuery;
|
||||||
function Ping: Boolean;
|
function Ping: Boolean;
|
||||||
function GetAffectedRowsFromLastPost: Int64;
|
function GetAffectedRowsFromLastPost: Int64;
|
||||||
function GetThreadId: Cardinal;
|
function GetThreadId: Cardinal;
|
||||||
|
@ -130,6 +130,8 @@ type
|
|||||||
function GetThreadId: Cardinal; override;
|
function GetThreadId: Cardinal; override;
|
||||||
function GetEscapeString(const Value: string): string; override;
|
function GetEscapeString(const Value: string): string; override;
|
||||||
|
|
||||||
|
procedure CancelQuery; override;
|
||||||
|
|
||||||
procedure SetCatalog(const Catalog: string); override;
|
procedure SetCatalog(const Catalog: string); override;
|
||||||
function GetCatalog: string; override;
|
function GetCatalog: string; override;
|
||||||
|
|
||||||
@ -463,6 +465,11 @@ begin
|
|||||||
inherited Open;
|
inherited Open;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TZMySQLConnection.CancelQuery;
|
||||||
|
begin
|
||||||
|
if not Closed then FPlainDriver.CancelQuery(FHandle);
|
||||||
|
end;
|
||||||
|
|
||||||
{**
|
{**
|
||||||
Ping Current Connection's server, if client was disconnected,
|
Ping Current Connection's server, if client was disconnected,
|
||||||
the connection is resumed.
|
the connection is resumed.
|
||||||
|
@ -64,7 +64,8 @@ interface
|
|||||||
|
|
||||||
uses Classes, ZClasses, ZPlainDriver, ZCompatibility, ZPlainMysqlConstants,
|
uses Classes, ZClasses, ZPlainDriver, ZCompatibility, ZPlainMysqlConstants,
|
||||||
{$IFDEF ENABLE_MYSQL_DEPRECATED} ZPlainMySql320, ZPlainMySql323, ZPlainMySql40,{$ENDIF}
|
{$IFDEF ENABLE_MYSQL_DEPRECATED} ZPlainMySql320, ZPlainMySql323, ZPlainMySql40,{$ENDIF}
|
||||||
ZPlainMySql41, ZPlainMySql5;
|
ZPlainMySql41, ZPlainMySql5,
|
||||||
|
Winsock;
|
||||||
|
|
||||||
const
|
const
|
||||||
|
|
||||||
@ -157,6 +158,20 @@ const
|
|||||||
// a new driver returns when connected to a pre-4.1 server.
|
// a new driver returns when connected to a pre-4.1 server.
|
||||||
COLLATION_NONE = 0;
|
COLLATION_NONE = 0;
|
||||||
|
|
||||||
|
type
|
||||||
|
TZMySQLNet = record
|
||||||
|
{ From: mysql-source/include/mysql_com.h }
|
||||||
|
sock: TSocket;
|
||||||
|
{ ... more unused ABI here ... }
|
||||||
|
end;
|
||||||
|
PZMySQLNet = ^TZMySQLNet;
|
||||||
|
TZMySQLConnect = record
|
||||||
|
{ From: mysql-source/include/mysql.h }
|
||||||
|
net: PZMySQLNet;
|
||||||
|
{ ... more unused ABI here ... }
|
||||||
|
end;
|
||||||
|
PZMySQLConnectPeek = ^TZMySQLConnect;
|
||||||
|
|
||||||
type
|
type
|
||||||
PZMySQLConnect = Pointer;
|
PZMySQLConnect = Pointer;
|
||||||
PZMySQLResult = Pointer;
|
PZMySQLResult = Pointer;
|
||||||
@ -194,6 +209,7 @@ type
|
|||||||
function GetAffectedRows(Handle: PZMySQLConnect): Int64;
|
function GetAffectedRows(Handle: PZMySQLConnect): Int64;
|
||||||
// char_set_name
|
// char_set_name
|
||||||
procedure SetCharacterSet(Handle: PZMySQLConnect; const CharSet: PChar);
|
procedure SetCharacterSet(Handle: PZMySQLConnect; const CharSet: PChar);
|
||||||
|
procedure CancelQuery(Handle: PZMySQLConnect);
|
||||||
procedure Close(Handle: PZMySQLConnect);
|
procedure Close(Handle: PZMySQLConnect);
|
||||||
function Connect(Handle: PZMySQLConnect; const Host, User, Password: PChar): PZMySQLConnect;
|
function Connect(Handle: PZMySQLConnect; const Host, User, Password: PChar): PZMySQLConnect;
|
||||||
function CreateDatabase(Handle: PZMySQLConnect; const Database: PChar): Integer;
|
function CreateDatabase(Handle: PZMySQLConnect; const Database: PChar): Integer;
|
||||||
@ -355,6 +371,7 @@ type
|
|||||||
function RealConnect(Handle: PZMySQLConnect;
|
function RealConnect(Handle: PZMySQLConnect;
|
||||||
const Host, User, Password, Db: PChar; Port: Cardinal;
|
const Host, User, Password, Db: PChar; Port: Cardinal;
|
||||||
UnixSocket: PChar; ClientFlag: Cardinal): PZMySQLConnect;
|
UnixSocket: PChar; ClientFlag: Cardinal): PZMySQLConnect;
|
||||||
|
procedure CancelQuery(Handle: PZMySQLConnect);
|
||||||
procedure Close(Handle: PZMySQLConnect);
|
procedure Close(Handle: PZMySQLConnect);
|
||||||
|
|
||||||
function ExecQuery(Handle: PZMySQLConnect; const Query: PChar): Integer;
|
function ExecQuery(Handle: PZMySQLConnect; const Query: PChar): Integer;
|
||||||
@ -479,6 +496,7 @@ type
|
|||||||
function RealConnect(Handle: PZMySQLConnect;
|
function RealConnect(Handle: PZMySQLConnect;
|
||||||
const Host, User, Password, Db: PChar; Port: Cardinal;
|
const Host, User, Password, Db: PChar; Port: Cardinal;
|
||||||
UnixSocket: PChar; ClientFlag: Cardinal): PZMySQLConnect;
|
UnixSocket: PChar; ClientFlag: Cardinal): PZMySQLConnect;
|
||||||
|
procedure CancelQuery(Handle: PZMySQLConnect);
|
||||||
procedure Close(Handle: PZMySQLConnect);
|
procedure Close(Handle: PZMySQLConnect);
|
||||||
|
|
||||||
function ExecQuery(Handle: PZMySQLConnect; const Query: PChar): Integer;
|
function ExecQuery(Handle: PZMySQLConnect; const Query: PChar): Integer;
|
||||||
@ -602,6 +620,7 @@ type
|
|||||||
function RealConnect(Handle: PZMySQLConnect;
|
function RealConnect(Handle: PZMySQLConnect;
|
||||||
const Host, User, Password, Db: PChar; Port: Cardinal;
|
const Host, User, Password, Db: PChar; Port: Cardinal;
|
||||||
UnixSocket: PChar; ClientFlag: Cardinal): PZMySQLConnect;
|
UnixSocket: PChar; ClientFlag: Cardinal): PZMySQLConnect;
|
||||||
|
procedure CancelQuery(Handle: PZMySQLConnect);
|
||||||
procedure Close(Handle: PZMySQLConnect);
|
procedure Close(Handle: PZMySQLConnect);
|
||||||
|
|
||||||
function ExecQuery(Handle: PZMySQLConnect; const Query: PChar): Integer;
|
function ExecQuery(Handle: PZMySQLConnect; const Query: PChar): Integer;
|
||||||
@ -735,6 +754,7 @@ type
|
|||||||
function RealConnect(Handle: PZMySQLConnect;
|
function RealConnect(Handle: PZMySQLConnect;
|
||||||
const Host, User, Password, Db: PChar; Port: Cardinal;
|
const Host, User, Password, Db: PChar; Port: Cardinal;
|
||||||
UnixSocket: PChar; ClientFlag: Cardinal): PZMySQLConnect;
|
UnixSocket: PChar; ClientFlag: Cardinal): PZMySQLConnect;
|
||||||
|
procedure CancelQuery(Handle: PZMySQLConnect);
|
||||||
procedure Close(Handle: PZMySQLConnect);
|
procedure Close(Handle: PZMySQLConnect);
|
||||||
|
|
||||||
function ExecQuery(Handle: PZMySQLConnect; const Query: PChar): Integer;
|
function ExecQuery(Handle: PZMySQLConnect; const Query: PChar): Integer;
|
||||||
@ -870,6 +890,7 @@ type
|
|||||||
function RealConnect(Handle: PZMySQLConnect;
|
function RealConnect(Handle: PZMySQLConnect;
|
||||||
const Host, User, Password, Db: PChar; Port: Cardinal;
|
const Host, User, Password, Db: PChar; Port: Cardinal;
|
||||||
UnixSocket: PChar; ClientFlag: Cardinal): PZMySQLConnect;
|
UnixSocket: PChar; ClientFlag: Cardinal): PZMySQLConnect;
|
||||||
|
procedure CancelQuery(Handle: PZMySQLConnect);
|
||||||
procedure Close(Handle: PZMySQLConnect);
|
procedure Close(Handle: PZMySQLConnect);
|
||||||
|
|
||||||
function ExecQuery(Handle: PZMySQLConnect; const Query: PChar): Integer;
|
function ExecQuery(Handle: PZMySQLConnect; const Query: PChar): Integer;
|
||||||
@ -980,7 +1001,7 @@ type
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
uses SysUtils, ZMessages;
|
uses SysUtils, ZMessages, Windows;
|
||||||
|
|
||||||
var
|
var
|
||||||
ServerArgs: array of PChar;
|
ServerArgs: array of PChar;
|
||||||
@ -1038,6 +1059,11 @@ begin
|
|||||||
MYSQL_API := ZPlainMySql320.LibraryLoader.api_rec;
|
MYSQL_API := ZPlainMySql320.LibraryLoader.api_rec;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TZMySQL320PlainDriver.CancelQuery(Handle: PZMySQLConnect);
|
||||||
|
begin
|
||||||
|
raise Exception.Create('This driver version does not support cancelling a query.');
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TZMySQL320PlainDriver.Close(Handle: PZMySQLConnect);
|
procedure TZMySQL320PlainDriver.Close(Handle: PZMySQLConnect);
|
||||||
begin
|
begin
|
||||||
MYSQL_API.mysql_close(Handle);
|
MYSQL_API.mysql_close(Handle);
|
||||||
@ -1545,6 +1571,11 @@ begin
|
|||||||
MYSQL_API := ZPlainMySql323.LibraryLoader.api_rec;
|
MYSQL_API := ZPlainMySql323.LibraryLoader.api_rec;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TZMySQL323PlainDriver.CancelQuery(Handle: PZMySQLConnect);
|
||||||
|
begin
|
||||||
|
raise Exception.Create('This driver version does not support cancelling a query.');
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TZMySQL323PlainDriver.Close(Handle: PZMySQLConnect);
|
procedure TZMySQL323PlainDriver.Close(Handle: PZMySQLConnect);
|
||||||
begin
|
begin
|
||||||
MYSQL_API.mysql_close(Handle);
|
MYSQL_API.mysql_close(Handle);
|
||||||
@ -2051,6 +2082,11 @@ begin
|
|||||||
MYSQL_API := ZPlainMySql40.LibraryLoader.api_rec;
|
MYSQL_API := ZPlainMySql40.LibraryLoader.api_rec;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TZMySQL40PlainDriver.CancelQuery(Handle: PZMySQLConnect);
|
||||||
|
begin
|
||||||
|
raise Exception.Create('This driver version does not support cancelling a query.');
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TZMySQL40PlainDriver.Close(Handle: PZMySQLConnect);
|
procedure TZMySQL40PlainDriver.Close(Handle: PZMySQLConnect);
|
||||||
begin
|
begin
|
||||||
MYSQL_API.mysql_close(Handle);
|
MYSQL_API.mysql_close(Handle);
|
||||||
@ -2589,6 +2625,11 @@ begin
|
|||||||
MYSQL_API := ZPlainMySql41.LibraryLoader.api_rec;
|
MYSQL_API := ZPlainMySql41.LibraryLoader.api_rec;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TZMySQL41PlainDriver.CancelQuery(Handle: PZMySQLConnect);
|
||||||
|
begin
|
||||||
|
raise Exception.Create('This driver version does not support cancelling a query.');
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TZMySQL41PlainDriver.Close(Handle: PZMySQLConnect);
|
procedure TZMySQL41PlainDriver.Close(Handle: PZMySQLConnect);
|
||||||
begin
|
begin
|
||||||
MYSQL_API.mysql_close(Handle);
|
MYSQL_API.mysql_close(Handle);
|
||||||
@ -3133,6 +3174,19 @@ begin
|
|||||||
MYSQL_API := ZPlainMySql5.LibraryLoader.api_rec;
|
MYSQL_API := ZPlainMySql5.LibraryLoader.api_rec;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TZMySQL5PlainDriver.CancelQuery(Handle: PZMySQLConnect);
|
||||||
|
var
|
||||||
|
peek: PZMySQLConnectPeek;
|
||||||
|
res: Integer;
|
||||||
|
begin
|
||||||
|
peek := Handle;
|
||||||
|
OutputDebugString(PChar('Tearing connection.'));
|
||||||
|
res := Winsock.shutdown(peek.net.sock, SD_BOTH);
|
||||||
|
if (res <> 0) then OutputDebugString(PChar(Format('Shutdown failed: %d', [WSAGetLastError()])));
|
||||||
|
res := Winsock.closesocket(peek.net.sock);
|
||||||
|
if (res <> 0) then OutputDebugString(PChar(Format('Close failed: %d', [WSAGetLastError()])));
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TZMySQL5PlainDriver.Close(Handle: PZMySQLConnect);
|
procedure TZMySQL5PlainDriver.Close(Handle: PZMySQLConnect);
|
||||||
begin
|
begin
|
||||||
MYSQL_API.mysql_close(Handle);
|
MYSQL_API.mysql_close(Handle);
|
||||||
|
@ -628,6 +628,7 @@ type
|
|||||||
HandleErrors: Boolean = false; DisplayErrors: Boolean = false ) : WideStrings.TWideStringList;
|
HandleErrors: Boolean = false; DisplayErrors: Boolean = false ) : WideStrings.TWideStringList;
|
||||||
procedure ZSQLMonitor1LogTrace(Sender: TObject; Event: TZLoggingEvent);
|
procedure ZSQLMonitor1LogTrace(Sender: TObject; Event: TZLoggingEvent);
|
||||||
procedure MenuTablelistColumnsClick(Sender: TObject);
|
procedure MenuTablelistColumnsClick(Sender: TObject);
|
||||||
|
procedure CancelQuery;
|
||||||
procedure CheckConnection();
|
procedure CheckConnection();
|
||||||
procedure QueryLoad( filename: String; ReplaceContent: Boolean = true );
|
procedure QueryLoad( filename: String; ReplaceContent: Boolean = true );
|
||||||
procedure ExecuteNonQuery(SQLQuery: String);
|
procedure ExecuteNonQuery(SQLQuery: String);
|
||||||
@ -795,6 +796,7 @@ type
|
|||||||
procedure AutoCalcColWidths(Tree: TVirtualStringTree; PrevLayout: Widestrings.TWideStringlist = nil);
|
procedure AutoCalcColWidths(Tree: TVirtualStringTree; PrevLayout: Widestrings.TWideStringlist = nil);
|
||||||
procedure FocusGridCol(Grid: TBaseVirtualTree; Column: TColumnIndex);
|
procedure FocusGridCol(Grid: TBaseVirtualTree; Column: TColumnIndex);
|
||||||
public
|
public
|
||||||
|
cancelling: Boolean;
|
||||||
virtualDesktopName: string;
|
virtualDesktopName: string;
|
||||||
MaintenanceForm: TOptimize;
|
MaintenanceForm: TOptimize;
|
||||||
ViewForm: TfrmView;
|
ViewForm: TfrmView;
|
||||||
@ -3864,6 +3866,7 @@ var
|
|||||||
signal: Cardinal;
|
signal: Cardinal;
|
||||||
begin
|
begin
|
||||||
debug( 'Waiting for query to complete.' );
|
debug( 'Waiting for query to complete.' );
|
||||||
|
cancelling := false;
|
||||||
if ForceDialog then begin
|
if ForceDialog then begin
|
||||||
debug( 'Showing progress form.' );
|
debug( 'Showing progress form.' );
|
||||||
WaitForm.ShowModal();
|
WaitForm.ShowModal();
|
||||||
@ -5801,6 +5804,13 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
procedure TMainForm.CancelQuery;
|
||||||
|
begin
|
||||||
|
cancelling := true;
|
||||||
|
MysqlConn.Connection.CancelQuery;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
// Searchbox unfocused
|
// Searchbox unfocused
|
||||||
procedure TMainForm.CheckConnection;
|
procedure TMainForm.CheckConnection;
|
||||||
begin
|
begin
|
||||||
|
@ -252,7 +252,16 @@ begin
|
|||||||
if E.Message = SCanNotOpenResultSet then begin
|
if E.Message = SCanNotOpenResultSet then begin
|
||||||
Result := true;
|
Result := true;
|
||||||
FreeAndNil(ADataset);
|
FreeAndNil(ADataset);
|
||||||
end else AExceptionData := GetExceptionData(E);
|
end else if MainForm.cancelling then begin
|
||||||
|
AExceptionData := GetExceptionData(Exception.Create('Cancelled by user.'));
|
||||||
|
try
|
||||||
|
FMysqlConn.Reconnect;
|
||||||
|
finally
|
||||||
|
MainForm.cancelling := false;
|
||||||
|
end;
|
||||||
|
end else begin
|
||||||
|
AExceptionData := GetExceptionData(E);
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@ -273,9 +282,19 @@ begin
|
|||||||
q.DoAsyncExecSql();
|
q.DoAsyncExecSql();
|
||||||
Result := True;
|
Result := True;
|
||||||
except
|
except
|
||||||
On E: Exception do
|
On E: Exception do begin
|
||||||
|
if MainForm.cancelling then begin
|
||||||
|
AExceptionData := GetExceptionData(Exception.Create('Cancelled by user.'));
|
||||||
|
try
|
||||||
|
FMysqlConn.Reconnect;
|
||||||
|
finally
|
||||||
|
MainForm.cancelling := false;
|
||||||
|
end;
|
||||||
|
end else begin
|
||||||
AExceptionData := GetExceptionData(E);
|
AExceptionData := GetExceptionData(E);
|
||||||
end;
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
FreeAndNil (q);
|
FreeAndNil (q);
|
||||||
end;
|
end;
|
||||||
|
@ -31,9 +31,8 @@ object frmQueryProgress: TfrmQueryProgress
|
|||||||
Width = 73
|
Width = 73
|
||||||
Height = 25
|
Height = 25
|
||||||
Cancel = True
|
Cancel = True
|
||||||
Caption = 'Please wait'
|
Caption = 'Cancel'
|
||||||
Default = True
|
Default = True
|
||||||
Enabled = False
|
|
||||||
TabOrder = 0
|
TabOrder = 0
|
||||||
OnClick = btnAbortClick
|
OnClick = btnAbortClick
|
||||||
end
|
end
|
||||||
|
@ -32,8 +32,7 @@ uses
|
|||||||
|
|
||||||
procedure TfrmQueryProgress.btnAbortClick(Sender: TObject);
|
procedure TfrmQueryProgress.btnAbortClick(Sender: TObject);
|
||||||
begin
|
begin
|
||||||
Close();
|
MainForm.CancelQuery;
|
||||||
// todo: implement connection killing !!
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user