Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Confused about Buffering and TableUpdate
Message
De
16/04/2001 22:17:32
 
 
À
16/04/2001 19:32:38
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00495972
Message ID:
00495989
Vues:
10
>Hi.
>I am confused about how tableupdate works. I have a piece of code where I want to scan a table and based on records in this table, delete other records in other tables.
>BEGIN TRANSACTION
>SELECT drivertable
>SCAN FOR &somecondition
>     primkey = drivertable.primkey
>     SELECT table2
>     DELETE <b>ALL</b> FOR table2.keyfield = primkey
>
>     SELECT table3
>     DELETE <b>ALL</b> FOR table2.keyfield = primkey
>ENDSCAN
>
>SELE drivertable
>DELETE FOR &somecondition
>END TRANSACTION
>
>The question is where do I put the TABLEUPDATE. In the past I tried:
>okFlag = .T.
>BEGIN TRANSACTION
>SELECT drivertable
>IF !TABLEUPDATE()
>  okFlag = .F.
>ENDIF
>
>IF OKFlag
>  SCAN FOR &somecondition
>     primkey = drivertable.primkey
>     SELECT table2
>     IF !TABLEUPDATE(.T.,.T.)
>        okFlag = .F.
>     ENDIF
>     IF okFlag
>       DELETE FOR table2.keyfield = primkey
>     ENDIF
>
>     SELECT table3
>     IF !TABLEUPDATE(.T.,.T.)
>        okFlag = .F.
>     ENDIF
>     IF okFlag
>       DELETE FOR table2.keyfield = primkey
>     ENDIF
>
>ENDSCAN
>
>SELE drivertable
>IF !TABLEUPDATE(.T.,.T.)
>   okFlag = .F.
>ENDIF
>IF OkFlag
>  DELETE FOR &somecondition
>ENDIF
>IF okFlag
>  END TRANSACTION
>ELSE
>  ROLLBACK
>  =TABLEREVERT(.F.,"drivertable")
>  =TABLEREVERT(.F.,"table2")
>  =TABLEREVERT(.F.,"table3")
>ENDIF
>
>
>but for some reason my SCAN/ENDSCAN only processes one drivertable record and then because it did not delete the records in table2 and table3 for the second, etc. record in the drivertable file, it dies because my referential integrity rules will not allow a delete if a record exists matching its key in table2 or table3. I am setting up this routine to 'get around' the referential integrity rules when I allow purging of old data, but can't figure out what I am doing wrong. Can someone clarify how this buffering is working. I am using optimistic row buffering.

Before you get too carried away with TABLEUPDATE(), it looks like you might want to use DELETE ALL as indicated above. Remember that the default scope for DELETE is NEXT 1, so unless the record pointer happens to be on the record you want to delete in tables 2 and 3, nothing will happen.

You can also use the DELETE - SQL syntax here, such as
DELETE FROM Table2 WHERE Table2.KeyField = m.primkey
Note that this is a completely different command from the xBASE DELETE.
Regards. Al

"Violence is the last refuge of the incompetent." -- Isaac Asimov
"Never let your sense of morals prevent you from doing what is right." -- Isaac Asimov

Neither a despot, nor a doormat, be

Every app wants to be a database app when it grows up
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform