开发者

MySQL, C++: Retrieving auto-increment ID

开发者 https://www.devze.com 2022-12-29 16:34 出处:网络
I have a table with an auto-incrementing ID.After inserting a new row, I would like to retrieve the new ID.

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:

  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?


  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).
0

精彩评论

暂无评论...
验证码 换一张
取 消