Skip to content
Permalink
Browse files

Let TConnectionParameters.NetTypeName and TConnectionParameters.IsCom…

…patibleToWin10S 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.
  • Loading branch information
ansgarbecker committed Nov 22, 2019
1 parent 96aca7f commit 5a55f340c6eaecd0f4bca9df7e1b1bfc0d38e4dc
Showing with 15 additions and 13 deletions.
  1. +3 −2 source/connections.pas
  2. +10 −9 source/dbconnection.pas
  3. +2 −2 source/main.pas
@@ -257,8 +257,9 @@ procedure Tconnform.FormCreate(Sender: TObject);
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);
@@ -225,8 +225,8 @@ TConnectionParameters = class(TObject)
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 @@ function TConnectionParameters.CreateQuery(Connection: TDbConnection): TDBQuery;
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 @@ function TConnectionParameters.NetTypeName(NetType: TNetType; LongFormat: Boolea
end;

case LongFormat of
True: case NetType of
True: case FNetType of
ntMySQL_TCPIP:
Result := Prefix+' (TCP/IP)';
ntMySQL_NamedPipe:
@@ -1339,10 +1340,10 @@ function TConnectionParameters.NetTypeName(NetType: TNetType; LongFormat: Boolea
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 @@ procedure TMySQLConnection.SetActive( Value: Boolean );
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 @@ procedure TDBConnection.DoBeforeConnect;
// 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 @@ function TDBConnection.ConnectionInfo: TStringList;
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);
@@ -8714,7 +8714,7 @@ procedure TMainForm.DBtreeFocusChanged(Sender: TBaseVirtualTree; Node: PVirtualN
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 @@ procedure TMainForm.HostListBeforePaint(Sender: TBaseVirtualTree; TargetCanvas:
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;

0 comments on commit 5a55f34

Please sign in to comment.
You can’t perform that action at this time.