>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
Don't use any buffering on your keys table.
Craig Berntson
MCSD, Microsoft .Net MVP, Grape City Community Influencer