Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Comparison of two fox tables
Message
De
30/12/2003 06:06:12
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
30/12/2003 02:32:53
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00862751
Message ID:
00862772
Vues:
15
>Dear All,
>
>I wanted to findout whether user made any changes in a fox table.
>Is there any function to do this ?
>
>Thanks in advance
>
>Jijo David

Jijo,
Comparison depends on what you're really looking for. ie:
-Compare 2 tables (with memo fields) that you've read access just to know if they're identical.

llIdentical = ;
FileToStr('myTable1.dbf') == FileToStr('myTable2.dbf') and ;
FileToStr('myTable1.fpt') == FileToStr('myTable2.fpt')

This is however is a byte-to-byte comparison.

-Check out 2 tables if they're identical by a record by record comparison. This one does it on either based on PK (if any), unique fields expression if no PK but fields to define a unique record or rec by rec if no unicity could be defined :
* With PK
? TablesAreIdentical('myTable1.dbf','myTable2.dbf',"myPK","myPK")

* No PK but Field1+Field2 defines a record uniquely
? TablesAreIdentical('myTable1.dbf','myTable2.dbf',"myField1+myField2")

* No expression to define a record uniquely 
* and didn't even want to create using all fields, 
* expecting they should be in same physical entry order
? TablesAreIdentical('myTable1.dbf','myTable2.dbf')

Function TablesAreIdentical
Lparameters tcTable1, tcTable2, tcPKExpr, tcPKTag
Local lcAlias, lcOldDeleted, llMisMatch
lcAlias = Alias()
lcOldDeleted = Set('deleted')
* We don't want to check if deleted match too
Set Deleted On

Use (tcTable1) In 0 Again Alias '_cmp1'
Use (tcTable2) In 0 Again Alias '_cmp2'

Local Array arrCnt1[1],arCnt2[1]
Select Cnt(*) From _cmp1 Into Array arrCnt1
Select Cnt(*) From _cmp2 Into Array arrCnt2
If arrCnt1 # arrCnt2
  llMisMatch = .T. && Reccount mismatch
Else
  Local loRecord1, loRecord2, llUseSeek, llUseLocate, luValue

  llUseSeek   = (!Empty(tcPKTag) And !Empty(tcPKExpr))
  llUseLocate = (!llUseSeek And !Empty(tcPKExpr))

  Select _cmp1
  Scan
    * If not both indexed use indexed one as table2
    * If none indexed but has unique field(s) use locate
    * If no unique field(s) then use recno instead
    Do Case
      Case llUseSeek
        If !Seek(&tcPKExpr, '_cmp2', tcPKTag)
          llMisMatch = .T.
          Exit
        Endif
      Case llUseLocate
        luValue = &tcPKExpr
        Select _cmp2
        Locate For &tcPKExpr = luValue
        If Eof()
          llMisMatch = .T.
          Exit
        Endif
      Otherwise
        Go Recno('_cmp1') In '_cmp2'
    Endcase
    Select _cmp2
    Scatter Name loRecord2 Memo
    Select _cmp1
    Scatter Name loRecord1 Memo
    If !Compobj(loRecord1, loRecord2)
      llMisMatch = .T.
      Exit
    Endif
  Endscan
Endif

Use In '_cmp1'
Use In '_cmp2'
If !Empty(lcAlias)
  Select (lcAlias)
Endif
Set Deleted &lcOldDeleted
Return !llMisMatch
And still yet there might be other comparison needs.
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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform