开发者

MySQL++ and AUTO_INCREMENT

开发者 https://www.devze.com 2023-01-29 22:55 出处:网络
Use to work with a MySQL + + (library for C + +) The database has some fields for which you AUTO_INCREMENT.

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

0

精彩评论

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