Hello, Has anyone run into this problem: I have created a table with an auto_increment id. I want to be able to get the new id without having to do another query. Does someone know how to do this with Mysql? I.E. create table test( id NOT NULL auto_increment, name char(20)) insert into table test (name) values ("first"); > at this point I would like to get the id assigned to first without doing a select id from test where name ="first" is there a way to do this???? Thanks, Luis.
-----Original Message----- From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of Luis Cortes Sent: Monday, April 17, 2000 2:19 PM To: zope@zope.org Subject: [Zope] MySql and Auto_increment
Hello,
Has anyone run into this problem: I have created a table with an auto_increment id. I want to be able to get the new id without having to do another query. Does someone know how to do this with Mysql?
I.E.
create table test( id NOT NULL auto_increment, name char(20))
insert into table test (name) values ("first");
If your inserting from a SQL Method you can add the following after the insert statement: <dtml-var sql_delimiter> select LAST_INSERT_ID() as newid The method will return just like any other select SQL method with the auto number in 'newid'. I don't know, however, if there is a race issue if this is called by more than one client at "the same time" where one might end up getting the other's 'newid', since the ID is kept per connection. Anyone know if this is a problem? _______________________ Ron Bickers Logic Etc, Inc. rbickers@logicetc.com
I don't know about MySQL, but if it's anything like every other DBMS, it returns an object ID when you do an insert. The object id can be used to get the primary key. Luis Cortes wrote:
Hello,
Has anyone run into this problem: I have created a table with an auto_increment id. I want to be able to get the new id without having to do another query. Does someone know how to do this with Mysql?
I.E.
create table test( id NOT NULL auto_increment, name char(20))
insert into table test (name) values ("first");
> at this point I would like to get the id assigned to first without doing a select id from test where name ="first" is there a way to do this????
Thanks, Luis.
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
-- Ken Kinder 303.381.7631
participants (3)
-
Ken Kinder -
Luis Cortes -
Ron Bickers