Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Code to get table structure
Message
From
14/04/2005 11:19:01
 
 
To
14/04/2005 10:50:27
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 9
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01004671
Message ID:
01004694
Views:
23
This message has been marked as the solution to the initial question of the thread.
Gary,

I found some old code that should get you started. You may want to tweak the formatting (indentation, line length, etc.) to fit your preferences.
*  Program...........: GtCreate.prg
*  Author............: Daniel Gramunt
*  Created...........: 09.07.2001  17:53:24
*  Copyright.........: (c) Nokia, 2001
*) Description.......: Returns a string containing a CREATE CURSOR/TABLE command based
*)                   : on the selected table/cursor.
*  Calling Samples...:
*  Parameter List....:
*  Major change list.:
*--------------------------------------------------------------------------------------------------

#DEFINE ccCrLf    CHR(13)+CHR(10)
#DEFINE ccIndent  SPACE(28)

IF EMPTY(ALIAS())
   WAIT WINDOW NOWAIT "No table open in current workarea."
   RETURN ""
ENDIF

LOCAL lnFields, lcRetVal, i, lcFieldName, lcFieldType, lnFieldSize, lnFieldDeci, lcTypeAndLen, lcLineContinuation
LOCAL ARRAY laFields[1]

lnFields = AFIELDS(laFields)
lcRetVal = "CREATE CURSOR <CursorName> (;" + ccCrLf

FOR i = 1 TO lnFields
   
   lcFieldName = laFields[i, 1]
   lcFieldType = laFields[i, 2]
   lnFieldSize = laFields[i, 3]
   lnFieldDeci = laFields[i, 4]
   
   DO CASE
      CASE lcFieldType $ "DTIYMLG"
         lcTypeAndLen = lcFieldType
      CASE lcFieldType = "C"
         lcTypeAndLen = lcFieldType + "(" + ALLTRIM(STR(lnFieldSize)) + ")"
      CASE lcFieldType $ "NF"
         lcTypeAndLen = lcFieldType + "(" + ALLTRIM(STR(lnFieldSize)) + "," + ALLTRIM(STR(lnFieldDeci)) + ")"
      CASE lcFieldType = "B"
         lcTypeAndLen = lcFieldType + "(" + ALLTRIM(STR(lnFieldDeci)) + ")"
      OTHERWISE
         lcTypeAndLen = "?"
   ENDCASE

   lcLineContinuation = IIF(i=lnFields, ";", ",;")
   
   lcRetVal = lcRetVal + ccIndent + PADR(lcFieldName, 20) + lcTypeAndLen + PADL(lcLineContinuation , 10-LEN(lcTypeAndLen)) + ccCrLf

ENDFOR &&* i = 1 TO lnFields

lcRetVal = lcRetVal + ccIndent + ")"

RETURN lcRetVal
HTH
>Hi,
>
>Does anyone have a function they could share that will provide "SQL create cursor code" if you feed the function with a table/cursor name.
>
>Thanks,
Daniel
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform