From 5a55f340c6eaecd0f4bca9df7e1b1bfc0d38e4dc Mon Sep 17 00:00:00 2001 From: Ansgar Becker Date: Fri, 22 Nov 2019 20:00:22 +0100 Subject: [PATCH] Let TConnectionParameters.NetTypeName and TConnectionParameters.IsCompatibleToWin10S rely on a correctly set FNetType property. So we can safely use GetNetTypeGroup on it, and need less parameter passing. Closes #812. The default FNetType should probably not be ntMySQL_TCPIP any longer, so such bugs get seen earlier. --- source/connections.pas | 5 +++-- source/dbconnection.pas | 19 ++++++++++--------- source/main.pas | 4 ++-- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/source/connections.pas b/source/connections.pas index f1e9b4cf..1ef2ed39 100644 --- a/source/connections.pas +++ b/source/connections.pas @@ -257,8 +257,9 @@ begin comboNetType.Clear; Params := TConnectionParameters.Create; for nt:=Low(nt) to High(nt) do begin - NetTypeStr := Params.NetTypeName(nt, True); - if RunningOnWindows10S and (not Params.IsCompatibleToWin10S(nt)) then begin + Params.NetType := nt; + NetTypeStr := Params.NetTypeName(True); + if RunningOnWindows10S and (not Params.IsCompatibleToWin10S) then begin NetTypeStr := NetTypeStr + ' ['+_('Does not work on Windows 10 S')+']'; end; comboNetType.Items.Add(NetTypeStr); diff --git a/source/dbconnection.pas b/source/dbconnection.pas index 54a17c65..788cb603 100644 --- a/source/dbconnection.pas +++ b/source/dbconnection.pas @@ -225,8 +225,8 @@ type procedure SaveToRegistry; function CreateConnection(AOwner: TComponent): TDBConnection; function CreateQuery(Connection: TDbConnection): TDBQuery; - function NetTypeName(NetType: TNetType; LongFormat: Boolean): String; - class function IsCompatibleToWin10S(NetType: TNetType): Boolean; + function NetTypeName(LongFormat: Boolean): String; + function IsCompatibleToWin10S: Boolean; function GetNetTypeGroup: TNetTypeGroup; function IsMySQL: Boolean; function IsMSSQL: Boolean; @@ -1273,10 +1273,11 @@ begin end; -function TConnectionParameters.NetTypeName(NetType: TNetType; LongFormat: Boolean): String; +function TConnectionParameters.NetTypeName(LongFormat: Boolean): String; var Prefix: String; begin + // Return the name of a net type, either in short or long format case NetTypeGroup of ngMySQL: begin if IsMariaDB then @@ -1306,7 +1307,7 @@ begin end; case LongFormat of - True: case NetType of + True: case FNetType of ntMySQL_TCPIP: Result := Prefix+' (TCP/IP)'; ntMySQL_NamedPipe: @@ -1339,10 +1340,10 @@ begin end; -class function TConnectionParameters.IsCompatibleToWin10S(NetType: TNetType): Boolean; +function TConnectionParameters.IsCompatibleToWin10S: Boolean; begin // Using plink on 10S is not possible - Result := (NetType <> ntMySQL_SSHtunnel) and (NetType <> ntPgSQL_SSHtunnel); + Result := (FNetType <> ntMySQL_SSHtunnel) and (FNetType <> ntPgSQL_SSHtunnel); end; @@ -1774,7 +1775,7 @@ begin if Value and (FHandle = nil) then begin // Die if trying to run plink on Win10S - if RunningOnWindows10S and (not FParameters.IsCompatibleToWin10S(FParameters.NetType)) then begin + if RunningOnWindows10S and (not FParameters.IsCompatibleToWin10S) then begin raise EDbError.Create(_('The network type defined for this session is not compatible to your Windows 10 S')); end; @@ -2269,7 +2270,7 @@ begin // Prepare connection if FParameters.Password <> '' then UsingPass := 'Yes' else UsingPass := 'No'; Log(lcInfo, f_('Connecting to %s via %s, username %s, using password: %s ...', - [FParameters.Hostname, FParameters.NetTypeName(FParameters.NetType, True), FParameters.Username, UsingPass] + [FParameters.Hostname, FParameters.NetTypeName(True), FParameters.Username, UsingPass] )); case Parameters.NetTypeGroup of @@ -5134,7 +5135,7 @@ begin Result := TStringList.Create; if Assigned(Parameters) then begin Result.Values[_('Host')] := Parameters.Hostname; - Result.Values[_('Network type')] := Parameters.NetTypeName(Parameters.NetType, True); + Result.Values[_('Network type')] := Parameters.NetTypeName(True); end; Ping(False); Result.Values[_('Connected')] := EvalBool(FActive); diff --git a/source/main.pas b/source/main.pas index d25ad359..e427c18a 100644 --- a/source/main.pas +++ b/source/main.pas @@ -8714,7 +8714,7 @@ begin InvalidateVT(ListTables, VTREE_NOTLOADED, True); tabHost.Caption := _('Host')+': '+StrEllipsis(FActiveDbObj.Connection.Parameters.HostName, 20); tabDatabase.Caption := _('Database')+': '+StrEllipsis(FActiveDbObj.Connection.Database, 20); - ShowStatusMsg(FActiveDbObj.Connection.Parameters.NetTypeName(FActiveDbObj.Connection.Parameters.NetType, False)+' '+FActiveDbObj.Connection.ServerVersionStr, 3); + ShowStatusMsg(FActiveDbObj.Connection.Parameters.NetTypeName(False)+' '+FActiveDbObj.Connection.ServerVersionStr, 3); end else begin LogSQL('DBtreeFocusChanged without node.', lcDebug); FreeAndNil(FActiveDbObj); @@ -10185,7 +10185,7 @@ begin and (Conn <> nil) and (not Conn.Parameters.IsMySQL) then begin vt.Clear; - vt.EmptyListMessage := f_('Not available on %s', [Conn.Parameters.NetTypeName(Conn.Parameters.NetType, False)]); + vt.EmptyListMessage := f_('Not available on %s', [Conn.Parameters.NetTypeName(False)]); vt.Tag := VTREE_LOADED; Exit; end;