# HG changeset patch # User Sebastien Jodogne # Date 1531909660 -7200 # Node ID 6a574d810b98e736d01f231ce9c0bbd0954fa5ef # Parent 95f0f57f8920d710807cebd45aa92300b52b8a17 Compatibility with MySQL 8.0 diff -r 95f0f57f8920 -r 6a574d810b98 Framework/MySQL/MySQLDatabase.cpp --- a/Framework/MySQL/MySQLDatabase.cpp Tue Jul 17 08:50:53 2018 +0200 +++ b/Framework/MySQL/MySQLDatabase.cpp Wed Jul 18 12:27:40 2018 +0200 @@ -81,6 +81,19 @@ } + MySQLDatabase::~MySQLDatabase() + { + try + { + Close(); + } + catch (Orthanc::OrthancException&) + { + // Ignore possible exceptions due to connection loss + } + } + + void MySQLDatabase::LogError() { if (mysql_ != NULL) @@ -118,6 +131,13 @@ LOG(ERROR) << "Cannot initialize the MySQL connector"; throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); } + + if (parameters_.GetUnixSocket().empty()) + { + // Fallback to TCP connection if no UNIX socket is provided + unsigned int protocol = MYSQL_PROTOCOL_TCP; + mysql_options(mysql_, MYSQL_OPT_PROTOCOL, (unsigned int *) &protocol); + } const char* socket = (parameters_.GetUnixSocket().empty() ? NULL : parameters_.GetUnixSocket().c_str()); diff -r 95f0f57f8920 -r 6a574d810b98 Framework/MySQL/MySQLDatabase.h --- a/Framework/MySQL/MySQLDatabase.h Tue Jul 17 08:50:53 2018 +0200 +++ b/Framework/MySQL/MySQLDatabase.h Wed Jul 18 12:27:40 2018 +0200 @@ -47,10 +47,7 @@ public: MySQLDatabase(const MySQLParameters& parameters); - virtual ~MySQLDatabase() - { - Close(); - } + virtual ~MySQLDatabase(); void LogError(); diff -r 95f0f57f8920 -r 6a574d810b98 Framework/MySQL/MySQLParameters.cpp --- a/Framework/MySQL/MySQLParameters.cpp Tue Jul 17 08:50:53 2018 +0200 +++ b/Framework/MySQL/MySQLParameters.cpp Wed Jul 18 12:27:40 2018 +0200 @@ -33,7 +33,13 @@ password_.clear(); database_.clear(); port_ = 3306; + +#if defined(_WIN32) + unixSocket_.clear(); +#else unixSocket_ = "/var/run/mysqld/mysqld.sock"; +#endif + lock_ = true; } @@ -106,7 +112,7 @@ { if (database.empty()) { - LOG(ERROR) << "Empty database name"; + LOG(ERROR) << "MySQL: Empty database name"; throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); } @@ -114,8 +120,8 @@ { if (!isalnum(database [i])) { - LOG(ERROR) << "Only alphanumeric characters are allowed in a " - << "MySQL database name: \"" << database << "\""; + LOG(ERROR) << "MySQL: Only alphanumeric characters are allowed in a " + << "database name: \"" << database << "\""; throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); } } @@ -139,6 +145,13 @@ void MySQLParameters::SetUnixSocket(const std::string& socket) { +#if defined(_WIN32) + if (!socket.empty()) + { + LOG(WARNING) << "MySQL: Setting an UNIX socket on Windows has no effect"; + } +#endif + unixSocket_ = socket; } diff -r 95f0f57f8920 -r 6a574d810b98 Framework/MySQL/MySQLStatement.cpp --- a/Framework/MySQL/MySQLStatement.cpp Tue Jul 17 08:50:53 2018 +0200 +++ b/Framework/MySQL/MySQLStatement.cpp Wed Jul 18 12:27:40 2018 +0200 @@ -151,6 +151,7 @@ case 45: // utf8mb4_general_ci case 46: // utf8mb4_bin case 224: // utf8mb4_unicode_ci => RECOMMENDED collation + case 255: // utf8mb4_0900_ai_ci => necessary for MySQL 8.0 // https://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci orthancType_ = ValueType_Utf8String; break; @@ -395,6 +396,19 @@ } + MySQLStatement::~MySQLStatement() + { + try + { + Close(); + } + catch (Orthanc::OrthancException&) + { + // Ignore possible exceptions due to connection loss + } + } + + MYSQL_STMT* MySQLStatement::GetObject() { if (statement_ == NULL) diff -r 95f0f57f8920 -r 6a574d810b98 Framework/MySQL/MySQLStatement.h --- a/Framework/MySQL/MySQLStatement.h Tue Jul 17 08:50:53 2018 +0200 +++ b/Framework/MySQL/MySQLStatement.h Wed Jul 18 12:27:40 2018 +0200 @@ -49,10 +49,7 @@ MySQLStatement(MySQLDatabase& db, const Query& query); - virtual ~MySQLStatement() - { - Close(); - } + virtual ~MySQLStatement(); virtual bool IsReadOnly() const { diff -r 95f0f57f8920 -r 6a574d810b98 Framework/MySQL/MySQLTransaction.cpp --- a/Framework/MySQL/MySQLTransaction.cpp Tue Jul 17 08:50:53 2018 +0200 +++ b/Framework/MySQL/MySQLTransaction.cpp Wed Jul 18 12:27:40 2018 +0200 @@ -52,6 +52,7 @@ } catch (Orthanc::OrthancException&) { + // Ignore possible exceptions due to connection loss } } } diff -r 95f0f57f8920 -r 6a574d810b98 Framework/PostgreSQL/PostgreSQLDatabase.cpp --- a/Framework/PostgreSQL/PostgreSQLDatabase.cpp Tue Jul 17 08:50:53 2018 +0200 +++ b/Framework/PostgreSQL/PostgreSQLDatabase.cpp Wed Jul 18 12:27:40 2018 +0200 @@ -68,6 +68,19 @@ } } + + PostgreSQLDatabase::~PostgreSQLDatabase() + { + try + { + Close(); + } + catch (Orthanc::OrthancException&) + { + // Ignore possible exceptions due to connection loss + } + } + void PostgreSQLDatabase::Open() { diff -r 95f0f57f8920 -r 6a574d810b98 Framework/PostgreSQL/PostgreSQLDatabase.h --- a/Framework/PostgreSQL/PostgreSQLDatabase.h Tue Jul 17 08:50:53 2018 +0200 +++ b/Framework/PostgreSQL/PostgreSQLDatabase.h Wed Jul 18 12:27:40 2018 +0200 @@ -50,10 +50,7 @@ { } - ~PostgreSQLDatabase() - { - Close(); - } + ~PostgreSQLDatabase(); void Open(); diff -r 95f0f57f8920 -r 6a574d810b98 Framework/PostgreSQL/PostgreSQLResult.cpp --- a/Framework/PostgreSQL/PostgreSQLResult.cpp Tue Jul 17 08:50:53 2018 +0200 +++ b/Framework/PostgreSQL/PostgreSQLResult.cpp Wed Jul 18 12:27:40 2018 +0200 @@ -105,6 +105,19 @@ } + PostgreSQLResult::~PostgreSQLResult() + { + try + { + Clear(); + } + catch (Orthanc::OrthancException&) + { + // Ignore possible exceptions due to connection loss + } + } + + void PostgreSQLResult::Next() { position_++; diff -r 95f0f57f8920 -r 6a574d810b98 Framework/PostgreSQL/PostgreSQLResult.h --- a/Framework/PostgreSQL/PostgreSQLResult.h Tue Jul 17 08:50:53 2018 +0200 +++ b/Framework/PostgreSQL/PostgreSQLResult.h Wed Jul 18 12:27:40 2018 +0200 @@ -46,10 +46,7 @@ public: explicit PostgreSQLResult(PostgreSQLStatement& statement); - ~PostgreSQLResult() - { - Clear(); - } + ~PostgreSQLResult(); void Next(); diff -r 95f0f57f8920 -r 6a574d810b98 Framework/PostgreSQL/PostgreSQLStatement.cpp --- a/Framework/PostgreSQL/PostgreSQLStatement.cpp Tue Jul 17 08:50:53 2018 +0200 +++ b/Framework/PostgreSQL/PostgreSQLStatement.cpp Wed Jul 18 12:27:40 2018 +0200 @@ -342,6 +342,19 @@ } + PostgreSQLStatement::~PostgreSQLStatement() + { + try + { + Unprepare(); + } + catch (Orthanc::OrthancException&) + { + // Ignore possible exceptions due to connection loss + } + } + + void PostgreSQLStatement::Run() { PGresult* result = reinterpret_cast(Execute()); diff -r 95f0f57f8920 -r 6a574d810b98 Framework/PostgreSQL/PostgreSQLStatement.h --- a/Framework/PostgreSQL/PostgreSQLStatement.h Tue Jul 17 08:50:53 2018 +0200 +++ b/Framework/PostgreSQL/PostgreSQLStatement.h Wed Jul 18 12:27:40 2018 +0200 @@ -72,10 +72,7 @@ PostgreSQLStatement(PostgreSQLDatabase& database, const Query& query); - ~PostgreSQLStatement() - { - Unprepare(); - } + ~PostgreSQLStatement(); virtual bool IsReadOnly() const { diff -r 95f0f57f8920 -r 6a574d810b98 Framework/PostgreSQL/PostgreSQLTransaction.cpp --- a/Framework/PostgreSQL/PostgreSQLTransaction.cpp Tue Jul 17 08:50:53 2018 +0200 +++ b/Framework/PostgreSQL/PostgreSQLTransaction.cpp Wed Jul 18 12:27:40 2018 +0200 @@ -49,6 +49,7 @@ } catch (Orthanc::OrthancException&) { + // Ignore possible exceptions due to connection loss } } } diff -r 95f0f57f8920 -r 6a574d810b98 MySQL/NEWS --- a/MySQL/NEWS Tue Jul 17 08:50:53 2018 +0200 +++ b/MySQL/NEWS Wed Jul 18 12:27:40 2018 +0200 @@ -1,6 +1,8 @@ Pending changes in the mainline =============================== +* Compatibility with MySQL 8.0 +* Improvement in the configuration of UNIX socket Release 1.0 (2018-07-17) diff -r 95f0f57f8920 -r 6a574d810b98 MySQL/UnitTests/UnitTestsMain.cpp --- a/MySQL/UnitTests/UnitTestsMain.cpp Tue Jul 17 08:50:53 2018 +0200 +++ b/MySQL/UnitTests/UnitTestsMain.cpp Wed Jul 18 12:27:40 2018 +0200 @@ -190,14 +190,19 @@ { if (argc < 5) { - std::cerr << "Usage (UNIX): " << argv[0] << " " - << std::endl - << "Usage (Windows): " << argv[0] << " " - << std::endl << std::endl - << "Example (UNIX): " << argv[0] << " /var/run/mysqld/mysqld.sock root root orthanctest" - << std::endl - << "Example (Windows): " << argv[0] << " localhost 3306 root root orthanctest" - << std::endl << std::endl; + std::cerr +#if !defined(_WIN32) + << "Usage (UNIX socket): " << argv[0] << " " + << std::endl +#endif + << "Usage (TCP connection): " << argv[0] << " " + << std::endl << std::endl +#if !defined(_WIN32) + << "Example (UNIX socket): " << argv[0] << " /var/run/mysqld/mysqld.sock root root orthanctest" + << std::endl +#endif + << "Example (TCP connection): " << argv[0] << " localhost 3306 root root orthanctest" + << std::endl << std::endl; return -1; } @@ -222,7 +227,8 @@ if (args.size() == 4) { - // UNIX flavor + // UNIX socket flavor + globalParameters_.SetHost(""); globalParameters_.SetUnixSocket(args[0]); globalParameters_.SetUsername(args[1]); globalParameters_.SetPassword(args[2]); @@ -230,12 +236,15 @@ } else if (args.size() == 5) { - // Windows flavor + // TCP connection flavor globalParameters_.SetHost(args[0]); globalParameters_.SetPort(boost::lexical_cast(args[1])); globalParameters_.SetUsername(args[2]); globalParameters_.SetPassword(args[3]); globalParameters_.SetDatabase(args[4]); + + // Force the use of TCP on localhost, even if UNIX sockets are available + globalParameters_.SetUnixSocket(""); } else { diff -r 95f0f57f8920 -r 6a574d810b98 Resources/CMake/DatabasesPluginConfiguration.cmake --- a/Resources/CMake/DatabasesPluginConfiguration.cmake Tue Jul 17 08:50:53 2018 +0200 +++ b/Resources/CMake/DatabasesPluginConfiguration.cmake Wed Jul 18 12:27:40 2018 +0200 @@ -33,7 +33,7 @@ message(FATAL_ERROR "Unsupported version of the Orthanc plugin SDK: ${ORTHANC_SDK_VERSION}") endif() else () - CHECK_INCLUDE_FILE_CXX(orthanc/OrthancCppDatabasePlugin.h HAVE_ORTHANC_H) + CHECK_INCLUDE_FILE_CXX(orthanc/OrthancCDatabasePlugin.h HAVE_ORTHANC_H) if (NOT HAVE_ORTHANC_H) message(FATAL_ERROR "Please install the headers of the Orthanc plugins SDK") endif()