mirror of
https://github.com/HeidiSQL/HeidiSQL.git
synced 2025-08-16 03:30:50 +08:00
Issue #2550: Do not report unknown uptime if server was started before client machine. Broken in r4020.
This commit is contained in:
@ -215,7 +215,7 @@ type
|
|||||||
private
|
private
|
||||||
FActive: Boolean;
|
FActive: Boolean;
|
||||||
FConnectionStarted: Integer;
|
FConnectionStarted: Integer;
|
||||||
FServerStarted: Integer;
|
FServerUptime: Integer;
|
||||||
FParameters: TConnectionParameters;
|
FParameters: TConnectionParameters;
|
||||||
FLoginPromptDone: Boolean;
|
FLoginPromptDone: Boolean;
|
||||||
FDatabase: String;
|
FDatabase: String;
|
||||||
@ -948,7 +948,7 @@ begin
|
|||||||
Log(lcDebug, 'Characterset: '+CurCharset);
|
Log(lcDebug, 'Characterset: '+CurCharset);
|
||||||
FIsUnicode := CurCharset = 'utf8';
|
FIsUnicode := CurCharset = 'utf8';
|
||||||
FConnectionStarted := GetTickCount div 1000;
|
FConnectionStarted := GetTickCount div 1000;
|
||||||
FServerStarted := FConnectionStarted - StrToIntDef(GetVar('SHOW STATUS LIKE ''Uptime''', 1), 1);
|
FServerUptime := StrToIntDef(GetVar('SHOW STATUS LIKE ''Uptime''', 1), -1);
|
||||||
FServerVersionUntouched := DecodeAPIString(mysql_get_server_info(FHandle));
|
FServerVersionUntouched := DecodeAPIString(mysql_get_server_info(FHandle));
|
||||||
Vars := GetServerVariables;
|
Vars := GetServerVariables;
|
||||||
while not Vars.Eof do begin
|
while not Vars.Eof do begin
|
||||||
@ -990,7 +990,7 @@ end;
|
|||||||
|
|
||||||
procedure TAdoDBConnection.SetActive(Value: Boolean);
|
procedure TAdoDBConnection.SetActive(Value: Boolean);
|
||||||
var
|
var
|
||||||
tmpdb, tmp, Error, NetLib, DataSource: String;
|
tmpdb, Error, NetLib, DataSource: String;
|
||||||
rx: TRegExpr;
|
rx: TRegExpr;
|
||||||
i: Integer;
|
i: Integer;
|
||||||
begin
|
begin
|
||||||
@ -1040,11 +1040,7 @@ begin
|
|||||||
// CurCharset := CharacterSet;
|
// CurCharset := CharacterSet;
|
||||||
// Log(lcDebug, 'Characterset: '+CurCharset);
|
// Log(lcDebug, 'Characterset: '+CurCharset);
|
||||||
FIsUnicode := True;
|
FIsUnicode := True;
|
||||||
tmp := GetVar('SELECT DATEDIFF(SECOND, '+QuoteIdent('login_time')+', CURRENT_TIMESTAMP) FROM '+QuoteIdent('master')+'.'+QuoteIdent('sys')+'.'+QuoteIdent('sysprocesses')+' WHERE '+QuoteIdent('spid')+'=1');
|
FServerUptime := StrToIntDef(GetVar('SELECT DATEDIFF(SECOND, '+QuoteIdent('login_time')+', CURRENT_TIMESTAMP) FROM '+QuoteIdent('master')+'.'+QuoteIdent('sys')+'.'+QuoteIdent('sysprocesses')+' WHERE '+QuoteIdent('spid')+'=1'), -1);
|
||||||
if tmp <> '' then
|
|
||||||
FServerStarted := FConnectionStarted - MakeInt(tmp)
|
|
||||||
else
|
|
||||||
FServerStarted := -1;
|
|
||||||
// Microsoft SQL Server 2008 R2 (RTM) - 10.50.1600.1 (Intel X86)
|
// Microsoft SQL Server 2008 R2 (RTM) - 10.50.1600.1 (Intel X86)
|
||||||
// Apr 2 2010 15:53:02
|
// Apr 2 2010 15:53:02
|
||||||
// Copyright (c) Microsoft Corporation
|
// Copyright (c) Microsoft Corporation
|
||||||
@ -2189,10 +2185,10 @@ end;
|
|||||||
function TDBConnection.GetServerUptime: Integer;
|
function TDBConnection.GetServerUptime: Integer;
|
||||||
begin
|
begin
|
||||||
// Return server uptime in seconds. Return -1 if unknown.
|
// Return server uptime in seconds. Return -1 if unknown.
|
||||||
if FServerStarted > 0 then
|
if FServerUptime > 0 then
|
||||||
Result := Integer(GetTickCount div 1000) - FServerStarted
|
Result := FServerUptime + (Integer(GetTickCount div 1000) - FConnectionStarted)
|
||||||
else
|
else
|
||||||
Result := FServerStarted;
|
Result := -1;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
@ -132,7 +132,7 @@ type
|
|||||||
function getFirstWord( text: String ): String;
|
function getFirstWord( text: String ): String;
|
||||||
function FormatByteNumber( Bytes: Int64; Decimals: Byte = 1 ): String; Overload;
|
function FormatByteNumber( Bytes: Int64; Decimals: Byte = 1 ): String; Overload;
|
||||||
function FormatByteNumber( Bytes: String; Decimals: Byte = 1 ): String; Overload;
|
function FormatByteNumber( Bytes: String; Decimals: Byte = 1 ): String; Overload;
|
||||||
function FormatTimeNumber(Seconds: Int64; DisplaySeconds: Boolean): String;
|
function FormatTimeNumber(Seconds: Cardinal; DisplaySeconds: Boolean): String;
|
||||||
function GetTempDir: String;
|
function GetTempDir: String;
|
||||||
procedure SetWindowSizeGrip(hWnd: HWND; Enable: boolean);
|
procedure SetWindowSizeGrip(hWnd: HWND; Enable: boolean);
|
||||||
procedure SaveUnicodeFile(Filename: String; Text: String);
|
procedure SaveUnicodeFile(Filename: String; Text: String);
|
||||||
@ -1062,31 +1062,27 @@ end;
|
|||||||
@param Cardinal Number of seconds
|
@param Cardinal Number of seconds
|
||||||
@result String 12:34:56
|
@result String 12:34:56
|
||||||
}
|
}
|
||||||
function FormatTimeNumber(Seconds: Int64; DisplaySeconds: Boolean): String;
|
function FormatTimeNumber(Seconds: Cardinal; DisplaySeconds: Boolean): String;
|
||||||
var
|
var
|
||||||
d, h, m, s : Integer;
|
d, h, m, s : Integer;
|
||||||
begin
|
begin
|
||||||
if Seconds < 0 then begin
|
s := Seconds;
|
||||||
Result := '(unknown)';
|
d := s div (60*60*24);
|
||||||
|
s := s mod (60*60*24);
|
||||||
|
h := s div (60*60);
|
||||||
|
s := s mod (60*60);
|
||||||
|
m := s div 60;
|
||||||
|
s := s mod 60;
|
||||||
|
if d > 0 then begin
|
||||||
|
if DisplaySeconds then
|
||||||
|
Result := Format('%d days, %.2d:%.2d:%.2d', [d, h, m, s])
|
||||||
|
else
|
||||||
|
Result := Format('%d days, %.2d:%.2d h', [d, h, m]);
|
||||||
end else begin
|
end else begin
|
||||||
s := Seconds;
|
if DisplaySeconds then
|
||||||
d := s div (60*60*24);
|
Result := Format('%.2d:%.2d:%.2d', [h, m, s])
|
||||||
s := s mod (60*60*24);
|
else
|
||||||
h := s div (60*60);
|
Result := Format('%.2d:%.2d h', [h, m])
|
||||||
s := s mod (60*60);
|
|
||||||
m := s div 60;
|
|
||||||
s := s mod 60;
|
|
||||||
if d > 0 then begin
|
|
||||||
if DisplaySeconds then
|
|
||||||
Result := Format('%d days, %.2d:%.2d:%.2d', [d, h, m, s])
|
|
||||||
else
|
|
||||||
Result := Format('%d days, %.2d:%.2d h', [d, h, m]);
|
|
||||||
end else begin
|
|
||||||
if DisplaySeconds then
|
|
||||||
Result := Format('%.2d:%.2d:%.2d', [h, m, s])
|
|
||||||
else
|
|
||||||
Result := Format('%.2d:%.2d h', [h, m])
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -4973,12 +4973,17 @@ end;
|
|||||||
procedure TMainForm.TimerHostUptimeTimer(Sender: TObject);
|
procedure TMainForm.TimerHostUptimeTimer(Sender: TObject);
|
||||||
var
|
var
|
||||||
Conn: TDBConnection;
|
Conn: TDBConnection;
|
||||||
|
Uptime: Integer;
|
||||||
begin
|
begin
|
||||||
// Display server uptime
|
// Display server uptime
|
||||||
Conn := ActiveConnection;
|
Conn := ActiveConnection;
|
||||||
if Assigned(Conn) then
|
if Assigned(Conn) then begin
|
||||||
ShowStatusMsg('Uptime: '+FormatTimeNumber(Conn.ServerUptime, False), 4)
|
Uptime := Conn.ServerUptime;
|
||||||
else
|
if Uptime >= 0 then
|
||||||
|
ShowStatusMsg('Uptime: '+FormatTimeNumber(Conn.ServerUptime, False), 4)
|
||||||
|
else
|
||||||
|
ShowStatusMsg('Uptime: unknown', 4)
|
||||||
|
end else
|
||||||
ShowStatusMsg('', 4);
|
ShowStatusMsg('', 4);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user