Steve Shaughnessy

The new dbExpress 4.0 MetaData

In the effort to consolidate the dbExpress and BDP driver frameworks into one we needed to enhance the metadata for dbexpress.  The dbExpress 3 metadata is written in C.  The BDP metadata is written in C#.  The dbExpress metadata was not rich enough for the tooling infrastructure we want to support in the future for both win32 and .NET.  Our solution was to implement new metadata for all drivers in Object Pascal.  This can be compiled for both win32 and .NET.

 

On the .net side this is also the metadata we use for our ADO.NET 2.0 AdoDbxClient provider which allows any of our dbExpress drivers to be surfaced as an ADO.NET 2.0 provider.

 

Another interesting aspect is that the new metadata is provider based making it pluggable.  This allows other dbExpress driver implementations that use the same back end to reuse our metadata implementation.  It also allows us to potentially support other vendor’s ADO.NET drivers with our tooling.  For example, the DataExplorer can use Microsoft’s ADO.NET driver with our MS-SQL metadata provider.

 

The provider is specified in the dbxdrivers.ini.  If this entry does not exist in the dbxdrivers.ini file, the metadata request will be passed on to the underlying driver.  In the case of our dbxDrivers, you will get dbExpress 3 metadata support.

 

I’d say about 25% of the dbExpress driver implementations deal with metadata support.  There is already a large amount of framework implementation shared for all drivers.  With the new metadata we are one more significant step towards a 100% Object Pascal solution.  Object Pascal provides us with the portability we need to support win32, .NET and eventually win64.

 

The new metadata commands are documented in the DbxCommon.pas.  There are also several classes with constants and documentation for the new metadata tables and their columns.  The new metadata extends dbExpress 3 metadata with support for retrieving:  data types, views, synonyms, catalogs, schemas, procedure source, package source, package procedure parameters, roles, and reserved words.

 

We also now provide driver independent support for editing metadata.  Support for creating sql dialect sensitive create, alter, drop statements was initially only provided for tooling purposes in the DataExplorer.  However we have now also exposed a DbxMetaDataProvider class that surfaces this capability for applications.  This will make a slight increase in the size of your application since you will need to include the metadata writers.  The ability to generically create tables is useful for many applications.  The interface allows you to describe what a table and its columns should look like.  This description is passed to the TdbxMetaDataProvider.CreateTable.  Here is a very simple example that shows how to create a table with an int32 column named "C1", a decimal with a precision of 10 and scale of 2 named "C2" and a character based column with a precision of 32 named "C3". 

var
  MetaDataTable: TDBXMetaDataTable;
  DataGenerator: TDbxDataGenerator;
  Command: TDBXCommand;
  Row: Integer;
begin
  MetaDataTable := TDBXMetaDataTable.Create;

  MetaDataTable.TableName := ‘QCXXX_TABLE’;
  MetaDataTable.AddColumn(TDBXInt32Column.Create(’C1′));
  MetaDataTable.AddColumn(TDBXDecimalColumn.Create(’C2′, 10, 2));
  MetaDataTable.AddColumn(TDBXUnicodeCharColumn.Create(’C3′, 32));
  MetaDataProvider.CreateTable(MetaDataTable);

TDBXInt32Column, DecimalColumn and UnicodeCharColumn are pre fabricated class extensions of the TDBXMetaDataColumn class.  The TDBXMetaDataColumn class contains several column properties including data type, precision, scale, is fixed length, is Unicode, etc.  You can create your own pre fabricated classes for column types common to your application.  The MetaDataProvider will find the best possible match of each TDBXMetaDataColumn to the underlying type system of the targeted database backend.

 

Posted by Steve Shaughnessy on September 7th, 2007 under Uncategorized |



5 Responses to “The new dbExpress 4.0 MetaData”

  1. richard Says:

    Is the DBExpress ’spec’ published anywhere? I would have thought CodeGear would publish it so that the development community could write drivers for the non-mainstream databases. In fact, why does CodeGear waste limited resources writing drivers — publish the full specs (versioned) and the complete source code (eg for Interbase or MySQL) and let the other database vendors get on with writing the DBExpress drivers.

  2. Bvo Says:

    So when Firebird (Interbase?) Blobs will work? I just wondering how CG can ignore users demsnd.

  3. Bvo Says:

    Sorry, demsnd == demAnd

  4. Jaimy Says:

    Is there any plan on DBX development on supporting two-phase-commit? today more and more RDBMS has add their support for distributed transactions.

    IMO, DBX by its architecture which prefer unidirectional dataset, and supporting multiple RDBMS is the best choice to be used in a multi-tier system, but to enable other developer create a distributed transaction manager (like on java with JTS), DBX must support XA transaction interface.

  5. Jens Froherz Says:

    in my test’s the example works fine with DBX MS-SQL or Blackfish, but with Interbase 7 a metadata error for MetaDataProvider.CreateTable(MetaDataTable); appears …



Server Response from: blog1.codegear.com