Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Turn a DBF into CREATE TABLE SQL prg

Usefull Functions & Procedures

Turn a DBF into CREATE TABLE SQL prg

by  baltman  Posted    (Edited  )
This procedure currently only supports character, date and numberic fields. It shouldn't me too hard to modify...

Brian

Code:
layout_to_code(GETFILE('*.dbf'))

PROCEDURE layout_to_code
LPARAMETERS lcTable

IF ADIR(laTemp,lcTable)=0
 MESSAGEBOX("No Table Selected")
 RETURN
ELSE
 lcTable=JUSTSTEM(lcTable)
 IF USED(lcTable) = .f.
  USE (lcTable) IN 0
ENDIF

SELECT (lcTable)

lcCmd=""
FOR lnFieldCnt = 1 TO AFIELDS(laTemp)
 lcCmd=lcCmd+laTemp(lnFieldCnt,1)+" "+laTemp(lnFieldCnt,2)+;
 IIF(laTemp(lnFieldCnt,2)="D","","("+TRANSFORM(laTemp(lnFieldCnt,3))+;
 IIF(laTemp(lnFieldCnt,2)='N',","+TRANSFORM(laTemp(lnFieldCnt,4))+")",")"))+;
 IIF(MOD(lnFieldCnt,4)=0,",;"+CHR(13),",")
ENDFOR

lcCmd=LEFT(lcCmd,LEN(lcCmd)-4)+")"

STRTOFILE("create table "+lcTable+"_layout ("+lcCmd+")",lcTable+'_layout_prg.prg')
COMPILE (lcTable+"_layout_prg")

MESSAGEBOX("'"+lcTable+"_layout_prg' sucessfully created")

MODIFY COMMAND (lcTable+"_layout_prg") NOWAIT
ENDPROC
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top