Use to work with a MySQL + + (library for C + +)
The database has some fields for which you AUTO_INCREMENT. How 开发者_运维百科to know what value will these fields when inserting a new row to the table?
While stacker's answer will work, MySQL++ wraps that function as SimpleResult::insert_id(). Example:
Query q = conn.query();
q.insert(something);
if (SimpleResult res = q.execute()) {
cout << "Auto-increment value: " << res.insert_id() << endl;
}
You could use mysql_insert_id()
C API function to retieve the auto-increment value after an insert.
See also MySql Reference Manual
精彩评论