Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Quick way to compare two arrays
Message
 
 
À
05/05/2001 22:49:27
Al Doman (En ligne)
M3 Enterprises Inc.
North Vancouver, Colombie Britannique, Canada
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00503959
Message ID:
00503970
Vues:
27
>>>>He everybody,
>>>>
>>>>Suppose, I have an array generated by afields(). I have DataDict table, which describes structure of a table, so I can generate similar array. What would be the quickest way to compare two such arrays?
>>>
>>>How about converting your AFIELDS() array to a cursor - you could then use SELECT - SQL against the two tables/cursors.
>>
>>It's still not clear, how then I compare two cursors... scan, scatter & compobj seems to be not easy.
>>
>>Thanks. I'll think about it.
* Get new fields not in DataDict:
>SELECT ;
>  * ;
>  FROM FieldsCursor ;
>  WHERE FieldsCursor.FieldName NOT IN ;
>    (SELECT FieldName FROM DataDict) ;
>  INTO CURSOR Cursor1
>
>* Get fields in DataDict no longer in the table:
>SELECT ;
>  * ;
>  FROM DataDict ;
>  WHERE DataDict.FieldName NOT IN ;
>    (SELECT FieldName FROM FieldsCursor) ;
>  INTO CURSOR Cursor2
>
>* If you massage the FieldsCursor to have the same structure as DataDict,
>* create a third cursor with the same structure:
>CREATE CURSOR Cursor3 ...
>
>* Append ALL fields from both source cursors:
>APPEND FROM FieldsCursor
>APPEND FROM DataDict
>
>* Use the GROUP BY clause on ALL the field attributes
>* e.g. type, size, decimals etc. If you get a COUNT of 2,
>* the fields are identical, if 1, there is a difference in one of the
>* field attributes:
>SELECT ;
>  FieldName, ;
>  COUNT(*) AS nCount ;
>  FROM Cursor3 ;
>  WHERE Cursor3.FieldName NOT IN ;
>    (SELECT FieldName FROM Cursor1) ;
>    AND Cursor3.FieldName NOT IN ;
>      (SELECT FieldName FROM Cursor2) ;
>  INTO Cursor4 ;
>  GROUP BY < list of all field attributes >
>  HAVING nCount < 2
Great! Thanks a lot, I'll probably then go forward with my idea.
I have a program modifystructure. It works just fine, though quite complicated. I was thinking about creating a custom object, which will have a_Fields array, a_Indexes and some other properties. Then I can easily manipulate with DataDict and oTable.

Thanks again.
If it's not broken, fix it until it is.


My Blog
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform