On Fri, Jul 17, 2009 at 11:12:43AM -0400, Jason Pruim wrote:

> Hi everyone!
> So some of you may have noticed that I have been away for quite
> awhile... Been trying to get settled (Moved across the country) and
> getting a job.
> And now that that is done I have a question about a project that I
> might be doing for my current employer and want to do it properly.
> If all goes through, I'll be writing an online database that upwards
> of 10 people will be using at various times through out the day.
> Basically, in a form they fill out a model number, customer name,
> phone number etc. etc.. And then submit the form. After submitting
> they need to write the log number on some paperwork. If I have 2
> people submit the form at the same time, I'm thinking I could end up
> with a race condition and they might get the wrong log number (The log
> number is simply a consecutive record number)
> Do I need to be reading up on locking tables/rows? Or in my situation
> as I've briefly described it do I not have to worry about it? Or is
> there a third door with the magic bullet that will solve all my
> problems? :)

The database engine should take care of this for you. You left out some
details, so I'll make some assumptions. And I can only speak for
PostgreSQL, since I don't work that much with MySQL.

When using sequences in PostgreSQL, you can use the currval() function
to grab the last id number for the last record you added in this
session. Someone else running currval() will get the id number for the
last record they entered in their current session. No race condition
possible. In all this, I assume you just added a record and you want to
get the ID of that record. If you added a record yesterday, that's a
different story, but should not allow race conditions. A good database
engine should protect you in this area.


Paul M. Foster

PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to