Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Auto Increment Primary Key
Message
 
 
À
24/05/1998 20:17:29
Information générale
Forum:
Visual FoxPro
Catégorie:
Applications Internet
Divers
Thread ID:
00101564
Message ID:
00101734
Vues:
68
The real stumbling block I see in your situation, Gene, is the desire to avoid locking. However, this is easily solved by using an updateable view to retrieve the primary key value, and store the incremented value. The following code uses a primary key table called KEYVALUE and an updateable view V_KEYVALUE that uses the table name as the view parameter. Rather than locking, it determines whether there is a collision, and if not, then the primary key value that it got from the table is ok to use. If there is a collision, then it grabs it again. Pretty simple, really.

FUNCTION NewID(tcTable)
ASSERT TYPE("tcTable") = "C" ;
AND ! EMPTY(tcTable)
LOCAL lnRetVal, ;
lcOldAlias
lcOldAlias = ALIAS()
lnRetVal = 0
vp_cTableName = tcTable
IF ! USED("v_KeyValue")
USE cmhoffic!v_KeyValue IN 0
ELSE
Requery("v_KeyValue")
ENDIF
IF _TALLY = 1
SELECT v_KeyValue
llSuccess = .F.
DO WHILE ! llSuccess
lnRetVal = v_KeyValue.iKeyValue
REPLACE v_KeyValue.iKeyValue WITH v_KeyValue.iKeyValue + 1
llSuccess = TABLEUPDATE(1)
IF ! llSuccess
Requery("v_KeyValue")
ENDIF
ENDDO
ENDIF
IF ! EMPTY(lcOldAlias)
SELECT (lcOldAlias)
ENDIF
RETURN lnRetVal


>Since VFP doesn't have an auto-increment field,
>how have others done their increment for web
>applications?
>
>I am using VFP tables and "ADO", we can't use any
>locking schemes.
>
>I don't want to use Access (too corruptable) or
>SQL Server (extra cost by my web hosting service).
>But those two databases do offer auto-increment.
>
>I was thinking of using Application variables
>but since every table has a primiary key,
>there would be too many Application variables.
>
>So once again ... how are you incrementing
>your primary keys from VB Script to VFP tables?
>>-Steve->>

Steve Sawyer
Geeks and Gurus, Inc.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform