Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Getting a Unique Id (sort of)
Message
From
04/12/2001 09:33:22
 
 
To
04/12/2001 09:08:59
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00589215
Message ID:
00589244
Views:
29
Hi!

In the moment between program figured out that PK is unique and record is saved, another user runs exactly the same process and use the same PK. Because sys(3) is time-depended, there is a high chance to get the same PK and write it to database. To avoid conflicts, you can only lock the entire table until you finish the insert (that is a bad idea).

There are a lot of other solutions to organize PK in VFP database.

In particular, take a look to the FAQ article about auto-increment fields in VFP database at the VFP Forum at the www.tek-tips.com site.

HTH.

>I am trying to generate and capture a unique id using the sys3 command. Once a id is created it checks a table that holds all the previous id's that were generated, if the id is found in the table already, then continue with process until it comes across one that doesnt match and then write to the table. Is this code accomplishing this? I am finding duplicate records in my Keytable.dbf.
>
>PARAMETERS mOdeType, pk_find
>
>*LOCAL m.pk_find
>
>m.pk_find = .F.
>
>IF !USED('KEYTABLE')
> USE (oVar.SysPath) + 'KEYTABLE.dbf' IN 0 SHARED
>ENDIF
>
>SELE KEYTABLE
>GO TOP
>
>*!* SET MULTILOCKS ON
>=CURSORSETPROP("BUFFERING",5)
>
>
>DO WHILE m.pk_find = .F.
> oVar.KeyId = SYS(3)
>
> SELE KEY_ID FROM KEYTABLE ;
> WHERE ALLT(KEYTABLE.KEY_ID) == ALLT(oVar.KeyId) ;
> INTO CURSOR PkIdFound
>
> SELE PkIdFound
> IF RECCOUNT() > 0 && PK ID FOR THIS PARTICULAR TABLE EXIST....LOOP
> m.pk_find = .F.
> LOOP
> ELSE
> m.pk_find = .T.
> DO CASE
> CASE ALLT(UPPER(mOdeType)) == 'UPDATE VTRANS'
> INSERT INTO KEYTABLE (KEY_ID, HTC_PROC) VALUE (oVar.KeyId, 'VTRANS UPDATE')
>
> CASE ALLT(UPPER(mOdeType)) == 'PRINT REPORTS'
> INSERT INTO KEYTABLE (KEY_ID, HTC_PROC) VALUE (oVar.KeyId, 'PRINT REPORTS')
>
> ENDCASE
>
> SELE KEYTABLE
> =TABLEUPDATE(.T.)
> ENDIF
>ENDDO
>
>RETURN
Vlad Grynchyshyn, Project Manager, MCP
vgryn@yahoo.com
ICQ #10709245
The professional level of programmer could be determined by level of stupidity of his/her bugs

It is not appropriate to say that question is "foolish". There could be only foolish answers. Everybody passed period of time when knows nothing about something.
Previous
Reply
Map
View

Click here to load this message in the networking platform