Skip to content

Commit

Permalink
Fix a Mysql connection error on Windows (#449)
Browse files Browse the repository at this point in the history
  • Loading branch information
an-tao committed Jun 2, 2020
1 parent c2f6aa0 commit adab48e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -329,14 +329,16 @@ if(BUILD_TESTING)
add_subdirectory(lib/tests)
if(pg_FOUND)
add_subdirectory(${PROJECT_SOURCE_DIR}/orm_lib/src/postgresql_impl/test)
add_subdirectory(${PROJECT_SOURCE_DIR}/orm_lib/tests)
endif(pg_FOUND)
if(MySQL_FOUND)
add_subdirectory(${PROJECT_SOURCE_DIR}/orm_lib/src/mysql_impl/test)
endif(MySQL_FOUND)
if(SQLite3_FOUND)
add_subdirectory(${PROJECT_SOURCE_DIR}/orm_lib/src/sqlite3_impl/test)
endif(SQLite3_FOUND)
if(pg_FOUND OR MySQL_FOUND OR SQLite3_FOUND)
add_subdirectory(${PROJECT_SOURCE_DIR}/orm_lib/tests)
endif(pg_FOUND OR MySQL_FOUND OR SQLite3_FOUND)
find_package(GTest)
if(GTest_FOUND)
message(STATUS "gtest found")
Expand Down
19 changes: 14 additions & 5 deletions orm_lib/src/mysql_impl/MysqlConnection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
#include <errmsg.h>
#ifndef _WIN32
#include <poll.h>
#else
#define POLLIN (1U << 0)
#define POLLPRI (1U << 1)
#define POLLOUT (1U << 2)
#endif
#include <regex>

Expand Down Expand Up @@ -186,10 +190,13 @@ void MysqlConnection::handleTimeout()
waitStatus_ = mysql_real_connect_cont(&ret, mysqlPtr_.get(), status);
if (waitStatus_ == 0)
{
if (!ret)
auto errorNo = mysql_errno(mysqlPtr_.get());
if (!ret && errorNo)
{
handleClosed();
LOG_ERROR << "Error(" << errorNo << ") \""
<< mysql_error(mysqlPtr_.get()) << "\"";
LOG_ERROR << "Failed to mysql_real_connect()";
handleClosed();
return;
}
// I don't think the programe can run to here.
Expand Down Expand Up @@ -225,11 +232,13 @@ void MysqlConnection::handleEvent()
waitStatus_ = mysql_real_connect_cont(&ret, mysqlPtr_.get(), status);
if (waitStatus_ == 0)
{
if (!ret)
auto errorNo = mysql_errno(mysqlPtr_.get());
if (!ret && errorNo)
{
handleClosed();
// perror("");
LOG_ERROR << "Error(" << errorNo << ") \""
<< mysql_error(mysqlPtr_.get()) << "\"";
LOG_ERROR << "Failed to mysql_real_connect()";
handleClosed();
return;
}
status_ = ConnectStatus::Ok;
Expand Down

0 comments on commit adab48e

Please sign in to comment.