如何设置autoreconnect选项与mysql连接器c ++ [英] How to set autoreconnect option with mysql connector c++

查看:1267
本文介绍了如何设置autoreconnect选项与mysql连接器c ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问候,我如何设置autoReconnect选项与mysql连接器c + +?
(不与mysql c api http:// dev .mysql.com / doc / refman / 5.0 / en / mysql-options.html

解决方案

不是这个库的用户,所以我的知识只是最后10分钟的价值,所以请进行验证。



作为一般规则,最好的资源关于图书馆的各种具体细节的使用的信息是看看它的单元测试。关于OSS的最好的事情。



所以,如果你看看MySQL连接器/ C ++单元测试,可以在他们的源代码树中找到,你会看到下面的提取。 p>

  sql :: ConnectOptionsMap connection_properties; 

...

connection_properties [OPT_RECONNECT] = true;
try
{
con.reset(driver-> connect(connection_properties));
}
catch(sql :: SQLException& e)
{
std :: cerr< e.what();
}

有关详细信息,请执行以下操作,以便您可以查看你自己。

 〜/ tmp $ bzr branch lp:〜mysql / mysql-connector-cpp / trunk mysql-connector-cpp 
〜/ tmp $ vi mysql-connector-cpp / test / unit / classes / connection.cpp +170
〜/ tmp $ vi mysql-connector-cpp / test / unit / classes / connection.h $所有这一切,在mysql中的重新连接选项必须非常仔细地使用,因为你将不得不重置。任何会话变量等。您必须将重新连接的连接视为全新的连接。这必须使用您正在使用的特定版本的MySQL的文档进行验证。


Greetings, how can i set autoReconnect option with mysql connector c++ ? ( not with mysql c api http://dev.mysql.com/doc/refman/5.0/en/mysql-options.html )

解决方案

I am not a user of this library, so my knowledge of it is only that last 10 mins worth, so please do verify.

As a general rule, the best resource of such information about usage of various specific details of a library is to take a look at its unit tests. The best thing about OSS.

So if you look at MySQL Connector/C++ unit tests that can be found on their source tree, you will see the below extract.

sql::ConnectOptionsMap connection_properties;

...

connection_properties["OPT_RECONNECT"]=true;
try
{
    con.reset(driver->connect(connection_properties));
}
catch (sql::SQLException &e)
{
    std::cerr << e.what();
}

For more information, please do the below, so that you can take a look yourselves.

~/tmp$ bzr branch lp:~mysql/mysql-connector-cpp/trunk mysql-connector-cpp
~/tmp$ vi mysql-connector-cpp/test/unit/classes/connection.cpp +170
~/tmp$ vi mysql-connector-cpp/test/unit/classes/connection.h 

Having said all that, reconnect option in mysql has to be used very carefully, as you will have to reset any session variables, etc. You will have to treat a reconnected connection as a brand new connection. This has to be verified with the documentation of the particular version of MySQL you are working with.

这篇关于如何设置autoreconnect选项与mysql连接器c ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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