mirror of
https://github.com/HeidiSQL/HeidiSQL.git
synced 2025-08-18 05:18:33 +08:00
Display server's current date time instead of useless UTC time in status bar
This commit is contained in:
@ -297,8 +297,9 @@ type
|
|||||||
TDBConnection = class(TComponent)
|
TDBConnection = class(TComponent)
|
||||||
private
|
private
|
||||||
FActive: Boolean;
|
FActive: Boolean;
|
||||||
FConnectionStarted: Integer;
|
FConnectionStarted: Cardinal;
|
||||||
FServerUptime: Integer;
|
FServerUptime: Integer;
|
||||||
|
FServerDateTimeOnStartup: String;
|
||||||
FParameters: TConnectionParameters;
|
FParameters: TConnectionParameters;
|
||||||
FLoginPromptDone: Boolean;
|
FLoginPromptDone: Boolean;
|
||||||
FDatabase: String;
|
FDatabase: String;
|
||||||
@ -356,6 +357,7 @@ type
|
|||||||
function GetInformationSchemaObjects: TStringList; virtual;
|
function GetInformationSchemaObjects: TStringList; virtual;
|
||||||
function GetConnectionUptime: Integer;
|
function GetConnectionUptime: Integer;
|
||||||
function GetServerUptime: Integer;
|
function GetServerUptime: Integer;
|
||||||
|
function GetServerNow: TDateTime;
|
||||||
function GetCurrentUserHostCombination: String;
|
function GetCurrentUserHostCombination: String;
|
||||||
function DecodeAPIString(a: AnsiString): String;
|
function DecodeAPIString(a: AnsiString): String;
|
||||||
function ExtractIdentifier(var SQL: String): String;
|
function ExtractIdentifier(var SQL: String): String;
|
||||||
@ -413,6 +415,7 @@ type
|
|||||||
property ThreadId: Int64 read GetThreadId;
|
property ThreadId: Int64 read GetThreadId;
|
||||||
property ConnectionUptime: Integer read GetConnectionUptime;
|
property ConnectionUptime: Integer read GetConnectionUptime;
|
||||||
property ServerUptime: Integer read GetServerUptime;
|
property ServerUptime: Integer read GetServerUptime;
|
||||||
|
property ServerNow: TDateTime read GetServerNow;
|
||||||
property CharacterSet: String read GetCharacterSet write SetCharacterSet;
|
property CharacterSet: String read GetCharacterSet write SetCharacterSet;
|
||||||
property LastErrorCode: Cardinal read GetLastErrorCode;
|
property LastErrorCode: Cardinal read GetLastErrorCode;
|
||||||
property LastError: String read GetLastError;
|
property LastError: String read GetLastError;
|
||||||
@ -1823,6 +1826,7 @@ begin
|
|||||||
FIsSSL := Status.Col(1) <> '';
|
FIsSSL := Status.Col(1) <> '';
|
||||||
Status.Next;
|
Status.Next;
|
||||||
end;
|
end;
|
||||||
|
FServerDateTimeOnStartup := GetVar('SELECT NOW()');
|
||||||
FServerVersionUntouched := DecodeAPIString(mysql_get_server_info(FHandle));
|
FServerVersionUntouched := DecodeAPIString(mysql_get_server_info(FHandle));
|
||||||
Vars := GetSessionVariables(False);
|
Vars := GetSessionVariables(False);
|
||||||
while not Vars.Eof do begin
|
while not Vars.Eof do begin
|
||||||
@ -1958,6 +1962,7 @@ begin
|
|||||||
except
|
except
|
||||||
FServerUptime := -1;
|
FServerUptime := -1;
|
||||||
end;
|
end;
|
||||||
|
FServerDateTimeOnStartup := GetVar('SELECT GETDATE()');
|
||||||
// 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
|
||||||
@ -2053,6 +2058,7 @@ begin
|
|||||||
raise EDatabaseError.Create(Error);
|
raise EDatabaseError.Create(Error);
|
||||||
end;
|
end;
|
||||||
FActive := True;
|
FActive := True;
|
||||||
|
FServerDateTimeOnStartup := GetVar('SELECT NOW()');
|
||||||
FServerVersionUntouched := GetVar('SELECT VERSION()');
|
FServerVersionUntouched := GetVar('SELECT VERSION()');
|
||||||
FConnectionStarted := GetTickCount div 1000;
|
FConnectionStarted := GetTickCount div 1000;
|
||||||
Log(lcInfo, f_('Connected. Thread-ID: %d', [ThreadId]));
|
Log(lcInfo, f_('Connected. Thread-ID: %d', [ThreadId]));
|
||||||
@ -4303,7 +4309,7 @@ begin
|
|||||||
if not FActive then
|
if not FActive then
|
||||||
Result := 0
|
Result := 0
|
||||||
else
|
else
|
||||||
Result := Integer(GetTickCount div 1000) - FConnectionStarted;
|
Result := (GetTickCount div 1000) - FConnectionStarted;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -4311,12 +4317,25 @@ 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 FServerUptime > 0 then
|
if FServerUptime > 0 then
|
||||||
Result := FServerUptime + (Integer(GetTickCount div 1000) - FConnectionStarted)
|
Result := Cardinal(FServerUptime) + ((GetTickCount div 1000) - FConnectionStarted)
|
||||||
else
|
else
|
||||||
Result := -1;
|
Result := -1;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
function TDBConnection.GetServerNow: TDateTime;
|
||||||
|
var
|
||||||
|
d: TDateTime;
|
||||||
|
begin
|
||||||
|
// Return server datetime. Return -1 if unknown.
|
||||||
|
if not FServerDateTimeOnStartup.IsEmpty then begin
|
||||||
|
d := StrToDateTimeDef(FServerDateTimeOnStartup, 0);
|
||||||
|
Result := IncSecond(d, (GetTickCount div 1000) - FConnectionStarted);
|
||||||
|
end else
|
||||||
|
Result := -1;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
function TDBConnection.GetCurrentUserHostCombination: String;
|
function TDBConnection.GetCurrentUserHostCombination: String;
|
||||||
begin
|
begin
|
||||||
// Return current user@host combination, used by various object editors for DEFINER clauses
|
// Return current user@host combination, used by various object editors for DEFINER clauses
|
||||||
|
@ -2243,8 +2243,8 @@ begin
|
|||||||
w1 := CalcPanelWidth(110, 10);
|
w1 := CalcPanelWidth(110, 10);
|
||||||
w2 := CalcPanelWidth(140, 10);
|
w2 := CalcPanelWidth(140, 10);
|
||||||
w3 := CalcPanelWidth(170, 15);
|
w3 := CalcPanelWidth(170, 15);
|
||||||
w4 := CalcPanelWidth(170, 15);
|
w4 := CalcPanelWidth(150, 15);
|
||||||
w5 := CalcPanelWidth(170, 15);
|
w5 := CalcPanelWidth(210, 15);
|
||||||
w6 := CalcPanelWidth(250, 20);
|
w6 := CalcPanelWidth(250, 20);
|
||||||
w0 := StatusBar.Width - w1 - w2 - w3 - w4 - w5 - w6;
|
w0 := StatusBar.Width - w1 - w2 - w3 - w4 - w5 - w6;
|
||||||
StatusBar.Panels[0].Width := w0;
|
StatusBar.Panels[0].Width := w0;
|
||||||
@ -5875,11 +5875,9 @@ procedure TMainForm.TimerHostUptimeTimer(Sender: TObject);
|
|||||||
var
|
var
|
||||||
Conn: TDBConnection;
|
Conn: TDBConnection;
|
||||||
Uptime: Integer;
|
Uptime: Integer;
|
||||||
SystemTime: TSystemTime;
|
ServerNow: TDateTime;
|
||||||
tmp: TDateTime;
|
|
||||||
utcs: String;
|
|
||||||
begin
|
begin
|
||||||
// Display server uptime
|
// Display server uptime and current date time
|
||||||
Conn := ActiveConnection;
|
Conn := ActiveConnection;
|
||||||
if Assigned(Conn) then begin
|
if Assigned(Conn) then begin
|
||||||
Uptime := Conn.ServerUptime;
|
Uptime := Conn.ServerUptime;
|
||||||
@ -5887,15 +5885,16 @@ begin
|
|||||||
ShowStatusMsg(_('Uptime')+': '+FormatTimeNumber(Conn.ServerUptime, False), 4)
|
ShowStatusMsg(_('Uptime')+': '+FormatTimeNumber(Conn.ServerUptime, False), 4)
|
||||||
else
|
else
|
||||||
ShowStatusMsg(_('Uptime')+': '+_('unknown'), 4);
|
ShowStatusMsg(_('Uptime')+': '+_('unknown'), 4);
|
||||||
end else
|
|
||||||
ShowStatusMsg('', 4);
|
|
||||||
|
|
||||||
// Display UTC date/time
|
ServerNow := Conn.ServerNow;
|
||||||
GetSystemTime(SystemTime);
|
if ServerNow >= 0 then
|
||||||
tmp := EncodeDate(SystemTime.wYear, SystemTime.wMonth, SystemTime.wDay) +
|
ShowStatusMsg(f_('Server time: %s', [DateTimeToStr(ServerNow)]), 5)
|
||||||
EncodeTime(SystemTime.wHour, SystemTime.wMinute, SystemTime.wSecond, SystemTime.wMilliseconds);
|
else
|
||||||
DateTimeToString(utcs, 'ddddd t', tmp);
|
ShowStatusMsg(f_('Server time: %s', [_('unknown')]), 5);
|
||||||
ShowStatusMsg('UTC: ' + utcs, 5);
|
end else begin
|
||||||
|
ShowStatusMsg('', 4);
|
||||||
|
end;
|
||||||
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user