4

我与 Firebird 和 Delphi 合作,我想通过有线压缩实现通过 Internet 的访问;但我无法激活它。

我已按照本文档中的步骤获取新参数(我能找到的少数参数之一) 如何使用 FireDAC 在 Firebird 3.0 上启用 WireCompression

在测试中,我使用 Windows server 2012 R2 Firebird:Firebird-3.0.4.33054_0_Win32(32 bits) 也复制到可执行文件夹。fbclient.dll zlib1.dll(同上服务器和客户端)使用wirecompression = true 创建了firebird.conf。我在应用程序的 Firedac 中给出了 wirecompression=true 。

为什么我无法激活 P15:CZ 压缩?

Sending connection info for the example:
================================
Connection definition parameters
================================
DriverID=FB
Database=miservidor001:C:\sysdat\C100\gestdat03.fdb
User_Name=SYSDBA
PassWord=*****
WireCompression=true
================================
FireDAC info
================================
Tool = RAD Studio 10.2
FireDAC = 16.0.0 (Build 88974)
Platform = Windows 32 bit
Defines = FireDAC_NOLOCALE_META;FireDAC_MONITOR
================================
Client info
================================
Loading driver FB ...
Brand = Firebird
Client version = 300049900
Client DLL name = C:\APPS\WC01\fbclient.dll
================================
Session info
================================
Current catalog = 
Current schema = 
Server version = WI-V3.0.4.33054 Firebird 3.0
WI-V3.0.4.33054 Firebird 3.0/tcp (WIN-2012LAGO003)/P15:C
WI-V3.0.4.33054 Firebird 3.0/tcp (nucleo)/P15:C'
4

2 回答 2

5

注意:我不知道 Delphi 和 FireDAC,这个答案是基于 Firebird 的一般行为和我维护其 JDBC 驱动程序(Jaybird)的经验。因此,可能有专门针对 FireDAC/Delphi 的更好答案。

启用或禁用线路压缩完全由客户端决定,而不是由服务器决定。这意味着服务器的配置不是必需的,也没有任何影响,除非服务器本身充当客户端,例如使用execute statement ... on external datasource.

为了能够使用线压缩,您需要三件事:

  1. fbclient.dll
  2. zlib1.dll(在与 相同的位置fbclient.dll,或在搜索路径上)
  3. 为客户端启用线路压缩的配置

第 3 点可能是您的问题:我不确定 FireDAC 是否具有WireCompression实际启用线压缩的连接属性。

我知道为客户端启用线路压缩的两种方法:

  1. 在与您的应用程序使用的firebird.conf目录相同的目录中创建一个。fbclient.dll在此配置文件中,放置请求的配置选项(每行一个):

    WireCompression = true
    # maybe other config lines (eg AuthClient, WireCrypt, etc)
    
  2. 无需创建文件,而是在(int 87) 数据库参数项firebird.conf中传递配置(使用换行符分隔配置选项) 。isc_dpb_config

    firebird.conf该值与上一个选项中的文件内容相同。如果客户端使用旧的数据库参数缓冲区格式(其中字符串最大 255 字节)并且您想要传递(很多)更多配置选项,这可能会遇到大小问题。

选项 1 可能是最简单的,适用于所有框架。选项 2 取决于框架或驱动程序是否公开数据库参数缓冲区,或者它是否具有映射到isc_dpb_config.

例如,在使用 Jaybird 的 Java 中,您可以使用以下命令启用压缩(仅在使用本机连接时):

Properties props = new Properties();
props.setProperty("user", "sysdba");
props.setProperty("password", "masterkey");
props.setProperty("config", "WireCompression=true");

try (var connection = DriverManager.getConnection(
        "jdbc:firebirdsql:native:localhost:D:/data/db/fb3/fb3testdatabase.fdb", props)) {

    FirebirdConnection fbCon = connection.unwrap(FirebirdConnection.class);
    FbDatabase fbDatabase = fbCon.getFbDatabase();
    System.out.println(fbDatabase.getServerVersion());

} catch (SQLException e) {
    e.printStackTrace();
}

这会打印出来WI-V3.0.4.33054 Firebird 3.0,WI-V3.0.4.33054 Firebird 3.0/tcp (host)/P15:CZ,WI-V3.0.4.33054 Firebird 3.0/tcp (host)/P15:CZ(注意这是<server version>,<server protocol info>,<client protocol info>)。ZinP15:CZ表示连接是 zlib 压缩的(连接C是加密的)。

在这里,该config属性是 的别名isc_dpb_config

于 2018-12-28T10:01:53.620 回答
4

马克的回答是整个互联网上关于这个问题的最好的(也可能是唯一的)信息来源。祝你在 Delphi、FireDAC 或 Firebird 文档中找到关于他所说的任何内容。

根据他的回答,以下是使用 FireDAC 使用 Firebird 线压缩所需的内容:

  • 您需要 Delphi Rio 10.3.1 (Update 1) 或更高版本。只有在这个版本中,config低级参数(见下文)才被添加到 FireDAC。

  • 您必须传递WireCompression=true低级 config连接参数。这不是TFDConnection.Params(高级)。

    • 要做到这一点,您需要将 的IBAdvanced属性设置TFDPhysFBConnectionDefParamsconfig=WireCompression=true(是的!算了!)

    • 代码:

      FDConnection1.DriverName := '​FB';
      with FDConnection1.Params as TFDPhysFBConnectionDefParams do   
      begin
        Server := '...';
        Database := '...';
        UserName := '...';
        Password := '...';
        IBAdvanced := 'config=WireCompression=true';
      end;
      FDConnection1.Connected := True;
      
    • 使用连接定义文件

      [FB_Demo]
      DriverID=FB
      Server=...
      Database=...
      User_Name=...
      Password=...
      IBAdvanced=config=WireCompression=true
      
  • 你需要zlib1.dll在你的fbclient.dll. 这里的问题是 Firebird 发行版的zlib1.dll文件C:\Program Files\Firebird\Firebird_3_0\WOW64夹中没有 32 位版本。所以:

    • 如果您的应用程序是 64 位的,您可能没问题。只需同时使用fbclient.dllzlib1.dll从您的C:\Program Files\Firebird\Firebird_3_0文件夹中使用。

    • 如果您的应用程序是 32 位的,您必须从 32 位 Firebird 发行版下载32 位版本。zlib1.dll将它与fbclient.dll您在您的C:\Program Files\Firebird\Firebird_3_0\WOW64(包含 32 位库)中找到的一起使用。

在 Firebird 3.0.4 或更高版本中,您可以使用WIRE_COMPRESSED上下文变量来检查连接是否按预期建立:

SELECT
  RDB$GET_CONTEXT('SYSTEM', 'WIRE_COMPRESSED') wire_compressed
FROM
  rdb$database

如果当前连接被压缩,这将返回 TRUE。

于 2019-08-22T04:49:29.043 回答