marco
cantu

Books : Mastering Borland Delphi 2005: Update for Delphi 2006

Mastering Delphi Update for Delphi 2006


Chapter 13

Delphi 2006 Database Architecture


Delphi's database architecture has not changed significantly since Delphi 3 introduced the abstract TDataSet class to make custom datasets fully integrated with the dataset/data-aware architecture, that up to Delphi 2 was tied only to the BDE datasets.

Going from Delphi 2005 to Delphi 2006 doesn't constitute such a revolution, but is certainly quite a significant change (definitely far greater than Borland's documentation implies). Most of the internal data structures of the database architecture in Delphi 2006 use wide strings (Unicode strings based on 16-bit characters) rather than plain strings. Examples are table names, field names, and SQL queries.

Beside this change I'll cover in some detail in the next section (Unicode Support), there are a few other minor improvements that are worth mentioning:

Unicode Support

If you read Borland's documentation about what's new in Delphi 2006 you'll see that the dbExpress components now support Unicode strings. This is almost correct, but it is quite an understatement: the entire database architecture supports Unicode metadata! Actually, to be more precise, it supports wide strings that can be used to express the 16-bit Unicode representation or UTF-16. You can in fact, have Unicode strings also using standard 8-bit strings and using the UTF-8 encoding.

As an example, regardless of the dataset components you use the TField objects now have several wide string properties. Here is a fragment of the class declaration in the VCL source code:

type

  TField = class

    property AsWideString: WideString

      read GetAsWideString write SetAsWideString;

    property DisplayName: WideString read GetDisplayName;

    property FullName: WideString read GetFullName;

    property DisplayLabel: WideString

      read GetDisplayLabel write SetDisplayLabel

    property FieldName: WideString

      read FFieldName write SetFieldName;

    property LookupKeyFields: WideString

      read FLookupKeyFields write SetLookupKeyFields;

    property LookupResultField: WideString

      read FLookupResultField write SetLookupResultField;

    property KeyFields: WideString

      read FKeyFields write SetKeyFields;

Needless to say that the TDataSet class has corresponding changes including, for example, the replacement of the GetFieldNames method with a new incompatible version (the older one is still there but is marked as deprecated):

procedure GetFieldNames(List: TStrings);

  overload; virtual; deprecated;

procedure GetFieldNames(List: TWideStrings);

  overload; virtual;

There is also a new interface for providers (IProviderSupport2) that uses wide strings. This interface is implemented by a new base class of the VCL's database architecture:

type

  TWideDataSet = class(TDataSet, IProviderSupport2)

This new TWideDataSet class is the base class for the ADO datasets, the ClientDataSet, and almost all of the other datasets Delphi provides. The only exception is that of the (old) BDE datasets. These components (like Table) still inherit from the base TDataSet class, but the change in the field names applied to them as well.

That's not all. To comply with the new model, the DataField properties of the various data-aware controls are now declared of the WideString type instead of the string type. This is true also for the data-aware controls previously unable to show Unicode characters properly, which are most of the data-aware controls of the VCL.

Finally, Borland has extended the set of available field types (that is, the TFieldType enumeration), adding the ftFixedWideChar and ftWideMemo options. This enumeration has two other new values, not related with wide strings but with Oracle support, the ftOraTimeStamp and ftOraInterval options. The following code snippet shows the new field type mappings for these new field types:

    TWideStringField,   { ftFixedWideChar }

    TWideMemoField,     { ftWideMemo }

    TSQLTimeStampField, { ftOraTimeStamp }

    TStringField);      { ftOraInterval }

Among these, the WideMemoField is new in Delphi 2006. Needless to say all of these core changes and changes in the base classes have a pervasive effect on all of the dataset components, connection components, and SQL command components of the library. As an example, the SQL property of the ADOQuery component is now of the TWideStrings type.