Fix a Mysql connection error on Windows (#449)

This commit is contained in:
An Tao 2020-06-02 22:05:03 +08:00 committed by GitHub
parent c2f6aa0109
commit adab48e187
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 6 deletions

View File

@ -329,7 +329,6 @@ 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)
@ -337,6 +336,9 @@ if(BUILD_TESTING)
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")

View File

@ -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>
@ -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.
@ -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;