John,
Well I stand corrected.

On Wed, Mar 8, 2017 at 8:03 AM, John DeSoi via 4D_Tech <[email protected]
> wrote:

>
> > On Mar 8, 2017, at 9:09 AM, Kirk Brooks via 4D_Tech <
> [email protected]> wrote:
> >
> > Currently, let's say a user begins a transaction ​and the new record gets
> > the sequence number. Before that transaction is completed another user
> > starts a new record (or that user starts another process to create
> another
> > record) - and gets the same sequence number. The first one to save wins.
>
> This is not true if you are using 4D's Sequence number function. As long
> as you create a new record (or duplicate one) other processes will get a
> different sequence number.
>

​It is still a little wonky, though. I decided to test out what happens
with this test code:

​  // start a process and call seq num
$n:=Sequence number([ORDERS])
$msg:="At start: "+String($n)

$id1:=New process("__testSeq";0)
$id2:=New process("__testSeq";0)
$id3:=New process("__testSeq";0)

While (Process state($id1)>=0) | (Process state($id2)>=0) | (Process
state($id3)>=0)

DELAY PROCESS(Current process;60)

End while

$n:=Sequence number([ORDERS])
$msg:=$msg+"\rat end: "+String($n)
ALERT($msg)


​The __testSeg method is:

​$n:=Sequence number([ORDERS])
DELAY PROCESS(Current process;60*3)
ALERT("Proc # "+String(Current process)+"; seq n = "+String($n))


​Basically grab the seq num at the start (the test itself runs in a new
process, not the app process) then start three other processes which grab
the seqnum and delay for a few seconds before displaying an alert.

Each new process incremented the sequence number as you said. Back in the
original process, once all the others are done ​grab the seq number again.
To my surprise this is always the same as the start which seemed odd
because the sequence number actually gets incremented by testing it, though
not for every test.

Curious about it I inserted a delay between $id1 and $id2 - I wanted to
wait for the new process to have time to spawn and grab the sequence number
again. This 'mid' number was always the same as the starting number. So it
seems that each process gets only one call to the sequence number for a
given table until, presumably, the underlying table has a new record
created and saved. Just for fun I threw in a SAVE RECORD on the table (no
record was selected) to no effect.

If a subsequent call to sequence number is made it causes the sequence to
increment. So the final call my test method makes causes the sequence to
increment by 3 even through at the time that call is made the other
processes have quit and 'released' their numbers.


-- 
Kirk Brooks
San Francisco, CA
=======================
**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[email protected]
**********************************************************************

Reply via email to