MySQL C++ Connector: How do I get the thread/connection Id?

时间:2016-07-11 22:30:37

标签: c++ mysql mysql-connector

I'm trying to find out how to obtain the MySQL Connection/thread id using Connector C++.

mysql_thread_id(MYSQL* ) seems to be available for just this, but I'm not sure how to get an instance of MYSQL from the Connector C++.

What I've tried:

  int threadId = mysql_thread_id(NULL);

But this just returns zero.

Any ideas?

1 个答案:

答案 0 :(得分:1)

函数mysql_thread_id()需要一个指向由本机MySQL C API的mysql_connect(...)函数创建的连接对象的指针。 Connector / C ++已将该对象埋藏得非常深(我看)。 MySQL文档here建议的替代方法是执行查询EXEC SQL SELECT (y).p_foo, (y).p_bar into :foo,:bar from (select foobar() y) x; ,返回的结果将是您要查找的ID。