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