Germancho
Programmer
- Jul 9, 2003
- 36
VFP 8.0 SP1
Windows XP Professional
Buffering set to 5
MULTILOCKS set to ON
I have a parent table (Invoices, PK: prefix + number) and a child table (Products, Normal Key: (prefix + number) with a one-to-many relation based on these common fields. The rules in the RI are set to Cascade (Update), Cascade (Delete) and Ignore (Insert).
In addition, I have a table (Consecutive) to keep the last number of the last invoice saved.
As several users can be using the invoice form simultaneously, I have a function to assign the invoice’s number:
FUNCTION fConsecutive (lcPrefix)
LOCAL lcArea, lcNumber
lcArea = SELECT()
SELECT Consecutive
SEEK (lcPrefix)
IF FOUND()
lcNumber = TRANS(VAL(MAX(Number, CURVAL('Number', 'Consecutive'))) + 1, "@L 99999999")
ELSE
lcNumber = '00000001'
ENDIF
REPLACE Number WITH lcNumber
SELECT (lcArea)
RETURN lcNumber
ENDFUNC
Both the server and the client show me the same number. What am I doing wrong? What's the best way to handle concurrency?
Thanks in advance for your help.
Germán Restrepo
Bogotá, Colombia
Windows XP Professional
Buffering set to 5
MULTILOCKS set to ON
I have a parent table (Invoices, PK: prefix + number) and a child table (Products, Normal Key: (prefix + number) with a one-to-many relation based on these common fields. The rules in the RI are set to Cascade (Update), Cascade (Delete) and Ignore (Insert).
In addition, I have a table (Consecutive) to keep the last number of the last invoice saved.
As several users can be using the invoice form simultaneously, I have a function to assign the invoice’s number:
FUNCTION fConsecutive (lcPrefix)
LOCAL lcArea, lcNumber
lcArea = SELECT()
SELECT Consecutive
SEEK (lcPrefix)
IF FOUND()
lcNumber = TRANS(VAL(MAX(Number, CURVAL('Number', 'Consecutive'))) + 1, "@L 99999999")
ELSE
lcNumber = '00000001'
ENDIF
REPLACE Number WITH lcNumber
SELECT (lcArea)
RETURN lcNumber
ENDFUNC
Both the server and the client show me the same number. What am I doing wrong? What's the best way to handle concurrency?
Thanks in advance for your help.
Germán Restrepo
Bogotá, Colombia