mysqldb simple question (find unique number)

Brian Langenberger brian at brian.cbs.umn.edu
Thu Apr 26 12:11:46 EDT 2001


Steve  Holden <sholden at holdenweb.com> wrote:
: "Jacek Pop³awski" <jp at ulgo.koti.com.pl> wrote in message
: news:slrn9eckbh.2f7.jp at localhost.localdomain...
:> id_producenta is primary key (int) for table producent
:> I need to find unique value for it, I use that code:

<snip!>

: Of course, you will realise that problems might arise should any two users
: concurrently try to use any such routine, since NySQL (as far as I remember)
: does not support transactions.

It might be better to simply use MySQL's "auto_increment" tag for
the key column.  That way, one can simply use "0" as the ID number
and MySQL will automatically generate a new, unique ID.

Of course, if you need to return that same ID again for other 
purposes, you'll need the max() function along with some table 
locking before and aftwarwards (to keep the process atomic).  




More information about the Python-list mailing list