Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Transactions - ???
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00300983
Message ID:
00301017
Vues:
36
Ken,

A transaction is a method for causing multiple table or record updates to be a single all-or-none operation. For example, take the creation of an invoice.

You need to:

1. Create the invoice header record
2. Create the invoice detail records
3. Create the accounts receivable record
4. Update the customer balance
5. Reduce the customer's available credit

Now the problem is what do you do if the first two operations succeed and the then the rest fail? Fatc is that the database is left in an invalid condition and there is no easy way to 1) know the database is invlaid and 2) correct the situation. Transactions are the solution to this problem. Here's some psuedocode for teh above example;

In the save operation for the invoice;
LOCAL llRollBack
llRollBack = .F.  && not actually required as LOCAL 
                  && creates a logical var and assigns it .F.

* Start a transaction
BEGIN TRANSACTION

* Process your table updates
IF NOT TableUpdate("Invoice")
   llRollBack = .T.
ENDIF

IF NOT llRollBack AND TableUpdate("InvDet")
   llRollBack = .T.
ENDIF

IF NOT llRollBack AND TableUpdate("Customer")
   llRollBack = .T.
ENDIF

IF NOT llRollBack AND TableUpdate("AcctRcvbl")
   llRollBack = .T.
ENDIF

IF llRollBack
   ROLLBACK  && revers the whole operation
ELSE
   END TRANSACTION && Committ the transaction
ENDIF
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform