2

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?

GeoGo
  • 2,368
  • 2
  • 16
  • 11

2 Answers2

9

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;
}
Warren Young
  • 40,875
  • 8
  • 85
  • 101
4

You could use mysql_insert_id() C API function to retieve the auto-increment value after an insert. See also MySql Reference Manual

stacker
  • 68,052
  • 28
  • 140
  • 210