FireDAC ResultConnectionDef and information about Server and Port

FireDAC ResultConnectionDef and information about Server and Port



DelphiXE 10.2.2



Was checking here old http://codeverge.com topic where back then was working, but now with



ResultConnectionDef for getting information about established connection (Server and Port).



ZeosLib (ZeosDBO) code:


procedure TMainForm.UpdateCaption;
begin
Caption := Format('Truice %s - Connection: %s:%d / %s', [VERSION_EXE, MyTrinityConnection.HostName, MyTrinityConnection.Port, GetDBVersion]);
Application.Title := Caption;
end;



With FireDac:


uses FireDAC.Phys.MySQLDef, FireDAC.Stan.Intf, FireDAC.Stan.Option, FireDAC.Stan.Error, FireDAC.UI.Intf, FireDAC.Phys.Intf, FireDAC.Stan.Def, FireDAC.Stan.Pool, FireDAC.Stan.Async, FireDAC.Phys, FireDAC.Phys.MySQL, FireDAC.VCLUI.Wait, FireDAC.Comp.UI, FireDAC.Comp.Client, FireDAC.Stan.Param, FireDAC.DatS, FireDAC.DApt.Intf, FireDAC.DApt, FireDAC.Comp.DataSet, FireDAC.Comp.Script, FireDAC.Comp.ScriptCommands, FireDAC.Stan.Util;

procedure TMainForm.UpdateCaption;
begin
Caption := Format('Truice %s - Connection: %s:%d / %s', [VERSION_EXE, MyTrinityConnection.ResultConnectionDef.Server, MyTrinityConnection.ResultConnectionDef.Port, GetDBVersion]);
Application.Title := Caption;
end;



Result:


'IFDStanConnectionDef' does not contain a member named 'Server'
'IFDStanConnectionDef' does not contain a member named 'Port'



Questions:





Final code after Victorias solution, looks so:


procedure TMainForm.UpdateCaption;
var
Server: string;
Port: Integer;
begin
Server := TFDPhysMySQLConnectionDefParams(MyTrinityConnection.ResultConnectionDef.Params).Server;
Port := TFDPhysMySQLConnectionDefParams(MyTrinityConnection.ResultConnectionDef.Params).Port;
Caption := Format('Truice %s - Connection: %s:%d / %s', [VERSION_EXE, Server, Port, GetDBVersion]);

Application.Title := Caption;
end;




1 Answer
1



Yes, it has been changed. The old variant of the underlying interface (IADStanConnectionDef) was having properties like Server and Port. The new version of this interface
(IFDStanConnectionDef) publishes the Params property which points to specific DBMS parameter collection implementation.



The reason for the change might have been variety of the supported DBMS (some of which has no remote connection).



There are at least two ways to get server and port of the active MySQL connection I'm aware of. The first is using the mentioned ResultConnectionDef and its Params property (FDConnection1 object in both examples is assumed to be connected to MySQL server at the moment), e.g.:


uses
FireDAC.Phys.MySQLDef;

var
Port: Integer;
Server: string;
begin
Port := TFDPhysMySQLConnectionDefParams(FDConnection1.ResultConnectionDef.Params).Port;
Server := TFDPhysMySQLConnectionDefParams(FDConnection1.ResultConnectionDef.Params).Server;
...
end;



Another option for MySQL is getting these information from TMySQLSession session object, e.g.:


uses
FireDAC.Phys.MySQLWrapper;

var
Port: Cardinal;
Server: string;
begin
Port := TMySQLSession(FDConnection1.ConnectionIntf.CliObj).Port;
Server := TMySQLSession(FDConnection1.ConnectionIntf.CliObj).Host;
...
end;



Both above ways equal (at this time) because internally the TMySQLSession receives host and port from the connection definition parameters (which means what you set is what you get just like ZEOS is doing with their properties).



If you wanted to have host and port information as reported by MySQL, you could fetch the values of the hostname and port system variables.





Just a reminder: "Params.Values['Port'] and ['Hostname'] are empty with default ports! I.e. for Mysql if 3306 port is set, Params Port value will be nonexistant but it will be present if You change port to e.g 3310
– Vancalar
Aug 22 at 7:49





@Vancalar, that's what I've covered by "what you set is what you get".
– Victoria
Aug 23 at 17:26






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Crossroads (UK TV series)

ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế