Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

extract "Create Tablle SQL" statement from a paradox table

Posted on 2009-12-20
3
Medium Priority
?
511 Views
Last Modified: 2013-11-23
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;
   
0
Comment
Question by:BdLm
  • 2
3 Comments
 
LVL 2

Accepted Solution

by:
ASta earned 100 total points
ID: 26094817
aSQLString := 'Create table ' + aTable.TableName {?} + '('
 for I := 0 ...n
          //  loop through all field
         aSQLString := aSQLString + aTable.Field[I]{?}.FieldName + ' ';

         //   get Field Name
        //   get Field Type
       //  addd to SQL String

        case aTable.Field[I]{?}.FieldType of
          ...String: aSQLString := aSQLString + 'VARCHAR(' + aTable.Field[I]{?}.FieldSize + ')';
        ...
        end


  end;
aSQLString := aSQLString + ') ';

0
 
LVL 8

Author Comment

by:BdLm
ID: 26843933
{**********************************************************
 *  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;
0
 
LVL 8

Author Closing Comment

by:BdLm
ID: 31668246
here is the complete code
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Integration Management Part 2
Screencast - Getting to Know the Pipeline
Suggested Courses

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question