diff --git a/src/mysql.cpp b/src/mysql.cpp index de7f773..555b5ab 100644 --- a/src/mysql.cpp +++ b/src/mysql.cpp @@ -475,7 +475,8 @@ void module::mysql_regist(sol::state* lua) "update", &module::mysql::update, "insert", &module::mysql::insert, "delete", &module::mysql::delete_, - "get", &module::mysql::get + "get", &module::mysql::get, + "recover", &module::mysql::recover ); module::mysql_result::regist(lua); @@ -541,6 +542,11 @@ std::shared_ptr module::mysql::get() return std::make_shared(m_pool->get()); } +void module::mysql::recover(std::shared_ptr conn) +{ + conn->free(); +} + void module::mysql::regist_global(const char* name, sol::state* lua) { lua->registry()[name] = this; @@ -682,14 +688,7 @@ module::mysql_conn::mysql_conn(ylib::mysql::conn* conn) module::mysql_conn::~mysql_conn() { - if (m_conn != nullptr) - { - if (m_conn->pool() != nullptr) - m_conn->pool()->recover(m_conn); - else - delete m_conn; - m_conn = nullptr; - } + free(); } int module::mysql_conn::connect(const std::string& ipaddress, const std::string& username, const std::string& password, const std::string& database, const std::string& charset, ushort port) @@ -763,6 +762,18 @@ std::shared_ptr module::mysql_conn::delete_() return std::make_shared(m_conn, false); } +void module::mysql_conn::free() +{ + if (m_conn != nullptr) + { + if (m_conn->pool() != nullptr) + m_conn->pool()->recover(m_conn); + else + delete m_conn; + m_conn = nullptr; + } +} + void module::mysql_conn::regist(sol::state* lua) { diff --git a/src/mysql.h b/src/mysql.h index c09307f..626a7bb 100644 --- a/src/mysql.h +++ b/src/mysql.h @@ -212,6 +212,7 @@ namespace module std::shared_ptr update(); std::shared_ptr delete_(); + void free(); static void regist(sol::state* lua); private: @@ -247,6 +248,8 @@ namespace module std::shared_ptr delete_(); std::shared_ptr get(); + + void recover(std::shared_ptr conn); private: std::shared_ptr m_pool;