Claudine:  I see a problem in that you aren't checking whether the
'SET LOCK" fails.  It can happen if 2 people are doing it simultaneously
(probably small chance of that if your select and update are fast), but
also because I've seen tables get locked and never unlocked.

You should put your error variable check after the SET LOCK and quit
the program if the lock cannot be set.

Karen

 
> I'm using the following code which regularly burps when more than two 
> users
> are logged in:
> 
> -------------------------------------------------------------
> --LOCK TABLE TO PREVENT OTHER USERS FROM GRABBING SAME NUMBER
> -------------------------------------------------------------
> SET LOCK d_water_invoice_numbers ON
> --Grab next invoice number
> SELECT winvoice_id INTO vwinvoiceid INDICATOR iv1  +
> FROM d_water_invoice_numbers  +
> WHERE used_nb = 'N' AND LIMIT = 1
> --Mark that number as "used" so no one else can attempt to use it!
> UPDATE d_water_invoice_numbers SET used_nb = 'Y'  +
> WHERE winvoice_id = .vwinvoiceid
> -------------------------------------------------------------
> --UNLOCK TABLE
> -------------------------------------------------------------
> SET LOCK d_water_invoice_numbers OFF
> -------------------------------------------------------------
> 
> Claudine 

Reply via email to