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_INS开发者_运维技巧ERT_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:
- Is there an API, for the connector, that will fetch the ID out of the record?
- Does the result set, after an insert/append, contain the new ID?
- The
LAST_INSERT_ID
is MySQL specific. Is there an SQL standard method for obtaining the new ID?
- 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...).
- No, there is no result set from an INSERT.
- 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).
精彩评论