FireDAC Advantage DB连接类型

时间:2018-03-25 16:15:39

标签: database delphi firedac advantage-database-server

我正在考虑从Advantage Native Delphi组件迁移到FireDAC。我一直在寻找一种方法来确定如何使用FireDAC来确定用于连接服务器的方法 - 远程,本地,AIS(Internet)。

我会寻找相当于TAdsConnection.ConnectionType。

由于 加里康利

1 个答案:

答案 0 :(得分:0)

The function you're looking for is called AdsGetConnectionType. Its import you can find declared in the FireDAC.Phys.ADSCli module, but it's not used anywhere.

But it's not so difficult to get its address and call it by yourself. For example (not a good one):

uses
  FireDAC.Stan.Consts, FireDAC.Phys.ADSCli, FireDAC.Phys.ADSWrapper;

var
  FTAdsGetConnectionType: TAdsGetConnectionType = nil;

type
  TADSLib = class(FireDAC.Phys.ADSWrapper.TADSLib)
  end;

function GetConnectionType(Connection: TFDConnection): Word;
const
  AdsGetConnectionTypeName = 'AdsGetConnectionType';
var
  CliLib: TADSLib;
  CliCon: TADSConnection;
  Status: UNSIGNED32;
  Output: UNSIGNED16;
begin
  Result := 0;
  CliCon := TADSConnection(Connection.CliObj);
  CliLib := TADSLib(CliCon.Lib);

  if not Assigned(FTAdsGetConnectionType) then
    FTAdsGetConnectionType := CliLib.GetProc(AdsGetConnectionTypeName);

  if Assigned(FTAdsGetConnectionType) then
  begin
    Status := FTAdsGetConnectionType(CliCon.Handle, @Output);
    if Status = AE_SUCCESS then
      Result := Word(Output)
    else
      FDException(CliLib.OwningObj, EADSNativeException.Create(Status, CliLib, nil),
        {$IFDEF FireDAC_Monitor}True{$ELSE}False{$ENDIF});
  end
  else
    FDException(CliLib.OwningObj, [S_FD_LPhys, CliLib.DriverID],
      er_FD_AccCantGetLibraryEntry, [AdsGetConnectionTypeName]);
end;

Possible usage:

case GetConnectionType(FDConnection1) of
  ADS_AIS_SERVER: ShowMessage('AIS server');
  ADS_LOCAL_SERVER: ShowMessage('Local server');
  ADS_REMOTE_SERVER: ShowMessage('Remove server');
end;