>From: Morris Hirsch <[EMAIL PROTECTED]>
>Reply-To: "Tag Libraries Users List" <[EMAIL PROTECTED]>
>To: Tag Libraries Users List <[EMAIL PROTECTED]>
>Subject: Re: JSTL: sql
>Date: Wed, 1 May 2002 13:35:21 -0400 (EDT)
>
>The problem is not about your own thread doing several related updates,
>but some other thread doing an INSERT just after you do,
>and before you get a chance to SELECT LAST_INSERT_ID()

Is that really a problem ? I believe that LAST_INSERT_ID() is specific to 
the database connection. You can have 3 threads, A B and C which do the 
following in cronological order.

Thread A inserts a record.
Thread B inserts a record.
Thread C inserts a record.
Thread A does SELECT LAST_INSERT_ID().    <--- returns ex. 1
Thread B does SELECT LAST_INSERT_ID().    <--- returns ex. 2
Thread C does SELECT LAST_INSERT_ID().    <--- returns ex. 3

That means that the auto_increment ID is specific to a connection. Otherwise 
this would be a very serious failing of MySQL.

Please do correct me if I'm wrong though.

Soefara Redzuan.


>If there is any chance of it (anything except a single user can do it)
>you must ensure thread safety with either single-thread attribute,
>or synchronize (this) on the block.
>
>On Wed, 1 May 2002, Paul DuBois wrote:
>
> > At 12:56 -0400 5/1/02, Carole E. Mah wrote:
> > >Does anyone know if the JSTL database tags (<sql>) provide any method 
>for
> > >retrieving the unique ID of the row that was inserted last (when you 
>set
> > >up you mySQL database table to AUTO_INCREMENT the unique id).
> > >
> > >This is how I do it using PHP, which provides the mysql_insert_id()
> > >function for just this purpose:
> > >
> > >   $query = "INSERT INTO foo (name, phone) VALUES ('Jane 
>Doe','555-1212')";
> > >   $LINK = mysql_pconnect ($DB_SERVER, $DB_LOGIN, $DB_PASSWORD);
> > >   $result = mysql_db_query ("$DB", $query);
> > >   $my_id = mysql_insert_id($LINK);
> > >
> > >Thanks!
> > >
> > >-carole
> >
> > Don't know of any such thing in JSTL, but you can issue this query
> > to get the value from the server:
> >
> > SELECT LAST_INSERT_ID()
> >
> > --
> > To unsubscribe, e-mail:   
><mailto:[EMAIL PROTECTED]>
> > For additional commands, e-mail: 
><mailto:[EMAIL PROTECTED]>
> >
> >
>
>
>--
>To unsubscribe, e-mail:   
><mailto:[EMAIL PROTECTED]>
>For additional commands, e-mail: 
><mailto:[EMAIL PROTECTED]>
>


_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to