views:

120

answers:

1

I have a table with an auto-incrementing ID. After inserting a new row, I would like to retrieve the new ID.

I found an article that used the MySQL function LAST_INSERT_ID(). The article says to create a new query and submit it.

I'm using MySQL Connector C++, Windows XP and Vista, and Visual Studio 9.

Here are my questions:

  1. Is there an API, for the connector, that will fetch the ID out of the record?
  2. Does the result set, after an insert/append, contain the new ID?
  3. The LAST_INSERT_ID is MySQL specific. Is there an SQL standard method for obtaining the new ID?
A: 
  1. It doesn't look like it - in the C API, you have mysql_insert_id() for this, but it doesn't appear to be used in the C++ connector, nor does it appear to implement the getGeneratedKeys method from the JDBC API (However, I don't use this connector myself, so I may be missing something obvious...).
  2. No, there is no result set from an INSERT.
  3. No. Supposedly, DB2 is the only one that follows what the SQL standard says about auto-generated keys; everyone else does it differently (from both the standard and from each other).
Michael Madsen