2011. március 7., hétfő

How to modify the structure of a Paradox table at runtime


Problem/Question/Abstract:

I am upgrading an application and need to add fields to a Paradox TTable database. The application should inspect the existing database file structure and upgrade the customers existing database if necessary.

Answer:

First, open the files using a TTables exclusively, and check for fields. I was adding fields so I used the following code:

with tblEmployer do
begin
  open;
  lFoundAddCalcMethod := FindField('RetireCalcMethod') <> nil;
  lFoundRetireFundMethod := FindField('RetireFundMethod') <> nil;
  close;
end;

If I was altering a field (for example, say I wanted to make a field change from Integer to String), you could assing the result of FindField to a TField variable and check it. Then I alter the table as needed:

if not lFoundAddCalcMethod then
  QryAddRetireCalcMethod.ExecSQL;

and the SQL part of the TQuery:

alter table "MAXXEMPL.DB"
add RetireCalcMethod character(2),
add RetireFundDollar Float,
add RetireFundPercent Float,
add LocalTaxMthd character(2);

Nincsenek megjegyzések:

Megjegyzés küldése