diff --git a/source/dbconnection.pas b/source/dbconnection.pas index b076c4a6..84272000 100644 --- a/source/dbconnection.pas +++ b/source/dbconnection.pas @@ -990,7 +990,7 @@ end; procedure TAdoDBConnection.SetActive(Value: Boolean); var - tmpdb, Error, NetLib, DataSource: String; + tmpdb, tmp, Error, NetLib, DataSource: String; rx: TRegExpr; i: Integer; begin @@ -1040,11 +1040,15 @@ begin // CurCharset := CharacterSet; // Log(lcDebug, 'Characterset: '+CurCharset); FIsUnicode := True; - FServerStarted := FConnectionStarted - StrToIntDef(GetVar('SELECT DATEDIFF(SECOND, '+QuoteIdent('login_time')+', CURRENT_TIMESTAMP) FROM '+QuoteIdent('dbo')+'.'+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 - // Express Edition with Advanced Services on Windows NT 6.1 (Build 7600: ) + tmp := GetVar('SELECT DATEDIFF(SECOND, '+QuoteIdent('login_time')+', CURRENT_TIMESTAMP) FROM '+QuoteIdent('sys')+'.'+QuoteIdent('sysprocesses')+' WHERE '+QuoteIdent('spid')+'=1'); + if tmp <> '' then + FServerStarted := FConnectionStarted - MakeInt(tmp) + else + FServerStarted := -1; + // Microsoft SQL Server 2008 R2 (RTM) - 10.50.1600.1 (Intel X86) + // Apr 2 2010 15:53:02 + // Copyright (c) Microsoft Corporation + // Express Edition with Advanced Services on Windows NT 6.1 (Build 7600: ) FServerVersionUntouched := Trim(GetVar('SELECT @@VERSION')); rx := TRegExpr.Create; rx.ModifierI := False; @@ -2184,8 +2188,11 @@ end; function TDBConnection.GetServerUptime: Integer; begin - // Return server uptime in seconds - Result := Integer(GetTickCount div 1000) - FServerStarted; + // Return server uptime in seconds. Return -1 if unknown. + if FServerStarted > 0 then + Result := Integer(GetTickCount div 1000) - FServerStarted + else + Result := FServerStarted; end; diff --git a/source/helpers.pas b/source/helpers.pas index e974320b..705fa156 100644 --- a/source/helpers.pas +++ b/source/helpers.pas @@ -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: Cardinal; DisplaySeconds: Boolean): String; + function FormatTimeNumber(Seconds: Int64; DisplaySeconds: Boolean): String; function GetTempDir: String; procedure SetWindowSizeGrip(hWnd: HWND; Enable: boolean); procedure SaveUnicodeFile(Filename: String; Text: String); @@ -1062,27 +1062,31 @@ end; @param Cardinal Number of seconds @result String 12:34:56 } -function FormatTimeNumber(Seconds: Cardinal; DisplaySeconds: Boolean): String; +function FormatTimeNumber(Seconds: Int64; DisplaySeconds: Boolean): String; var d, h, m, s : Integer; 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]); + if Seconds < 0 then begin + Result := '(unknown)'; end else begin - if DisplaySeconds then - Result := Format('%.2d:%.2d:%.2d', [h, m, s]) - else - Result := Format('%.2d:%.2d h', [h, m]) + 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; end; end;