Chapter 2. Using the pgExpress Driver

1. Installation

The pgExpress Driver PostgreSQL dbExpress™ Driver installation procedure is similar to any other dbExpress™ driver's installation.

If you want to install the Delphi version, the files are under the pgExpress installation's Delphi directory; for the Kylix files, the directory is Kylix'.

If you're using the installer version (*.exe), it can perform the operations below for you, except configuring your connections parameters (what you can do manually by editing that file or just double-clicking a TSQLConnection component). You can edit the default [PGEConnection] entry it creates. The steps for manual installation are:

  1. Copy the driver dbexppge.dll (libdbexppge.so on Linux/Kylix) to a folder in your path. The usual folder is $Delphi\bin on Windows (where $Delphi is the Delphi's installed folder), or $kylix/bin on Kylix, but as long as it's on your path, you can choose any other folder.
  2. Copy the libpq.dll (libpq.so on Linux) file to a dir on your PATH. Please try to use the libpq supplied with the distribution. If you're under Linux, the standard libpq.so from the PostgreSQL original installation should work.

    Note for libpq incompatibilities:

    There could be some incompatilbility problems between the libpq.dll /libpq.so library provided in the distribution and other clients such as psql - specialy under Linux/Kylix. To solve this, you can either:

    If you rename the library to libpq_pge.so, for instance, your entry should become VendorLib=libpq_pge.so accordingly. There are more instructions on the dbxdrivers.ini/dbxdrivers file below.

    1. (for Linux only)- use the standard libpq.so file from the original PostgreSQL distribution, as it is, on your system;
    2. Rename the libpq.so/libpq.dll file from the pgExpress Driver distribution to something else, and update the entry on the dbxdrivers.ini /dbxdrivers file (which is by default
      VendorLib=libpq.so
      
      under Kylix or
      VendorLib=libpq.dll
      
      under Windows.
  3. Setup the entries on the dbxdrivers.ini and dbxconnections.ini dbExpress™ configuration files. These files are usually at the $ProgramFiles\Common Files\Borland Shared\DBExpress folder. The changes to be applied are the following:
  4. Edit the dbxdrivers.ini file. On Kylix™, this file is called dbxdrivers. On the [Installed Drivers] section, add the PostgreSQL=1 key and value:
    [Installed Drivers]
    DB2=1
    Interbase=1
    MYSQL=1
    Oracle=1
    PostgreSQL=1
    
  5. Still on this file, add the [PostgreSQL] section:
    [Oracle]
    GetDriverFunc=getSQLDriverORACLE
    LibraryName=dbexpora.dll
    VendorLib=OCI.DLL
    BlobSize=-1
    DataBase=Database Name
    ErrorResourceFile=
    LocaleCode=0000
    Password=password
    Oracle TransIsolation=ReadCommited
    User_Name=user
    
    [PostgreSQL]
    GetDriverFunc=getSQLDriverPOSTGRESQL
    LibraryName=dbexppge.dll
    VendorLib=LIBPQ.DLL
    

    Note:

    On Kylix, the PostgreSQL section is slightly different to reflect the Linux library file names:

    [PostgreSQL]
    GetDriverFunc=getSQLDriverPOSTGRESQL
    LibraryName=libdbexppge.so
    VendorLib=libpq.so
    

    Still on Linux/Kylix, you must add your driver's path to the LD_LIBRARY_PATH environment variable (or copy the driver to your Kylix's bin subdirectory):

    LD_LIBRARY_PATH=/home/steve/lib/
    export LD_LIBRARY_PATH
    

    Edit the dbxconnections.ini file. On Kylix, it's is called dbxconnections. This file lists all the dbExpress™ connections and it can contain as many entries for the pgExpress Driver as you might want add. We supply here an example connection, but you should modify it to meet your own settings (specially the server address, database name, user name and password) params:

    [PGEConnection]
    BlobSize=32
    HostName=host
    Database=database_name
    DriverName=PostgreSQL
    Password=temp123
    User_Name=steve
    

    The only required parameters are Database, DriverName, UserName and Password if desired. You can use a more reduced form like the one below (you're encouraged to use it):

    [PGEConnection]
    DriverName=PostgreSQL
    Database=hostname/database_name
    User_Name=steve
    Password=temp123
    

    The other parameters are optional (only those listed above are supported by the pgExpress Driver) and their meaning is that on dbExpress™ documentation. Pay special attention to the Database parameter. dbExpress™ only will load the HostName parameter if you set the TSQLConnection.LoadParamsOnConnect property to True. We at Vita Voom Software™ have used the following rules for the format of the Database parameter that avoid that confusion and also adds support for a Port parameter. It seems like an URL:

    host:port/database
    

    Where:

    • host is the Hostname (DNS or IP) of the machine. If you don't supply this parameter, it defaults to localhost.
    • port is the port to connect to, on the database server host. This do not need to be supplied, if you use the default port (5432). But if you do supply this parameter, you need also specify the host name, and separate the host and port with a colon (':').
    • Database is the database name to connect to. This parameter must be supplied.
    • The following are valid Database parameters:
      Database = myserver.mydomain.com/database
      Database = myserver.mydomain.com:5432/database
      Database = 111.111.111.111:5432/database
      Database = database
      

      Note that if you supply both the HostName and Database parameters with embedded hostname (as show above), the Database parameter will prevail. Don't forget you can add as many sections to the dbxconnections file as you want, like this:

    [PGEConnection]
    DriverName=PostgreSQL
    Database=hostname1/database_name
    User_Name=steve
    Password=temp123
    
    [pgserver]
    DriverName=PostgreSQL
    Database=pgserver/database_name
    User_Name=john
    

That's it; the driver should be working now.

Notes:

  • Inside the distribution there are example dbxdrivers(.ini) and dbxconnections(.ini) for both Delphi and Kylix.