Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Comparing Table Structures
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00518332
Message ID:
00518355
Views:
18
George,
A little tweak could be to add an ASORT() (if the position doesn't matter) and simply compare Aflds1 to Aflds2 for every element. The same comparison could be done without the ASort if the position matters.
* provided lnSize1 and lnSize2 are equal
if !llorder then
   =asort(Aflds1,1)  && sort on column name
   =asort(Aflds2,1)  && sort on column name
else
   * order matters so don't sort the arrays
endif
llMatch = .T.
for lxx = 1 to lnSize1
   for lyy = 1 to 16
      if Aflds1(lxx,lyy) # AFlds2(lxx,lyy) then
         llMatch = .F.
         exit
      endif
   endfor
   if !llMatch then
      exit
   endif
endfor

return llMatch
Can you find any bugs with it?

>>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
Larry Miller
MCSD
LWMiller3@verizon.net

Accumulate learning by study, understand what you learn by questioning. -- Mingjiao
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform