Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Problem creating unique key
Message
 
To
All
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Problem creating unique key
Miscellaneous
Thread ID:
00251382
Message ID:
00251382
Views:
55
I have the following piece of code that is in my Session object to create a unique id for a table. I call it from forms that have a private datasession and optimistic record buffering. Basically, all it does is going in a wsseq table that contains the name of the table and the next number. From what I can see, it is very simple. Each time I create a record in mytable, I do an append blank and I replace the unique ident with oSession.get_next_id("mytable"). It works 99.9999% of the time but for a specific table, where a lot of data is created by several people, it fail sometime with a "uniqueness violated blablabla error".
I wonder how this could append?


oSession.get_next_id:

** Get the next id number in WsSeq
** And increase the table
PARAMETERS ltable

LOCAL cur_area, the_id

STORE SELECT() TO cur_area

SELECT 0
USE WsSeq ORDER TableId

IF SEEK (ALLTRIM(UPPER(ltable)))
DO WHILE !RLOCK()
WAIT "Data locked. Retry..." WINDOW NOWAIT
ENDDO
STORE WsSeq.next_Id TO the_id
REPLACE WsSeq.Next_Id WITH WsSeq.Next_Id + 1
UNLOCK
ELSE
STORE 1 TO the_id
INSERT INTO WsSeq VALUES (ltable, 2)
ENDIF

IF CURSORGETPROP("buffering","WsSeq") > 1
=TABLEUPDATE(.T.)
ENDIF


USE
SELECT (cur_area)
RETURN the_id
Eric Crespin
Consultant
PC PLUS Software Inc.
www.pcplus.ca
Next
Reply
Map
View

Click here to load this message in the networking platform