From 8a954bb5e763666b3f1f7fe8b18dd9cf3024e3b6 Mon Sep 17 00:00:00 2001 From: Jarle Aase Date: Tue, 16 Apr 2024 13:52:44 +0300 Subject: [PATCH] Trying to fix the Windows build. Thank you Microsoft for making my life interesting! --- CMakeLists.txt | 4 ++++ include/mysqlpool/mysqlpool.h | 14 +++++++------- src/mysqlpool.cpp | 4 ++-- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c593a83..4d0c7c1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -90,6 +90,10 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) set(MYSQLPOOL_ROOT ${CMAKE_CURRENT_SOURCE_DIR}) +if(WIN32) + add_compile_options(-D_WIN32_WINNT=0x0601 -DWINVER=0x0601 -DWIN32_LEAN_AND_MEAN=1) +endif() + message(STATUS "Using ${CMAKE_CXX_COMPILER}") if (MYSQLPOOL_WITH_CONAN) diff --git a/include/mysqlpool/mysqlpool.h b/include/mysqlpool/mysqlpool.h index ef14306..80f28b7 100644 --- a/include/mysqlpool/mysqlpool.h +++ b/include/mysqlpool/mysqlpool.h @@ -161,9 +161,9 @@ T getFirstArgument(T first, ArgsT...) { class Mysqlpool { enum class ErrorMode { - IGNORE, - RETRY, - ALWAYS_FAIL + EM_IGNORE, // Cant use "IGNORE" as it clashes with one of Microsofts *many* cursed macros! + EM_RETRY, + EM_ALWAYS_FAIL }; @@ -647,7 +647,7 @@ class Mysqlpool { logQuery("close-stmt", query); const auto [csec] = co_await connection().async_close_statement(*stmt, diag, tuple_awaitable); if (sec) { - handleError(sec, diag, ErrorMode::IGNORE); + handleError(sec, diag, ErrorMode::EM_IGNORE); } connectionWrapper()->stmtCache().erase(query); } @@ -717,9 +717,9 @@ class Mysqlpool { ErrorMode errorMode(const Options& opts) const noexcept { if (opts.reconnect_and_retry_query) { assert(!has_transaction_); - return ErrorMode::RETRY; + return ErrorMode::EM_RETRY; } - return ErrorMode::ALWAYS_FAIL; + return ErrorMode::EM_ALWAYS_FAIL; } void commitAndReleaseLater() noexcept { @@ -885,7 +885,7 @@ class Mysqlpool { // If it returns false, connection to server is closed static bool handleError(const boost::system::error_code& ec, boost::mysql::diagnostics& diag, - ErrorMode mode = ErrorMode::ALWAYS_FAIL); + ErrorMode mode = ErrorMode::EM_ALWAYS_FAIL); void startTimer(); diff --git a/src/mysqlpool.cpp b/src/mysqlpool.cpp index 6a352ea..d254640 100644 --- a/src/mysqlpool.cpp +++ b/src/mysqlpool.cpp @@ -216,7 +216,7 @@ bool Mysqlpool::handleError(const boost::system::error_code &ec, boost::mysql::d << "). Client: " << diag.client_message() << ". Server: " << diag.server_message()); - if (em == ErrorMode::IGNORE) { + if (em == ErrorMode::EM_IGNORE) { MYSQLPOOL_LOG_DEBUG_("Ignoring the error..."); return false; } @@ -230,7 +230,7 @@ bool Mysqlpool::handleError(const boost::system::error_code &ec, boost::mysql::d case boost::system::errc::connection_reset: case boost::system::errc::connection_aborted: case boost::asio::error::operation_aborted: - if (em == ErrorMode::RETRY) { + if (em == ErrorMode::EM_RETRY) { MYSQLPOOL_LOG_DEBUG_("The error is recoverable if we re-try the query it may succeed..."); return false; // retry }