Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_databases thread: Concurrent Users - SELECT and UPDATE logic


Message #1 by "Paul Douglas" <pdouglas@t...> on Wed, 5 Feb 2003 00:20:59
Hi all,
I'm a bit of a newbie so this may be very obvious....however....

I'm having problems with the logic for the following problem :

On our intranet I'd like to create an inventory status list that shows who 
in the company has what items booked out at any time.  I have a form that 
shows all items that are currently available and allows a user to check an 
item they'd like to book.

When the form is submitted it goes to a piece of code similar to that 
below that first does a recheck to ensure that the item is STILL available 
(ie. objRS("Status")="A" to ensure another user hasn't booked it in the 
meantime).  If it is still available it performs an UPDATE to alter the 
items status and should generate a message saying that it's being booked - 
if not it would say that in the meantime another user has beaten them to 
booking the requested item.

Now I would have thought that this logic would work but what actually 
happens with this cut down, test code is that it performs the UPDATE ok 
but ALWAYS displays the "Sorry - You were too slow..." message.  It's as 
though the Database transactions are carried out FIRST and THEN the Status 
test is carried out AFTERWARDS always resulting in a Status of "B" and 
hence the "sorry - too slow...." message. I tried mucking around with 
Response.Flush etc to force output but to no avail.....

Can somebody please explain how ASP flows in a situation like this or 
point me in the right direction of getting the logic correct??  Any tips 
would be MOST appreciated....

Cheers
Paul

---------------------------------------------
' Usual DB Connection Stuff here....

strQuery="SELECT ID, Title, Status from Items WHERE ID=" & Request.Form
("frmID")
set objRS=objConn.Execute(strQuery)

if NOT objRS.EOF then
   if objRS("Status")="A" then
      strQuery="UPDATE Items Set Status='B' WHERE ID=" & objRS("ID")
      objConn.Execute(strQuery)
      Response.Write("Item Still Available - Booking Now...")
   else
      Response.Write("Sorry - You were too slow - item already booked by 
another user")
   end if
end if
---------------------------------------------


  Return to Index