Delphi Clinic C++Builder Gate Training & Consultancy Delphi Notes Weblog Dr.Bob's Webshop
Dr.Bob's Delphi Notes Dr.Bob's Delphi Clinics Dr.Bob's Delphi Courseware Manuals
 Dr.Bob Examines... #14
See Also: other Dr.Bob Examines columns or Delphi articles

Moving BDE Data to Linux
Delphi 5 supports a number of different databases and table formats, such as BDE (dBASE, Paradox), InterBase (native as well as via the BDE), ODBC/ADO (to Access and FoxPro for example) and SQL Server to Oracle, DB2, Informix and SQL Server. Kylix does not support BDE, but has replaced the BDE by dbExpress, for an open access to native Linux database engines. Kylix Desktop Developer supports MyBase (local XML), MySQL and InterBase, while Kylix Server Developer adds support for Oracle and DB2.
As a consequence, not all database formats available in Delphi 5 will be available for Kylix. Specifically, the Borland Database Engine (dBASE, Paradox formats) will not be ported to Linux. This means that your dBASE and Paradox tables cannot be used by Kylix. Fortunately, you can use Delphi 5 to migrate your dBASE and Paradox tables to InterBase or the local ClientDataSet format (CDS or XML). Data in XML format can also be used by the MyBase XML database for Linux.
After you've moved your BDE data to dbExpress, you can consider the next logical step: migrating your BDE applications themselves to (cross-platform) dbExpress

ClientDataSet XML
Using Delphi 5 Enterprise you can connect a Table to a DataSetProvider in order to feed a ClientDataSet component that can be used to store the data in .cds or .xml format. The following console application takes a local table (in the same directory) as command-line argument, and produces an XML file containing the data:

  program BDE2XML;
  {$APPTYPE CONSOLE}
  uses
    SysUtils, DB, DBTables, Provider, DBClient;
  var
    Table: TTable;
    DataSetProvider: TDataSetProvider;
    ClientDataSet: TClientDataSet;
  begin
    Table := TTable.Create(nil);
    try
      Table.TableName := ParamStr(1);
      Table.Open;
      DataSetProvider := TDataSetProvider.Create(nil);
      try
        DataSetProvider.DataSet := Table;
        ClientDataSet := TClientDataSet.Create(nil);
        try
          ClientDataSet.SetProvider(DataSetProvider);
          ClientDataSet.Open;
          ClientDataSet.SaveToFile(
            ChangeFileExt(ParamStr(1),'.xml'));
          ClientDataSet.Close
        finally
          ClientDataSet.Free
        end
      finally
        DataSetProvider.Free
      end;
      Table.Close
    finally
      Table.Free
    end
  end.

Usage is really simple: make sure BDE2XML is in your path, and move to the directory where your database tables reside. Then, to convert the country.db table from Paradox to XML for example, execute:

  BDE2XML country.db

The result is a 2,298 bytes country.xml file, which can be moved from Windows to Linux (by using a network, ftp or even a floppy disk) and then loaded in Kylix by a TClientDataSet component using the LoadFromFile method or the FileName property.
Alternately, you can always move your database to an InterBase database, which runs just fine on Linux.

Delphi 5 Professional
For those of you who have Delphi 5 Professional, and hence cannot make use of the TClientDataSet component, I have written a unit that can also produce ClientDataSet-compatible XML files from regular DataSets. It was part of my Under Construction article in issue #62 of The Delphi Magazine.


This webpage © 2001-2010 by Bob Swart (aka Dr.Bob - www.drbob42.com). All Rights Reserved.