Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Locking with SQL7
Message
De
29/02/2000 10:18:32
 
 
À
29/02/2000 02:38:44
Information générale
Forum:
Visual FoxPro
Catégorie:
Client/serveur
Divers
Thread ID:
00338970
Message ID:
00339096
Vues:
16
>Usually when a next recordnumber is generated in VFP for whatever table, the record containing the next number or even better, the whole table, is locked to prevent to 2 users to simultanously update the next nr. It's essential that the lock is placed before the update is done.
>
>How can this be done with client/server ?
>I don't want the autonumbering feature of the database server because I'm not creating a primary key (as a matter of fact, I do let create the PK by the de DBserver) but for example an invoice number that restarts at 1 every year, unless SQL allows to reset this numbering programmatically ...
lSuccess = .f.
Do While Not lSuccess
   cSQL = "SELECT LastNumber FROM NumberTable WHERE cKey = 'TABLENAME'"

   SQLExec(nConn, cSQL) 

   nLastNumber = SQLResult.LastNumber
   nNewId = nLastNumber + 1

   cSQL = "UPDATE NumberTable SET LastNumber = nNewID WHERE "+ ;
            "cKey='TABLENAME' and LastNumber = nLastNumber"

   lSuccess = ( SQLExec(nConn, cSQL) = 1 )
EndDo 
You will want to also check the resule of the first query, cause if it fails you could be in this loop for a while.

BOb
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform