mirror of
https://github.com/HeidiSQL/HeidiSQL.git
synced 2025-08-06 18:24:26 +08:00
Bugfix: There is no thread safety mechanism in Zeos for the SQL log, so implement one in HeidiSQL. This should speed up async queries tremendously, as they no longer have to wait for the GUI to repaint before firing the actual query. Haven't bothered thinking about thread safety around the creation of the critical section protecting the TStringList, mainly because I'm infinitely annoyed by Delphi not providing a thread-safe list capable of holding lists OOTB..
This commit is contained in:
@ -510,6 +510,7 @@ type
|
|||||||
Column: TColumnIndex; var LineBreakStyle: TVTTooltipLineBreakStyle; var
|
Column: TColumnIndex; var LineBreakStyle: TVTTooltipLineBreakStyle; var
|
||||||
HintText: WideString);
|
HintText: WideString);
|
||||||
procedure popupFilterPopup(Sender: TObject);
|
procedure popupFilterPopup(Sender: TObject);
|
||||||
|
procedure ProcessSqlLog;
|
||||||
|
|
||||||
private
|
private
|
||||||
strHostRunning : String;
|
strHostRunning : String;
|
||||||
@ -534,6 +535,8 @@ type
|
|||||||
TablePropertiesForm : Ttbl_properties_form;
|
TablePropertiesForm : Ttbl_properties_form;
|
||||||
FileNameSessionLog : String;
|
FileNameSessionLog : String;
|
||||||
FileHandleSessionLog : Textfile;
|
FileHandleSessionLog : Textfile;
|
||||||
|
SqlMessages : TStringList;
|
||||||
|
SqlMessagesLock : TRtlCriticalSection;
|
||||||
|
|
||||||
function GetQueryRunning: Boolean;
|
function GetQueryRunning: Boolean;
|
||||||
procedure SetQueryRunning(running: Boolean);
|
procedure SetQueryRunning(running: Boolean);
|
||||||
@ -764,6 +767,10 @@ begin
|
|||||||
UserQueryFiring := False;
|
UserQueryFiring := False;
|
||||||
TemporaryDatabase := '';
|
TemporaryDatabase := '';
|
||||||
CachedTableLists := TStringList.Create;
|
CachedTableLists := TStringList.Create;
|
||||||
|
InitializeCriticalSection(SqlMessagesLock);
|
||||||
|
EnterCriticalSection(SqlMessagesLock);
|
||||||
|
SqlMessages := TStringList.Create;
|
||||||
|
LeaveCriticalSection(SqlMessagesLock);
|
||||||
|
|
||||||
FConn := AConn^;
|
FConn := AConn^;
|
||||||
FMysqlConn := AMysqlConn; // we're now responsible to free it
|
FMysqlConn := AMysqlConn; // we're now responsible to free it
|
||||||
@ -1087,6 +1094,9 @@ begin
|
|||||||
SetWindowConnected( false );
|
SetWindowConnected( false );
|
||||||
SetWindowName( main.discname );
|
SetWindowName( main.discname );
|
||||||
Application.Title := APPNAME;
|
Application.Title := APPNAME;
|
||||||
|
EnterCriticalSection(SqlMessagesLock);
|
||||||
|
FreeAndNil(SqlMessages);
|
||||||
|
LeaveCriticalSection(SqlMessagesLock);
|
||||||
|
|
||||||
// Closing connection and saving some vars into registry
|
// Closing connection and saving some vars into registry
|
||||||
case ( WindowState ) of
|
case ( WindowState ) of
|
||||||
@ -1173,7 +1183,30 @@ begin
|
|||||||
msg := '/* ' + msg + ' */';
|
msg := '/* ' + msg + ' */';
|
||||||
end;
|
end;
|
||||||
|
|
||||||
SynMemoSQLLog.Lines.Add( msg );
|
EnterCriticalSection(SqlMessagesLock);
|
||||||
|
try
|
||||||
|
SqlMessages.Add(msg);
|
||||||
|
finally
|
||||||
|
LeaveCriticalSection(SqlMessagesLock);
|
||||||
|
end;
|
||||||
|
PostMessage(MainForm.Handle, WM_PROCESSLOG, 0, 0);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TMDIChild.ProcessSqlLog;
|
||||||
|
var
|
||||||
|
msg: string;
|
||||||
|
begin
|
||||||
|
EnterCriticalSection(SqlMessagesLock);
|
||||||
|
try
|
||||||
|
if SqlMessages = nil then Exit;
|
||||||
|
if SqlMessages.Count < 1 then Exit;
|
||||||
|
msg := SqlMessages[0];
|
||||||
|
SqlMessages.Delete(0);
|
||||||
|
finally
|
||||||
|
LeaveCriticalSection(SqlMessagesLock);
|
||||||
|
end;
|
||||||
|
|
||||||
|
SynMemoSQLLog.Lines.Add( String(msg) );
|
||||||
SynMemoSQLLog.GotoLineAndCenter( SynMemoSQLLog.Lines.Count );
|
SynMemoSQLLog.GotoLineAndCenter( SynMemoSQLLog.Lines.Count );
|
||||||
SynMemoSQLLog.Repaint();
|
SynMemoSQLLog.Repaint();
|
||||||
|
|
||||||
@ -1834,7 +1867,7 @@ end;
|
|||||||
procedure TMDIChild.WaitForQueryCompletion(WaitForm: TForm);
|
procedure TMDIChild.WaitForQueryCompletion(WaitForm: TForm);
|
||||||
begin
|
begin
|
||||||
debug( 'Waiting for query to complete.' );
|
debug( 'Waiting for query to complete.' );
|
||||||
WaitForm.ShowModal();
|
WaitForm.ShowModal();
|
||||||
debug( 'Query complete.' );
|
debug( 'Query complete.' );
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ uses
|
|||||||
const
|
const
|
||||||
// Our custom message types.
|
// Our custom message types.
|
||||||
WM_COMPLETED = WM_APP + 1;
|
WM_COMPLETED = WM_APP + 1;
|
||||||
|
WM_PROCESSLOG = WM_APP + 2;
|
||||||
// Our message subtypes for WM_COPYDATA messages.
|
// Our message subtypes for WM_COPYDATA messages.
|
||||||
CMD_EXECUTEQUERY_NORESULTS = 1; { Slightly faster - Fire-and-forget, no results }
|
CMD_EXECUTEQUERY_NORESULTS = 1; { Slightly faster - Fire-and-forget, no results }
|
||||||
CMD_EXECUTEQUERY_RESULTS = 2; { Normal - Wait for completion, fetch results }
|
CMD_EXECUTEQUERY_RESULTS = 2; { Normal - Wait for completion, fetch results }
|
||||||
|
@ -195,6 +195,7 @@ type
|
|||||||
procedure ExecuteRemoteNonQuery(sender: THandle; query: string);
|
procedure ExecuteRemoteNonQuery(sender: THandle; query: string);
|
||||||
procedure HandleWMComplete(var msg: TMessage); message WM_COMPLETED;
|
procedure HandleWMComplete(var msg: TMessage); message WM_COMPLETED;
|
||||||
procedure HandleWMCopyData(var msg: TWMCopyData); message WM_COPYDATA;
|
procedure HandleWMCopyData(var msg: TWMCopyData); message WM_COPYDATA;
|
||||||
|
procedure HandleWMProcessLog(var msg: TMessage); message WM_PROCESSLOG;
|
||||||
private
|
private
|
||||||
function GetChildwin: TMDIChild;
|
function GetChildwin: TMDIChild;
|
||||||
public
|
public
|
||||||
@ -276,6 +277,11 @@ begin
|
|||||||
HandleWMCopyDataMessage(msg);
|
HandleWMCopyDataMessage(msg);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TMainForm.HandleWMProcessLog(var msg: TMessage);
|
||||||
|
begin
|
||||||
|
ChildWin.ProcessSqlLog;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TMainForm.EnsureConnected;
|
procedure TMainForm.EnsureConnected;
|
||||||
begin
|
begin
|
||||||
if ActiveMDIChild = nil then raise Exception.Create('Not connected.');
|
if ActiveMDIChild = nil then raise Exception.Create('Not connected.');
|
||||||
|
Reference in New Issue
Block a user