Link to home
Start Free TrialLog in
Avatar of BdLm
BdLmFlag for Germany

asked on

extract "Create Tablle SQL" statement from a paradox table

I'm looking for a function like this

function ExtractCreateTabSQl ( aTable :  TTable; var aSQLString : String);
{*
   in
   aTable :  A Paradox Table
   out
   aSQLString  :  the string to create this table unsing the create table SQL
*}

begin

      for I := 0 ...n
          //  loop through all field

         //   get Field Name


        //   get Field Type


       //  addd to SQL String


  end;

end;
   
ASKER CERTIFIED SOLUTION
Avatar of ASta
ASta
Flag of Ukraine image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of BdLm

ASKER

{**********************************************************
 *  in :
 *  aTable :  A Paradox Table
 *  out :
 *  aSQLString  :  the string to create this table unsing the create table SQL
 *  used:  ftdatatypeStrMSSQL, ftdatatypeStr  a function to
 *         create the Datatype string
 *  BdLm
 *********************************************************}


procedure ExtractCreateTabSQl ( aTable :  TTable; var aSQLString : String);
var  i            :   Integer;
     aFieldName   :   String;
     aFieldType   :   String;
     aFieldSize   :   String;
     tabName      :   String;
begin

      tabName := ExtractFilename(aTable.TableName );

      aSQLString := '';
      aSQLString := 'Create table ' + tabName ;
      aSQLString := aSQLString + ' ( ';
      for I := 0 to aTable.FieldCount -1   do
      begin
          //  loop through all fields

          //   get Field Name
          aFieldName :=  aTable.Fields[i].FieldName ;

          //   get Field Type
          aFieldType :=  ftdatatypeStrMSSQL(aTable.Fields[i].DataType);

          // aFieldType :=  ftdatatypeStr(aTable.Fields[i].DataType);


          //  Data size

          aFieldSize := '(' + IntToStr( aTable.Fields[i].DataSize -1  ) +')   NULL ';

          if  ((aFieldType =  'varchar')  or  (aFieldType =  'varbinary')) then
              aFieldSize := '  NULL';

          if ( (aFieldType =  'float') or (aFieldType =  'int') or (aFieldType =  'datetime') or (aFieldType =  'smallint') )then
              aFieldSize := '  NULL';

          //  add to SQL String

          aSQLString := aSQLString + aFieldName + ' ' +  aFieldType + aFieldSize + '  '  ;

          if i <> (aTable.FieldCount -1 ) then aSQLString := aSQLString + ', ';
      end;


      aSQLString := aSQLString + ') ';





  end;
Avatar of BdLm

ASKER

here is the complete code