mirror of
https://github.com/HeidiSQL/HeidiSQL.git
synced 2025-08-26 20:50:20 +08:00
* Remove spam.
* Improve performance by not painting the progress form if a query completes within 300 msecs.
This commit is contained in:
@ -543,7 +543,7 @@ type
|
|||||||
procedure GridHighlightChanged(Sender: TObject);
|
procedure GridHighlightChanged(Sender: TObject);
|
||||||
procedure SaveBlob;
|
procedure SaveBlob;
|
||||||
function GetActiveGrid: TSMDBGrid;
|
function GetActiveGrid: TSMDBGrid;
|
||||||
procedure WaitForQueryCompletion(WaitForm: TForm);
|
procedure WaitForQueryCompletion(WaitForm: TfrmQueryProgress; query: TMySqlQuery);
|
||||||
function RunThreadedQuery(AQuery : String) : TMysqlQuery;
|
function RunThreadedQuery(AQuery : String) : TMysqlQuery;
|
||||||
procedure DisplayRowCountStats(ds: TDataSet);
|
procedure DisplayRowCountStats(ds: TDataSet);
|
||||||
procedure insertFunction(Sender: TObject);
|
procedure insertFunction(Sender: TObject);
|
||||||
@ -1864,10 +1864,18 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
procedure TMDIChild.WaitForQueryCompletion(WaitForm: TForm);
|
procedure TMDIChild.WaitForQueryCompletion(WaitForm: TfrmQueryProgress; query: TMySqlQuery);
|
||||||
|
var
|
||||||
|
signal: Cardinal;
|
||||||
begin
|
begin
|
||||||
debug( 'Waiting for query to complete.' );
|
debug( 'Waiting for query to complete.' );
|
||||||
|
signal := WaitForSingleObject(query.EventHandle, 300);
|
||||||
|
if signal = 0 then debug( 'Query completed within 300msec.' )
|
||||||
|
else begin
|
||||||
|
debug( '300msec passed, showing progress form.' );
|
||||||
WaitForm.ShowModal();
|
WaitForm.ShowModal();
|
||||||
|
end;
|
||||||
|
CloseHandle(query.EventHandle);
|
||||||
debug( 'Query complete.' );
|
debug( 'Query complete.' );
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -5251,7 +5259,7 @@ begin
|
|||||||
FProgressForm := TFrmQueryProgress.Create(Self);
|
FProgressForm := TFrmQueryProgress.Create(Self);
|
||||||
debug('RunThreadedQuery(): Launching asynchronous query.');
|
debug('RunThreadedQuery(): Launching asynchronous query.');
|
||||||
res := ExecPostAsync(FConn,nil,FProgressForm.Handle,ds);
|
res := ExecPostAsync(FConn,nil,FProgressForm.Handle,ds);
|
||||||
WaitForQueryCompletion(FProgressForm);
|
WaitForQueryCompletion(FProgressForm, res);
|
||||||
if res.Result in [MQR_CONNECT_FAIL,MQR_QUERY_FAIL] then
|
if res.Result in [MQR_CONNECT_FAIL,MQR_QUERY_FAIL] then
|
||||||
begin
|
begin
|
||||||
raise Exception.Create(res.Comment);
|
raise Exception.Create(res.Comment);
|
||||||
@ -5300,7 +5308,7 @@ begin
|
|||||||
{ Repeatedly check if the query has finished by inspecting FQueryRunning
|
{ Repeatedly check if the query has finished by inspecting FQueryRunning
|
||||||
Allow repainting of user interface
|
Allow repainting of user interface
|
||||||
}
|
}
|
||||||
WaitForQueryCompletion(FProgressForm);
|
WaitForQueryCompletion(FProgressForm, Result);
|
||||||
finally
|
finally
|
||||||
FQueryRunning := false;
|
FQueryRunning := false;
|
||||||
end;
|
end;
|
||||||
|
@ -45,6 +45,7 @@ type
|
|||||||
FSyncMode : Integer;
|
FSyncMode : Integer;
|
||||||
FQueryThread : TMysqlQueryThread;
|
FQueryThread : TMysqlQueryThread;
|
||||||
FEventName : String;
|
FEventName : String;
|
||||||
|
FEventHandle : THandle;
|
||||||
FSql : String;
|
FSql : String;
|
||||||
FOnNotify : TMysqlQueryNotificationEvent;
|
FOnNotify : TMysqlQueryNotificationEvent;
|
||||||
function GetNotificationMode: Integer;
|
function GetNotificationMode: Integer;
|
||||||
@ -71,6 +72,7 @@ type
|
|||||||
property ThreadID : Integer read FThreadID; // Mysql query thread ID (on the clients os)
|
property ThreadID : Integer read FThreadID; // Mysql query thread ID (on the clients os)
|
||||||
property Sql : String read FSql; // Query string
|
property Sql : String read FSql; // Query string
|
||||||
property EventName : String read FEventName; // Operating system event name used for blocking mode
|
property EventName : String read FEventName; // Operating system event name used for blocking mode
|
||||||
|
property EventHandle : THandle read FEventHandle;
|
||||||
property NotificationMode : Integer read GetNotificationMode;
|
property NotificationMode : Integer read GetNotificationMode;
|
||||||
property OnNotify : TMysqlQueryNotificationEvent read FOnNotify write FOnNotify; // Event procedure used in MQN_EVENTPROC notification mode
|
property OnNotify : TMysqlQueryNotificationEvent read FOnNotify write FOnNotify; // Event procedure used in MQN_EVENTPROC notification mode
|
||||||
end;
|
end;
|
||||||
@ -187,58 +189,21 @@ begin
|
|||||||
inherited;
|
inherited;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
{***
|
|
||||||
|
|
||||||
@param
|
|
||||||
@param
|
|
||||||
|
|
||||||
@result
|
|
||||||
}
|
|
||||||
|
|
||||||
function TMysqlQuery.GetComment: String;
|
function TMysqlQuery.GetComment: String;
|
||||||
begin
|
begin
|
||||||
Result := FQueryResult.Comment;
|
Result := FQueryResult.Comment;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
{***
|
|
||||||
|
|
||||||
@param
|
|
||||||
@param
|
|
||||||
|
|
||||||
@result
|
|
||||||
}
|
|
||||||
|
|
||||||
function TMysqlQuery.GetConnectionID: Integer;
|
function TMysqlQuery.GetConnectionID: Integer;
|
||||||
begin
|
begin
|
||||||
Result := FQueryResult.ConnectionID;
|
Result := FQueryResult.ConnectionID;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
{***
|
|
||||||
|
|
||||||
@param
|
|
||||||
@param
|
|
||||||
|
|
||||||
@result
|
|
||||||
}
|
|
||||||
|
|
||||||
function TMysqlQuery.GetHasresultSet: Boolean;
|
function TMysqlQuery.GetHasresultSet: Boolean;
|
||||||
begin
|
begin
|
||||||
Result := FMysqlDataset <> nil;
|
Result := FMysqlDataset <> nil;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
{***
|
|
||||||
|
|
||||||
@param
|
|
||||||
@param
|
|
||||||
|
|
||||||
@result
|
|
||||||
}
|
|
||||||
|
|
||||||
function TMysqlQuery.GetNotificationMode: Integer;
|
function TMysqlQuery.GetNotificationMode: Integer;
|
||||||
begin
|
begin
|
||||||
if Assigned(FOnNotify) then
|
if Assigned(FOnNotify) then
|
||||||
@ -247,29 +212,11 @@ begin
|
|||||||
Result := MQN_WINMESSAGE;
|
Result := MQN_WINMESSAGE;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
{***
|
|
||||||
|
|
||||||
@param
|
|
||||||
@param
|
|
||||||
|
|
||||||
@result
|
|
||||||
}
|
|
||||||
|
|
||||||
function TMysqlQuery.GetResult: Integer;
|
function TMysqlQuery.GetResult: Integer;
|
||||||
begin
|
begin
|
||||||
Result := FQueryResult.Result;
|
Result := FQueryResult.Result;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
{***
|
|
||||||
|
|
||||||
@param
|
|
||||||
@param
|
|
||||||
|
|
||||||
@result
|
|
||||||
}
|
|
||||||
|
|
||||||
procedure TMysqlQuery.PostNotification(AQueryResult: TThreadResult; AEvent : Integer);
|
procedure TMysqlQuery.PostNotification(AQueryResult: TThreadResult; AEvent : Integer);
|
||||||
begin
|
begin
|
||||||
SetThreadResult(AQueryResult);
|
SetThreadResult(AQueryResult);
|
||||||
@ -285,18 +232,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
{***
|
|
||||||
|
|
||||||
@param
|
|
||||||
@param
|
|
||||||
|
|
||||||
@result
|
|
||||||
}
|
|
||||||
|
|
||||||
procedure TMysqlQuery.Query(ASql: String; AMode: Integer; ANotifyWndHandle : THandle; Callback: TAsyncPostRunner; ds: TDeferDataSet);
|
procedure TMysqlQuery.Query(ASql: String; AMode: Integer; ANotifyWndHandle : THandle; Callback: TAsyncPostRunner; ds: TDeferDataSet);
|
||||||
var
|
|
||||||
EventHandle : THandle;
|
|
||||||
begin
|
begin
|
||||||
|
|
||||||
// create thread object
|
// create thread object
|
||||||
@ -307,11 +243,11 @@ begin
|
|||||||
FSyncMode := AMode;
|
FSyncMode := AMode;
|
||||||
FSql := ASql;
|
FSql := ASql;
|
||||||
|
|
||||||
|
FEventHandle := CreateEvent ({*EVENT_MODIFY_STATE + SYNCHRONIZE*}nil, False, False, PChar(FEventName));
|
||||||
|
|
||||||
case AMode of
|
case AMode of
|
||||||
MQM_SYNC:
|
MQM_SYNC:
|
||||||
begin
|
begin
|
||||||
// create mutex
|
|
||||||
EventHandle := CreateEvent (nil,False,False,PChar(FEventName));
|
|
||||||
// exec query
|
// exec query
|
||||||
debug(Format('qry: Starting query thread %d', [FQueryThread.ThreadID]));
|
debug(Format('qry: Starting query thread %d', [FQueryThread.ThreadID]));
|
||||||
FQueryThread.Resume();
|
FQueryThread.Resume();
|
||||||
|
@ -161,14 +161,13 @@ var
|
|||||||
h : THandle;
|
h : THandle;
|
||||||
begin
|
begin
|
||||||
|
|
||||||
// trigger query finished event
|
if AEvent = MQE_FINISHED then begin
|
||||||
if (FSyncMode=MQM_SYNC) and (AEvent=MQE_FREED) then
|
// trigger query finished event
|
||||||
begin
|
h := OpenEvent (EVENT_MODIFY_STATE,False,PChar(TMysqlQuery(FOwner).EventName));
|
||||||
h := OpenEvent (EVENT_ALL_ACCESS,False,PChar(TMysqlQuery(FOwner).EventName));
|
debug('qry: Signalling completion via event.');
|
||||||
|
if not SetEvent (h) then debug(Format('qry: Assertion failed: Error %d signaling event', [GetLastError]));
|
||||||
if h<>0 then
|
CloseHandle(h);
|
||||||
SetEvent (h);
|
end;
|
||||||
end;
|
|
||||||
|
|
||||||
case TMysqlQuery(FOwner).NotificationMode of
|
case TMysqlQuery(FOwner).NotificationMode of
|
||||||
MQN_EVENTPROC: NotifyStatusViaEventProc(AEvent);
|
MQN_EVENTPROC: NotifyStatusViaEventProc(AEvent);
|
||||||
@ -198,6 +197,7 @@ begin
|
|||||||
debug(Format('qry: Setting result and posting status %d via WM_MYSQL_THREAD_NOTIFY message', [AEvent]));
|
debug(Format('qry: Setting result and posting status %d via WM_MYSQL_THREAD_NOTIFY message', [AEvent]));
|
||||||
qr := AssembleResult();
|
qr := AssembleResult();
|
||||||
TMysqlQuery(FOwner).SetThreadResult(qr);
|
TMysqlQuery(FOwner).SetThreadResult(qr);
|
||||||
|
debug('qry: Signalling completion via message.');
|
||||||
PostMessage(FNotifyWndHandle,WM_MYSQL_THREAD_NOTIFY,Integer(FOwner),AEvent);
|
PostMessage(FNotifyWndHandle,WM_MYSQL_THREAD_NOTIFY,Integer(FOwner),AEvent);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -234,11 +234,11 @@ begin
|
|||||||
end else begin
|
end else begin
|
||||||
try
|
try
|
||||||
r := RunDataQuery (FSql,TDataSet(q),ex,FCallback);
|
r := RunDataQuery (FSql,TDataSet(q),ex,FCallback);
|
||||||
if r then begin
|
//if r then begin
|
||||||
//if q.State=dsBrowse then begin
|
//if q.State=dsBrowse then begin
|
||||||
// WTF?
|
// WTF?
|
||||||
//end;
|
//end;
|
||||||
end;
|
//end;
|
||||||
TMysqlQuery(FOwner).SetMysqlDataset(q);
|
TMysqlQuery(FOwner).SetMysqlDataset(q);
|
||||||
|
|
||||||
if r then SetState (MQR_SUCCESS,'SUCCESS')
|
if r then SetState (MQR_SUCCESS,'SUCCESS')
|
||||||
|
Reference in New Issue
Block a user