[Zope] Re: [Zope-dev] MySQL with LAST_INSERT_ID()

Philipp Auersperg zope@philosoft.at
Mon, 08 Jan 2001 12:19:49 +0100


Be careful with last_insert_id() and similar sql functions and Zope and more than one simultanous user:

since all requests run over the same physical database connection, it is not guaranteed
 that your call last_insert_id() returns YOUR last inserted record ID. if another user performs an insert
 in the right moment you get HIS last id.

the scenario:

user1 inserts  (gets ID 42)
						user 2 inserts (gets ID 43)
user1 calls last_insert_id() (gets 43)


phil
*********** REPLY SEPARATOR  ***********

On 08.01.2001 at 08:27 Arno Gross wrote:

>Dieters assumption was right. 
>LAST_INSERTED_ID() returns a numeric value and
>that seems to be the problem. So if I change the statement as this: 
>SELECT CONV(LAST_INSERT_ID(),10,10) 
>it works (CONV returns a string!)
>
>P.S. Soren, maybe you can update your HowTo with a short note. Another
>possibilty instead of using LAST_INSERT_ID can be using MAX(). That should
>work  too.
>
>Thanks
>   Arno
>On Sat, 06 Jan
>2001, Dieter Maurer wrote: > Arno Gross writes:
>>  > SELECT LAST_INSERT_ID()
>>  > 
>>  > This method works with Zope 2.2.4 under Linux and MySQL 3.22.32
>>  > but I got an error with Zope 2.2.2 under NT 4.0 and MySQL 3.22.29
>>  >    Error, exceptions.KeyError: unhandled
>> Sieht aus, als könnte der MySQL Anschluss den
>> Rückgabewert von "LAST_INSERT_ID" nicht in einen Python
>> Datentyp wandeln, würde deshalb gerne eine "unhandled"
>> Funktion aus einen Dictionary auslesen, die leider
>> nicht drin ist.
>> 
>> Sieht für mich nach einem Upgrade auf eine neuere Version
>> von MySQL bzw. seinen Python Anschluss aus.
>> 
>> Allerdings müsste man zunächst den Traceback genau anschauen,
>> ob meine Vermutung auch wirklich zutrifft.
>> 
>> 
>> Dieter
>-------------------------------------------------------
>
>_______________________________________________
>Zope-Dev maillist  -  Zope-Dev@zope.org
>http://lists.zope.org/mailman/listinfo/zope-dev
>**  No cross posts or HTML encoding!  **
>(Related lists - 
> http://lists.zope.org/mailman/listinfo/zope-announce
> http://lists.zope.org/mailman/listinfo/zope )