From 7492d2ffe05337741d54f6d74ffcbaeaca7934e7 Mon Sep 17 00:00:00 2001 From: fasiondog Date: Thu, 3 May 2018 00:45:13 +0800 Subject: [PATCH] =?UTF-8?q?MySQL=E9=87=8D=E8=BF=9E=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kdata/mysql/MySQLKDataDriver.cpp | 42 +++++++++---------- .../kdata/mysql/MySQLKDataDriver.h | 2 - 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/libs/hikyuu/data_driver/kdata/mysql/MySQLKDataDriver.cpp b/libs/hikyuu/data_driver/kdata/mysql/MySQLKDataDriver.cpp index 594ea026..dcaaafdf 100644 --- a/libs/hikyuu/data_driver/kdata/mysql/MySQLKDataDriver.cpp +++ b/libs/hikyuu/data_driver/kdata/mysql/MySQLKDataDriver.cpp @@ -87,32 +87,32 @@ bool MySQLKDataDriver::_query(const string& sql_str) { return true; } - if(CR_SERVER_LOST == res || CR_SERVER_GONE_ERROR == res) { - //重新连接数据库 - shared_ptr mysql(new MYSQL, MySQLCloser()); - if (!mysql_init(mysql.get())) { - HKU_ERROR(" Initial MySQL handle error!" << func_name); - return false; - } + //重新连接数据库 + HKU_INFO("MySQL connect invalid, will retry connect!" << func_name); + m_mysql = NULL; - if (!mysql_real_connect(mysql.get(), m_host.c_str(), m_usr.c_str(), - m_pwd.c_str(), NULL, m_port, NULL, 0) ) { - HKU_ERROR(" Failed to connect to database!" << func_name); - return false; - } + shared_ptr mysql(new MYSQL, MySQLCloser()); + if (!mysql_init(mysql.get())) { + HKU_ERROR(" Initial MySQL handle error!" << func_name); + return false; + } - if (mysql_set_character_set(mysql.get(), "utf8")) { - HKU_ERROR(" mysql_set_character_set error!" << func_name); - return false; - } + if (!mysql_real_connect(mysql.get(), m_host.c_str(), m_usr.c_str(), + m_pwd.c_str(), NULL, m_port, NULL, 0) ) { + HKU_ERROR(" Failed to connect to database!" << func_name); + return false; + } - m_mysql = mysql; + if (mysql_set_character_set(mysql.get(), "utf8")) { + HKU_ERROR(" mysql_set_character_set error!" << func_name); + return false; + } - int res = mysql_query(m_mysql.get(), sql_str.c_str()); - if(!res) { - return true; - } + m_mysql = mysql; + res = mysql_query(m_mysql.get(), sql_str.c_str()); + if(!res) { + return true; } HKU_ERROR("mysql_query error! error no: " << res diff --git a/libs/hikyuu/data_driver/kdata/mysql/MySQLKDataDriver.h b/libs/hikyuu/data_driver/kdata/mysql/MySQLKDataDriver.h index ef169b3b..ff377035 100644 --- a/libs/hikyuu/data_driver/kdata/mysql/MySQLKDataDriver.h +++ b/libs/hikyuu/data_driver/kdata/mysql/MySQLKDataDriver.h @@ -12,10 +12,8 @@ #if defined(BOOST_WINDOWS) #include - #include #else #include - #include #endif namespace hku {