Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Compare Structures of 2 Tables Tip
Message
From
10/11/2001 04:05:43
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00579912
Message ID:
00580097
Views:
16
>In VFP 7, comparing structures of 2 tables is now easier. The first step is to copy the EXTENDED structure of each table to tables. I did a search here for other solutions. They generally used afields and other stuff, but this solution seems so much easier. The procedure I created is for comparing Oracle tables so you would have to change COLUMN_NAME to FIELD_NAME:
>   PROTECTED PROCEDURE CompareStructureData
>      LPARAMETERS tcAlias1, tcAlias2
>      IF RECCOUNT(tcAlias1)  RECCOUNT(tcAlias2)
>         RETURN .f.
>      ENDIF
>      LOCAL lnSelect, llTheSame, lcFedCols, lcGISCols
>      lnSelect = SELECT()
>
>      SELECT * from (tcAlias1) ORDER BY column_name INTO CURSOR crsTempOne nofilter
>      SELECT * from (tcAlias2) ORDER BY column_name INTO CURSOR crsTempTwo nofilter
>
>      CURSORTOXML('crsTempOne', 'lcTempOne')
>      CURSORTOXML('crsTempTwo', 'lcTempTwo')
>
>      lcTempOne = lower(lcTempOne)
>      lcTempTwo = lower(lcTempTwo)
>
>      *!* Change the cursor name in the second XML string to be the same as in the
>      *!* first string because this name is irrelevent to the structure comparison
>      lcTempTwo = STRTRAN(lcTempTwo, 'crstemptwo', 'crstempone')
>
>      IF SYS(2007, lcTempOne) = SYS(2007, lcTempTwo)
>         llTheSame = .t.
>      ENDIF
>      USE IN crsTempOne
>      USE IN crsTempTwo
>      SELECT (lnSelect)
>      RETURN llTheSame
>   ENDPROC</font
Mark,
I think this would fail if the tables were part of a DBC. You could however fix it by not including all fields in select from extended structures. Also I wouldn't lowercase each which might incorrectly return different structures as same.
BTW FoxyClasses DataDelta basically uses 'copy structure extended' technique and compatible with all VFP versions.
PS: Instead of XML you could use union for all VFP versions :
select	FIELD_NAME, FIELD_TYPE,	FIELD_LEN, FIELD_DEC, ;
  FIELD_NULL, FIELD_NOCP, FIELD_DEFA, FIELD_RULE, FIELD_ERR FROM xstruc1 ;
UNION ;
select	FIELD_NAME, FIELD_TYPE,	FIELD_LEN, FIELD_DEC, ;
  FIELD_NULL, FIELD_NOCP, FIELD_DEFA, FIELD_RULE, FIELD_ERR FROM xstruc2 ;
INTO ARRAY arrDummy
return ALEN(arrDummy,1) = reccount('xstruc1')
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform