Qt的odbc驱动程序不支持MySQL的LastInsertId,解决方法是什么? [英] Qt's odbc driver does not support LastInsertId with mysql, whats the workaround?

查看:260
本文介绍了Qt的odbc驱动程序不支持MySQL的LastInsertId,解决方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Qt 4.8.3和MySQL ODBC 3.51驱动程序.该驱动程序似乎不支持我对此进行测试的LastInsertId:

Im using Qt 4.8.3 and the MySQL ODBC 3.51 Driver. The driver does not seem to support LastInsertId which I test like this:

db.driver()->hasFeature(QSqlDriver::LastInsertId)

我需要它来找到我刚刚插入的自动增量ID

I need it to find the auto increment id I just inserted

query.exec("INSERT INTO myTable (MyVal, Created) VALUES ('1', NOW())");
auto insertId = query.lastInsertId().toString();

最好的解决方法是什么?

What is the best workaround?

将有多个客户端同时访问此表.

there will be concurrent access to this table from multiple clients.

推荐答案

根据在插入查询之后,即使对于使用ODBC的用户,也可以获取为当前连接插入的最新ID.

after the insert query to get the latest id inserted for the current connection, even when using ODBC.

这篇关于Qt的odbc驱动程序不支持MySQL的LastInsertId,解决方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆