Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Comparing Table Structures
Message
 
To
12/06/2001 09:29:21
Jay Johengen
Altamahaw-Ossipee, North Carolina, United States
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00518332
Message ID:
00518344
Views:
33
This message has been marked as the solution to the initial question of the thread.
>I'm looking for a simple way to compare the structures of a number of tables. I think they are the same, but there are 200+ fields and I would rather sit and write code for two hours rather than sit and stare at paper for two hours. I'm playing around with the AFields() function, but can't quite get the concept going of what I need to do... Any ideas? Thanks!
>
Renoir,

This depends on how you define "the same". For purposes of this, I took the same to mean that the same field names had to be in both tables, but not necessarily in the same relative position in the table, as well as matching data types, etc. If, however, the relative position is also to be considered then making the comparison based on the row offset into the array can be used instead of ASCAN().
FUNCTION DupStructs
  * Determines if two table structures are equal
  
  LPARAMETERS tcAlias1, tcAlias2
  
  LOCAL llresult, lnsize1, lnsize2, aflds1, aflds2, lni,;
    lcexact, lnpt
  lcexact = SET('EXACT')
  DIMENSION aflds1[1], aflds2[1]
  SET EXACT ON
  lnsize1 = AFIELDS(aflds1, tcAlias1)
  lnsize2 = AFIELDS(aflds2, tcAlias2)
  * Are there the same number of fields?
  llresult = (lnsize1 = lnsize2)
  IF llresult
    lni = 0
    DO WHILE lni < lnsize1 AND llresult
      lni = lni + 1
      lnpt = ASCAN(aflds2, aflds1[lni, 1])
      * Does the field exist?
      llresult = (lnpt > 0)
      IF llresult
        * Yes it does
        lnpt = ASUBSCRIPT(aflds2, lnpt, 1)
        * Are the data types, field sizes, and decimals equal?
        llresult = (aflds1[lni, 2] = aflds2[lnpt, 2] AND;
          aflds1[lni, 3] = aflds2[lnpt, 3] AND;
          aflds1[lni, 4] = aflds2[lnpt, 4])
      ENDIF
    ENDDO
  ENDIF
  SET EXACT &lcexact
  RETURN llresult
ENDFUNC
George

Ubi caritas et amor, deus ibi est
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform