* Remove spam.

* Improve performance by not painting the progress form if a query completes within 300 msecs.
This commit is contained in:
rosenfield
2007-10-08 21:52:59 +00:00
parent 74074fe633
commit 4232f36909
3 changed files with 27 additions and 83 deletions

View File

@ -543,7 +543,7 @@ type
procedure GridHighlightChanged(Sender: TObject);
procedure SaveBlob;
function GetActiveGrid: TSMDBGrid;
procedure WaitForQueryCompletion(WaitForm: TForm);
procedure WaitForQueryCompletion(WaitForm: TfrmQueryProgress; query: TMySqlQuery);
function RunThreadedQuery(AQuery : String) : TMysqlQuery;
procedure DisplayRowCountStats(ds: TDataSet);
procedure insertFunction(Sender: TObject);
@ -1864,10 +1864,18 @@ begin
end;
procedure TMDIChild.WaitForQueryCompletion(WaitForm: TForm);
procedure TMDIChild.WaitForQueryCompletion(WaitForm: TfrmQueryProgress; query: TMySqlQuery);
var
signal: Cardinal;
begin
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();
end;
CloseHandle(query.EventHandle);
debug( 'Query complete.' );
end;
@ -5251,7 +5259,7 @@ begin
FProgressForm := TFrmQueryProgress.Create(Self);
debug('RunThreadedQuery(): Launching asynchronous query.');
res := ExecPostAsync(FConn,nil,FProgressForm.Handle,ds);
WaitForQueryCompletion(FProgressForm);
WaitForQueryCompletion(FProgressForm, res);
if res.Result in [MQR_CONNECT_FAIL,MQR_QUERY_FAIL] then
begin
raise Exception.Create(res.Comment);
@ -5300,7 +5308,7 @@ begin
{ Repeatedly check if the query has finished by inspecting FQueryRunning
Allow repainting of user interface
}
WaitForQueryCompletion(FProgressForm);
WaitForQueryCompletion(FProgressForm, Result);
finally
FQueryRunning := false;
end;

View File

@ -45,6 +45,7 @@ type
FSyncMode : Integer;
FQueryThread : TMysqlQueryThread;
FEventName : String;
FEventHandle : THandle;
FSql : String;
FOnNotify : TMysqlQueryNotificationEvent;
function GetNotificationMode: Integer;
@ -71,6 +72,7 @@ type
property ThreadID : Integer read FThreadID; // Mysql query thread ID (on the clients os)
property Sql : String read FSql; // Query string
property EventName : String read FEventName; // Operating system event name used for blocking mode
property EventHandle : THandle read FEventHandle;
property NotificationMode : Integer read GetNotificationMode;
property OnNotify : TMysqlQueryNotificationEvent read FOnNotify write FOnNotify; // Event procedure used in MQN_EVENTPROC notification mode
end;
@ -187,58 +189,21 @@ begin
inherited;
end;
{***
@param
@param
@result
}
function TMysqlQuery.GetComment: String;
begin
Result := FQueryResult.Comment;
Result := FQueryResult.Comment;
end;
{***
@param
@param
@result
}
function TMysqlQuery.GetConnectionID: Integer;
begin
Result := FQueryResult.ConnectionID;
end;
{***
@param
@param
@result
}
function TMysqlQuery.GetHasresultSet: Boolean;
begin
Result := FMysqlDataset <> nil;
end;
{***
@param
@param
@result
}
function TMysqlQuery.GetNotificationMode: Integer;
begin
if Assigned(FOnNotify) then
@ -247,29 +212,11 @@ begin
Result := MQN_WINMESSAGE;
end;
{***
@param
@param
@result
}
function TMysqlQuery.GetResult: Integer;
begin
Result := FQueryResult.Result;
end;
{***
@param
@param
@result
}
procedure TMysqlQuery.PostNotification(AQueryResult: TThreadResult; AEvent : Integer);
begin
SetThreadResult(AQueryResult);
@ -285,18 +232,7 @@ begin
end;
end;
{***
@param
@param
@result
}
procedure TMysqlQuery.Query(ASql: String; AMode: Integer; ANotifyWndHandle : THandle; Callback: TAsyncPostRunner; ds: TDeferDataSet);
var
EventHandle : THandle;
begin
// create thread object
@ -307,11 +243,11 @@ begin
FSyncMode := AMode;
FSql := ASql;
FEventHandle := CreateEvent ({*EVENT_MODIFY_STATE + SYNCHRONIZE*}nil, False, False, PChar(FEventName));
case AMode of
MQM_SYNC:
begin
// create mutex
EventHandle := CreateEvent (nil,False,False,PChar(FEventName));
// exec query
debug(Format('qry: Starting query thread %d', [FQueryThread.ThreadID]));
FQueryThread.Resume();

View File

@ -161,14 +161,13 @@ var
h : THandle;
begin
// trigger query finished event
if (FSyncMode=MQM_SYNC) and (AEvent=MQE_FREED) then
begin
h := OpenEvent (EVENT_ALL_ACCESS,False,PChar(TMysqlQuery(FOwner).EventName));
if h<>0 then
SetEvent (h);
end;
if AEvent = MQE_FINISHED then begin
// trigger query finished event
h := OpenEvent (EVENT_MODIFY_STATE,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]));
CloseHandle(h);
end;
case TMysqlQuery(FOwner).NotificationMode of
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]));
qr := AssembleResult();
TMysqlQuery(FOwner).SetThreadResult(qr);
debug('qry: Signalling completion via message.');
PostMessage(FNotifyWndHandle,WM_MYSQL_THREAD_NOTIFY,Integer(FOwner),AEvent);
end;
@ -234,11 +234,11 @@ begin
end else begin
try
r := RunDataQuery (FSql,TDataSet(q),ex,FCallback);
if r then begin
//if r then begin
//if q.State=dsBrowse then begin
// WTF?
//end;
end;
//end;
TMysqlQuery(FOwner).SetMysqlDataset(q);
if r then SetState (MQR_SUCCESS,'SUCCESS')