mirror of
https://github.com/HeidiSQL/HeidiSQL.git
synced 2026-03-13 09:24:25 +08:00
Fix too short SQL query timer, used in query tabs: Also count network time consumed by mysql_store_result(), display that time separately.
This commit is contained in:
@@ -3912,7 +3912,7 @@ procedure TMainForm.ExecSQLClick(Sender: TObject; Selection: Boolean=false; Curr
|
||||
var
|
||||
SQL: TWideStringList;
|
||||
i, j, QueryCount: Integer;
|
||||
SQLTime: Cardinal;
|
||||
SQLTime, SQLNetTime: Cardinal;
|
||||
Results: TMySQLQuery;
|
||||
ColName, Text, LB: WideString;
|
||||
col: TVirtualTreeColumn;
|
||||
@@ -3946,6 +3946,7 @@ begin
|
||||
EnableProgressBar(SQL.Count);
|
||||
showstatus('Executing SQL...');
|
||||
SQLtime := 0;
|
||||
SQLNetTime := 0;
|
||||
QueryCount := 0;
|
||||
for i:=0 to SQL.Count-1 do begin
|
||||
ProgressBarStatus.StepIt;
|
||||
@@ -3957,6 +3958,7 @@ begin
|
||||
else
|
||||
Results := Connection.GetResults(SQL[i]);
|
||||
Inc(SQLtime, Connection.LastQueryDuration);
|
||||
Inc(SQLNetTime, Connection.LastQueryNetworkDuration);
|
||||
Inc(QueryCount);
|
||||
if Assigned(Results) and Results.HasResult then
|
||||
ResultLabel.Caption := FormatNumber(Results.ColumnCount) +' column(s) x '+FormatNumber(Results.RecordCount) +' row(s) in last result set.'
|
||||
@@ -3983,6 +3985,8 @@ begin
|
||||
else
|
||||
cap := cap + ' queries';
|
||||
cap := cap + ': '+FormatNumber(SQLTime/1000, 3) +' sec.';
|
||||
if SQLNetTime > 0 then
|
||||
cap := cap + ' (+ '+FormatNumber(SQLNetTime/1000, 3) +' sec. network)';
|
||||
ResultLabel.Caption := ResultLabel.Caption + cap;
|
||||
end;
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ type
|
||||
FRowsFound: Int64;
|
||||
FRowsAffected: Int64;
|
||||
FServerVersionUntouched: String;
|
||||
FLastQueryStart, FLastQueryEnd: Cardinal;
|
||||
FLastQueryDuration, FLastQueryNetworkDuration: Cardinal;
|
||||
FIsUnicode: Boolean;
|
||||
FTableEngines: TStringList;
|
||||
FTableEngineDefault: String;
|
||||
@@ -96,7 +96,6 @@ type
|
||||
function GetLastError: WideString;
|
||||
function GetServerVersionStr: String;
|
||||
function GetServerVersionInt: Integer;
|
||||
function GetLastQueryDuration: Cardinal;
|
||||
function GetTableEngines: TStringList;
|
||||
function GetCollationTable: TMySQLQuery;
|
||||
function GetCollationList: TStringList;
|
||||
@@ -129,7 +128,8 @@ type
|
||||
property Capabilities: TMySQLServerCapabilities read FCapabilities;
|
||||
property RowsFound: Int64 read FRowsFound;
|
||||
property RowsAffected: Int64 read FRowsAffected;
|
||||
property LastQueryDuration: Cardinal read GetLastQueryDuration;
|
||||
property LastQueryDuration: Cardinal read FLastQueryDuration;
|
||||
property LastQueryNetworkDuration: Cardinal read FLastQueryNetworkDuration;
|
||||
property IsUnicode: Boolean read FIsUnicode;
|
||||
property TableEngines: TStringList read GetTableEngines;
|
||||
property TableEngineDefault: String read FTableEngineDefault;
|
||||
@@ -202,8 +202,8 @@ begin
|
||||
FRowsFound := 0;
|
||||
FRowsAffected := 0;
|
||||
FConnectionStarted := 0;
|
||||
FLastQueryStart := 0;
|
||||
FLastQueryEnd := 0;
|
||||
FLastQueryDuration := 0;
|
||||
FLastQueryNetworkDuration := 0;
|
||||
FLogPrefix := '';
|
||||
FIsUnicode := False;
|
||||
end;
|
||||
@@ -323,14 +323,16 @@ function TMySQLConnection.Query(SQL: WideString; DoStoreResult: Boolean=False):
|
||||
var
|
||||
querystatus: Integer;
|
||||
NativeSQL: String;
|
||||
TimerStart: Cardinal;
|
||||
begin
|
||||
if not Ping then
|
||||
Active := True;
|
||||
Log(lcSQL, SQL);
|
||||
NativeSQL := UTF8Encode(SQL);
|
||||
FLastQueryStart := GetTickCount;
|
||||
TimerStart := GetTickCount;
|
||||
querystatus := mysql_real_query(FHandle, PChar(NativeSQL), Length(NativeSQL));
|
||||
FLastQueryEnd := GetTickCount;
|
||||
FLastQueryDuration := GetTickCount - TimerStart;
|
||||
FLastQueryNetworkDuration := 0;
|
||||
if querystatus <> 0 then begin
|
||||
Log(lcError, GetLastError);
|
||||
raise Exception.Create(GetLastError);
|
||||
@@ -338,7 +340,9 @@ begin
|
||||
// We must call mysql_store_result() + mysql_free_result() to unblock the connection
|
||||
// See: http://dev.mysql.com/doc/refman/5.0/en/mysql-store-result.html
|
||||
FRowsAffected := mysql_affected_rows(FHandle);
|
||||
TimerStart := GetTickCount;
|
||||
Result := mysql_store_result(FHandle);
|
||||
FLastQueryNetworkDuration := GetTickCount - TimerStart;
|
||||
if Result <> nil then begin
|
||||
FRowsFound := mysql_num_rows(Result);
|
||||
FRowsAffected := 0;
|
||||
@@ -584,12 +588,6 @@ begin
|
||||
end;
|
||||
|
||||
|
||||
function TMySQLConnection.GetLastQueryDuration: Cardinal;
|
||||
begin
|
||||
Result := FLastQueryEnd - FLastQueryStart;
|
||||
end;
|
||||
|
||||
|
||||
function TMySQLConnection.GetCol(SQL: WideString; Column: Integer=0): TWideStringList;
|
||||
var
|
||||
Results: TMySQLQuery;
|
||||
|
||||
Reference in New Issue
Block a user