marco
cantu

Books : Mastering Borland Delphi 2005: Update for Delphi 2006

Mastering Delphi Update for Delphi 2006


Chapter 14

dbExpress in Delphi 2006


The extensions to the VCL database architecture relating to Unicode support and discussed in the update material to Chapter 13, apply also to the dbExpress database components. For example, in comparison to Delphi 2005, there is full support for Unicode in the Microsoft SQL Server driver. The same driver, by the way, has been extended to manage the results returned by stored procedures.

The dbExpress architecture in Delphi 2006 has several changes and a new set of incompatible drivers. The new version of the dbExpress interfaces is numbered 3.0. Luckily enough the new drivers have the version number inside their file name, like dbxint30.dll, to avoid any type of conflict with the older libraries. Here is a table with the list if supported databases and the corresponding driver libraries:

Old driver

New driver

Database and Version

dbexpinf.dll

dbxinf30.dll

Interbase 7.5

dbexpora.dll

dbxora30.dll

Oracle 10g

dbexpdb2.dll

dbxdb230.dll

db2 UDB 8.x

dbexpmss.dll

dbxmss30.dll

MSSQL 2000

dbexpmys.dll

dbxmys30.dll

MySQL 4.0.24

dbexpasa.dll

dbxasa30.dll

Adaptive Sybase Anywhere 9

dbexpase.dll

dbxase30.dll

Sybase 12.5

dbexpinf.dll

dbxinf30.dll

Informix 9.x

Alongside the new version there is a new set of configuration files, that can coexist with those of the previous version (in case you want to keep using Delphi 7 or 2005 on the same development machine on which you installed Delphi 2006). The configuration files dbxconnections.ini and dbxdrivers.ini in this version of Delphi have been moved to the $(BDS)\dbexpress folder (that is something like c:\Program Files\Borland\BDS\4.0\dbExpress). This is only a default, you can change in the Registry key \Software\Borland\BDS\4.0\dbExpress. In the previous versions of Delphi, the Registry key was \Software\Borland\BDS\dbExpress (regardless of the Delphi version) while the default folder for the configuration files was something like c:\Program Files\Common Files\Borland Shared\DBExpress. This change in the structure makes things a little confusing. However with dbExpress potentially changing when you update Delphi, placing configuration files in a version specific folder and registry key makes a lot of sense to avoid any possible incompatibilities. In this specific case, the change in the interfaces (mostly due to the introduction of Unicode support) would have caused quite some trouble.

There are also some changes in the database connection component (SQLConnection). A nice features is that among the properties you can now set the value of the decimal separator format used by the database, to avoid problems with localized databases.

Database Explorer for dbExpress

The most visible new feature related with dbExpress of Delphi 2006 is the extension of the Database Explorer window of the IDE to support dbExpress alongside with the BDP components for ADO.NET. This means you can now see the configured database connections and browse their tables and views at design time, open these tables in the IDE, execute SQL statements, and so on. All without opening a specific tool and for each of the supported databases, as I described in Chapter 1 of the printed Mastering Delphi 2005 (look in particular to Figure 1.12).

Not only you can see metadata and data, but you can now also drag a table over a VCL designer (like a form or data module) to add the corresponding components right away. If you drag a connection, you get a ready-to-use SQLConnection component. If you drag a table, instead, the corresponding SQLDataSet component is set in the ctTable mode. I'd have preferred a generic query myself.

Dragging a dataset creates also the required connection component at once. With a single drag operation on the Employee table of the sample Employee InterBase database, you obtain the following components settings:

object IBCONNECTION: TSQLConnection

  ConnectionName = 'IBCONNECTION'

  DriverName = 'Interbase'

  GetDriverFunc = 'getSQLDriverINTERBASE'

  LibraryName = 'dbxint30.dll'

  LoginPrompt = False

  Params.Strings = (

    'DriverName=Interbase'

    'Database=c:\program files\common files\borland '

    'shared\data\employee.gdb'

    'RoleName=RoleName'

    'SQLDialect=3'

    'Interbase TransIsolation=ReadCommited'

    'Trim Char=False'

    ...)

  VendorLib = 'gds32.dll'

end

object EMPLOYEE: TSQLDataSet

  CommandText = 'EMPLOYEE'

  CommandType = ctTable

  SQLConnection = IBCONNECTION

end

Notice that the component names do not follow the VCL designer standards, (SQLConnection1, SQLDataSet1) but are copied directly from the dragged elements of the Database Explorer (even with the same cases), like IBCONNECTION and EMPLOYEE. This is far from the solution I'd like, merging a prefix with a mixed case name would have been a much nicer solution. Changing these names after the drag operation doesn't take a lot of time, though, and most developers would change them anyway to suit their own standards.