0

When using mysql.h, there's a property called insert_id on the MYSQL connection object. Is there a similar feature when using a TADOConnection?

I am well ware of SELECT LAST_INSERT_ID();. What I'm asking is: If the C API has that feature, why is that feature missing in the ADO connector, if missing?

And if the only solution is to INSERT and SELECT the last insert id, are these two queries atomic, can some other INSERT queries be executed in-between, from a different connection, and make LAST_INSERT_ID return an unexpected value?

Since SQL-Server has OUTPUT Inserted.ID and Postgres has RETURNING id, I find MySQL to have made a dumb design choice with LAST_INSERT_ID().

Yanick Rochon
  • 51,409
  • 25
  • 133
  • 214
  • MySQL is not Microsoft SQL Server or PostgreSQL. If you prefer to use them, go ahead. You already know the answer to your question, there's a complete example in the documentation: https://dev.mysql.com/doc/connector-net/en/connector-net-faq.html So I don't know why you posted this question except to kvetch about a feature of MySQL that you don't like. – Bill Karwin May 13 '21 at 15:44
  • 1
    For the record, LAST_INSERT_ID() returns the last inserted value _in the current session_. It doesn't matter if another session inserts another row in the same table, this won't affect the value returned by LAST_INSERT_ID() in your session. – Bill Karwin May 13 '21 at 15:45

0 Answers0