Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
LIST STRUCTURE alternative
Message
From
15/05/2019 16:18:28
 
 
To
15/05/2019 13:46:58
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01668636
Message ID:
01668643
Views:
69
Likes (1)
If you use VFP9 and Thor, Superbrowse will give you this and a zillion more features.

>This may already exist, but I created this today to give me with an easy way to get a table's structure into text form. It can be modified to create a SQL statement, CREATE CURSOR statement, etc. I call it list_struct.prg:
>
>
* list_struct.prg
>* Usage:  DO \path\to\list_struct.prg
>* Note:  Assumes the current work area
>LOCAL lnI, lcStruct
>LOCAL ARRAY laFields[1]
>
>AFIELDS(laFields)
>
>* Find out how long the longest field name is
>lnLen = 0
>FOR lnI = 1 TO ALEN(laFields, 1)
>    lnLen = MAX(lnLen, LEN(laFields[lnI, 1]))
>NEXT
>lnLen = lnLen + 4
>
>* Build the structure
>lcStruct = SPACE(0)
>FOR lnI = 1 TO ALEN(laFields, 1)
>    lcStruct = lcStruct + PADR(fixupCase(laFields[lnI, 1]), lnLen) + nameType(laFields[lnI, 2]) + SPACE(4) + fieldLength(laFields[lnI, 3], laFields[lnI, 4]) + CHR(13) + CHR(10)
>NEXT
>
>* Copy to clipboard
>_cliptext = lcStruct
>
>
>
>
>* Fixes up some names for case within a field name
>PROCEDURE fixupCase
>LPARAMETERS tcFieldName
>LOCAL lcFieldName
>    lcFieldName = LOWER(LEFT(tcFieldName, 1)) + PROPER(SUBSTR(tcFieldName, 2))
>    IF INLIST(RIGHT(lcFieldName, 2), "id", "by", "on")
>        IF LOWER(RIGHT(lcFieldName, 4)) != "void"
>            lcFieldName = LEFT(lcFieldName, LEN(lcFieldName) - 2) + PROPER(RIGHT(lcFieldName, 2))
>        ENDIF
>    ENDIF
>    IF INLIST(RIGHT(lcFieldName, 4), "date")
>        lcFieldName = LEFT(lcFieldName, LEN(lcFieldName) - 4) + PROPER(RIGHT(lcFieldName, 4))
>    ENDIF
>    IF INLIST(RIGHT(lcFieldName, 8), "modified")
>        lcFieldName = LEFT(lcFieldName, LEN(lcFieldName) - 8) + PROPER(RIGHT(lcFieldName, 8))
>    ENDIF
>    IF INLIST(RIGHT(lcFieldName, 10), "modifiedBy")
>        lcFieldName = LEFT(lcFieldName, LEN(lcFieldName) - 10) + PROPER(LEFT(RIGHT(lcFieldName, 10), 8)) + RIGHT(lcFieldName, 2)
>    ENDIF
>    RETURN lcFieldName
>
>
>
>
>PROCEDURE nameType
>LPARAMETERS tcType
>LOCAL lcLongType
>    DO CASE
>        CASE tcType = "C"
>            lcLongType = "Character"
>        CASE tcType = "Y"
>            lcLongType = "Currency"
>        CASE tcType = "D"
>            lcLongType = "Date"
>        CASE tcType = "T"
>            lcLongType = "DateTime"
>        CASE tcType = "B"
>            lcLongType = "Double"
>        CASE tcType = "F"
>            lcLongType = "Float"
>        CASE tcType = "G"
>            lcLongType = "General"
>        CASE tcType = "I"
>            lcLongType = "Integer"
>        CASE tcType = "L"
>            lcLongType = "Logical"
>        CASE tcType = "M"
>            lcLongType = "Memo"
>        CASE tcType = "N"
>            lcLongType = "Numeric"
>        CASE tcType = "Q"
>            lcLongType = "Varbinary"
>        CASE tcType = "V"
>            lcLongType = "Varchar"
>        CASE tcType = "W"
>            lcLongType = "Blob"
>        OTHERWISE
>            lcLongType = LEFT(REPLICATE(tcType, 9), 9)
>    ENDCASE
>    RETURN PADR(lcLongType, 9)      && Longest field names are "Character" and "Varbinary" both of which are 9 bytes
>
>
>
>
>PROCEDURE fieldLength
>LPARAMETERS tnWidth, tnDecimals
>    IF tnDecimals != 0
>        RETURN "(" + TRANSFORM(tnWidth) + "," + TRANSFORM(tnDecimals) + ")"
>    ENDIF
>    RETURN "(" + TRANSFORM(tnWidth) + ")"
Previous
Reply
Map
View

Click here to load this message in the networking platform