Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Getting list of PKs for All Tables
Message
 
 
To
24/02/2003 10:31:35
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00756362
Message ID:
00757013
Views:
14
>I don't know if there is a way w/o opening the table.

I see no other way either. This is the code I came up with to strip out any functions, plus signs, etc., and just return a list of fields. Try it on the Northwind DB.
IF EMPTY(DBC())
   OPEN DATABASE ?
   IF EMPTY(DBC())
      RETURN .f.
   ENDIF
ENDIF
CLEAR
?
CLOSE TABLES ALL
LOCAL lnRetVal, laFields[1], lcString, lnI, lcExpr
lnRetVal = ADBOBJECTS(laTables,"TABLE")
FOR EACH lcTable IN laTables
   lcTag = DBGETPROP(lcTable,"TABLE","PrimaryKey")
   IF EMPTY(lcTag)
      LOOP
   ENDIF
   USE (lcTable)
   lcKey = KEY(TAGNO(lcTag))
   lcExpr = lcKey
   USE
   IF EMPTY(STREXTRACT(lcKey, "(", ")", 1))
      lcKey = CHRTRAN(lcKey, [+ ], [])
      ? [Table:], lcTable, [--], lcExpr
      ?
      LOOP
   ENDIF
   lcKey = [+] + lcKey + [+]
   lnI = 1
   laFields = []
   DO WHILE NOT EMPTY(lcKey)
      lcString = STREXTRACT(lcKey, "+", "+", 1)
      lcKey = STRTRAN(lcKey, "+" + lcString + "+", [])
      IF NOT EMPTY(lcKey)
         lcKey = "+" + lcKey
      ENDIF
      IF NOT EMPTY(lcString)
         lcString = GetFieldName(lcString)
         DIMENSION laFields[lnI]
         laFields[lnI] = lcString
      ELSE
         EXIT
      ENDIF
      lnI = lnI + 1
   ENDDO
   ? [Table:], lcTable, [--], lcExpr
   FOR EACH lcField IN laFields
      ? lcField
   ENDFOR
   ?
ENDFOR


PROCEDURE GetFieldName
   LPARAMETERS tcString
   LOCAL lcName, lnI, lnAt
   lnI = OCCURS("(", tcString)
   tcString = STREXTRACT(tcString, "(", ")", lnI)
   lnAt = AT(",", tcString)
   IF lnAt > 1
      tcString = SUBSTR(tcString, 1, lnAt - 1)
   ENDIF
   RETURN ALLTRIM(tcString)
ENDPROC
Mark McCasland
Midlothian, TX USA
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform