是mysql_insert_id线程安全的? [英] Is mysql_insert_id thread safe?

查看:371
本文介绍了是mysql_insert_id线程安全的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用MySQL C API来构建一个数据库客户端应用程序,我需要得到一个INSERT语句中的最后一个自动增量值,所以mysql_insert_id呢。

但这个客户端是多线程和一块code像这样的:


的mysql_query(康涅狄格州,QUERY_STRING);
值= mysql_insert_id(康涅狄格州);

我不知道会是什么返回,该查询自动生成的ID或别的东西。任何线索?

先谢谢了。


解决方案

据该的文档 mysql_insert_id将返回最后插入成功的ID在当前连接

所以,如果你使用多个线程相同的连接不会被线程安全的。

I'm using MySQL C API to build a db client application, and i need to get the last autoincremented value in a INSERT statement, so mysql_insert_id does.

But this client is multithreaded and a piece of code like this:

mysql_query(conn, query_string); value = mysql_insert_id(conn);

I don't know what will it return, this query autogenerated id or something else. Any clues?

Thanks in advance.

解决方案

According to the documentation mysql_insert_id will return an id of the last successful insert on the current connection.

So if you use the same connection for several threads it will not be thread safe.

这篇关于是mysql_insert_id线程安全的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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