# HG changeset patch # User Sebastien Jodogne # Date 1531909732 -7200 # Node ID 771b3c4bf5f850871c76c0d18a45ca829afb7c68 # Parent 6a574d810b98e736d01f231ce9c0bbd0954fa5ef# Parent 4b2dab49b6ea1f3369e769b0ce94e00c4ea32f1f integration OrthancPostgreSQL-2.2->mainline diff -r 4b2dab49b6ea -r 771b3c4bf5f8 Framework/MySQL/MySQLDatabase.cpp --- a/Framework/MySQL/MySQLDatabase.cpp Tue Jul 17 08:53:20 2018 +0200 +++ b/Framework/MySQL/MySQLDatabase.cpp Wed Jul 18 12:28:52 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 4b2dab49b6ea -r 771b3c4bf5f8 Framework/MySQL/MySQLDatabase.h --- a/Framework/MySQL/MySQLDatabase.h Tue Jul 17 08:53:20 2018 +0200 +++ b/Framework/MySQL/MySQLDatabase.h Wed Jul 18 12:28:52 2018 +0200 @@ -47,10 +47,7 @@ public: MySQLDatabase(const MySQLParameters& parameters); - virtual ~MySQLDatabase() - { - Close(); - } + virtual ~MySQLDatabase(); void LogError(); diff -r 4b2dab49b6ea -r 771b3c4bf5f8 Framework/MySQL/MySQLParameters.cpp --- a/Framework/MySQL/MySQLParameters.cpp Tue Jul 17 08:53:20 2018 +0200 +++ b/Framework/MySQL/MySQLParameters.cpp Wed Jul 18 12:28:52 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 4b2dab49b6ea -r 771b3c4bf5f8 Framework/MySQL/MySQLStatement.cpp --- a/Framework/MySQL/MySQLStatement.cpp Tue Jul 17 08:53:20 2018 +0200 +++ b/Framework/MySQL/MySQLStatement.cpp Wed Jul 18 12:28:52 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 4b2dab49b6ea -r 771b3c4bf5f8 Framework/MySQL/MySQLStatement.h --- a/Framework/MySQL/MySQLStatement.h Tue Jul 17 08:53:20 2018 +0200 +++ b/Framework/MySQL/MySQLStatement.h Wed Jul 18 12:28:52 2018 +0200 @@ -49,10 +49,7 @@ MySQLStatement(MySQLDatabase& db, const Query& query); - virtual ~MySQLStatement() - { - Close(); - } + virtual ~MySQLStatement(); virtual bool IsReadOnly() const { diff -r 4b2dab49b6ea -r 771b3c4bf5f8 Framework/MySQL/MySQLTransaction.cpp --- a/Framework/MySQL/MySQLTransaction.cpp Tue Jul 17 08:53:20 2018 +0200 +++ b/Framework/MySQL/MySQLTransaction.cpp Wed Jul 18 12:28:52 2018 +0200 @@ -52,6 +52,7 @@ } catch (Orthanc::OrthancException&) { + // Ignore possible exceptions due to connection loss } } } diff -r 4b2dab49b6ea -r 771b3c4bf5f8 Framework/PostgreSQL/PostgreSQLDatabase.cpp --- a/Framework/PostgreSQL/PostgreSQLDatabase.cpp Tue Jul 17 08:53:20 2018 +0200 +++ b/Framework/PostgreSQL/PostgreSQLDatabase.cpp Wed Jul 18 12:28:52 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 4b2dab49b6ea -r 771b3c4bf5f8 Framework/PostgreSQL/PostgreSQLDatabase.h --- a/Framework/PostgreSQL/PostgreSQLDatabase.h Tue Jul 17 08:53:20 2018 +0200 +++ b/Framework/PostgreSQL/PostgreSQLDatabase.h Wed Jul 18 12:28:52 2018 +0200 @@ -50,10 +50,7 @@ { } - ~PostgreSQLDatabase() - { - Close(); - } + ~PostgreSQLDatabase(); void Open(); diff -r 4b2dab49b6ea -r 771b3c4bf5f8 Framework/PostgreSQL/PostgreSQLResult.cpp --- a/Framework/PostgreSQL/PostgreSQLResult.cpp Tue Jul 17 08:53:20 2018 +0200 +++ b/Framework/PostgreSQL/PostgreSQLResult.cpp Wed Jul 18 12:28:52 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 4b2dab49b6ea -r 771b3c4bf5f8 Framework/PostgreSQL/PostgreSQLResult.h --- a/Framework/PostgreSQL/PostgreSQLResult.h Tue Jul 17 08:53:20 2018 +0200 +++ b/Framework/PostgreSQL/PostgreSQLResult.h Wed Jul 18 12:28:52 2018 +0200 @@ -46,10 +46,7 @@ public: explicit PostgreSQLResult(PostgreSQLStatement& statement); - ~PostgreSQLResult() - { - Clear(); - } + ~PostgreSQLResult(); void Next(); diff -r 4b2dab49b6ea -r 771b3c4bf5f8 Framework/PostgreSQL/PostgreSQLStatement.cpp --- a/Framework/PostgreSQL/PostgreSQLStatement.cpp Tue Jul 17 08:53:20 2018 +0200 +++ b/Framework/PostgreSQL/PostgreSQLStatement.cpp Wed Jul 18 12:28:52 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 4b2dab49b6ea -r 771b3c4bf5f8 Framework/PostgreSQL/PostgreSQLStatement.h --- a/Framework/PostgreSQL/PostgreSQLStatement.h Tue Jul 17 08:53:20 2018 +0200 +++ b/Framework/PostgreSQL/PostgreSQLStatement.h Wed Jul 18 12:28:52 2018 +0200 @@ -72,10 +72,7 @@ PostgreSQLStatement(PostgreSQLDatabase& database, const Query& query); - ~PostgreSQLStatement() - { - Unprepare(); - } + ~PostgreSQLStatement(); virtual bool IsReadOnly() const { diff -r 4b2dab49b6ea -r 771b3c4bf5f8 Framework/PostgreSQL/PostgreSQLTransaction.cpp --- a/Framework/PostgreSQL/PostgreSQLTransaction.cpp Tue Jul 17 08:53:20 2018 +0200 +++ b/Framework/PostgreSQL/PostgreSQLTransaction.cpp Wed Jul 18 12:28:52 2018 +0200 @@ -49,6 +49,7 @@ } catch (Orthanc::OrthancException&) { + // Ignore possible exceptions due to connection loss } } } diff -r 4b2dab49b6ea -r 771b3c4bf5f8 MySQL/CMakeLists.txt --- a/MySQL/CMakeLists.txt Tue Jul 17 08:53:20 2018 +0200 +++ b/MySQL/CMakeLists.txt Wed Jul 18 12:28:52 2018 +0200 @@ -17,11 +17,45 @@ include(${CMAKE_SOURCE_DIR}/../Resources/CMake/DatabasesPluginConfiguration.cmake) + +if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows") + execute_process( + COMMAND + ${PYTHON_EXECUTABLE} ${ORTHANC_ROOT}/Resources/WindowsResources.py + ${ORTHANC_PLUGIN_VERSION} "MySQL storage area plugin" OrthancMySQLStorage.dll + "MySQL as a database back-end to Orthanc (storage area)" + ERROR_VARIABLE Failure + OUTPUT_FILE ${AUTOGENERATED_DIR}/StorageVersion.rc + ) + + if (Failure) + message(FATAL_ERROR "Error while computing the version information: ${Failure}") + endif() + + execute_process( + COMMAND + ${PYTHON_EXECUTABLE} ${ORTHANC_ROOT}/Resources/WindowsResources.py + ${ORTHANC_PLUGIN_VERSION} "MySQL index plugin" OrthancMySQLIndex.dll + "MySQL as a database back-end to Orthanc (index)" + ERROR_VARIABLE Failure + OUTPUT_FILE ${AUTOGENERATED_DIR}/IndexVersion.rc + ) + + if (Failure) + message(FATAL_ERROR "Error while computing the version information: ${Failure}") + endif() + + set(INDEX_RESOURCES ${AUTOGENERATED_DIR}/IndexVersion.rc) + set(STORAGE_RESOURCES ${AUTOGENERATED_DIR}/StorageVersion.rc) +endif() + + EmbedResources( MYSQL_PREPARE_INDEX ${CMAKE_SOURCE_DIR}/Plugins/PrepareIndex.sql ) add_library(OrthancMySQLIndex SHARED + ${INDEX_RESOURCES} ${ORTHANC_DATABASES_ROOT}/Framework/Plugins/PluginInitialization.cpp Plugins/IndexPlugin.cpp Plugins/MySQLIndex.cpp @@ -32,6 +66,7 @@ add_library(OrthancMySQLStorage SHARED ${ORTHANC_DATABASES_ROOT}/Framework/Plugins/PluginInitialization.cpp + ${STORAGE_RESOURCES} Plugins/MySQLStorageArea.cpp Plugins/StoragePlugin.cpp diff -r 4b2dab49b6ea -r 771b3c4bf5f8 MySQL/NEWS --- a/MySQL/NEWS Tue Jul 17 08:53:20 2018 +0200 +++ b/MySQL/NEWS Wed Jul 18 12:28:52 2018 +0200 @@ -1,4 +1,11 @@ Pending changes in the mainline =============================== +* Compatibility with MySQL 8.0 +* Improvement in the configuration of UNIX socket + + +Release 1.0 (2018-07-17) +======================== + * Initial release diff -r 4b2dab49b6ea -r 771b3c4bf5f8 MySQL/Plugins/IndexPlugin.cpp --- a/MySQL/Plugins/IndexPlugin.cpp Tue Jul 17 08:53:20 2018 +0200 +++ b/MySQL/Plugins/IndexPlugin.cpp Wed Jul 18 12:28:52 2018 +0200 @@ -23,7 +23,9 @@ #include "../../Framework/MySQL/MySQLDatabase.h" #include "../../Framework/Plugins/PluginInitialization.h" +#include #include +#include static std::auto_ptr backend_; @@ -37,6 +39,9 @@ return -1; } + Orthanc::Toolbox::InitializeOpenSsl(); + Orthanc::HttpClient::GlobalInitialize(); + OrthancPlugins::OrthancConfiguration configuration(context); if (!configuration.IsSection("MySQL")) @@ -88,6 +93,8 @@ backend_.reset(NULL); OrthancDatabases::MySQLDatabase::GlobalFinalization(); + Orthanc::HttpClient::GlobalFinalize(); + Orthanc::Toolbox::FinalizeOpenSsl(); } diff -r 4b2dab49b6ea -r 771b3c4bf5f8 MySQL/Plugins/StoragePlugin.cpp --- a/MySQL/Plugins/StoragePlugin.cpp Tue Jul 17 08:53:20 2018 +0200 +++ b/MySQL/Plugins/StoragePlugin.cpp Wed Jul 18 12:28:52 2018 +0200 @@ -23,7 +23,9 @@ #include "../../Framework/MySQL/MySQLDatabase.h" #include "../../Framework/Plugins/PluginInitialization.h" +#include #include +#include extern "C" @@ -35,6 +37,9 @@ return -1; } + Orthanc::Toolbox::InitializeOpenSsl(); + Orthanc::HttpClient::GlobalInitialize(); + OrthancPlugins::OrthancConfiguration configuration(context); if (!configuration.IsSection("MySQL")) @@ -82,6 +87,8 @@ OrthancDatabases::StorageBackend::Finalize(); OrthancDatabases::MySQLDatabase::GlobalFinalization(); + Orthanc::HttpClient::GlobalFinalize(); + Orthanc::Toolbox::FinalizeOpenSsl(); } diff -r 4b2dab49b6ea -r 771b3c4bf5f8 MySQL/UnitTests/UnitTestsMain.cpp --- a/MySQL/UnitTests/UnitTestsMain.cpp Tue Jul 17 08:53:20 2018 +0200 +++ b/MySQL/UnitTests/UnitTestsMain.cpp Wed Jul 18 12:28:52 2018 +0200 @@ -31,7 +31,9 @@ #include "../../Framework/MySQL/MySQLTransaction.h" #include "../../Framework/Plugins/IndexUnitTests.h" +#include #include +#include #include @@ -188,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; } @@ -215,10 +222,13 @@ Orthanc::Logging::Initialize(); Orthanc::Logging::EnableInfoLevel(true); Orthanc::Logging::EnableTraceLevel(true); + Orthanc::Toolbox::InitializeOpenSsl(); + Orthanc::HttpClient::GlobalInitialize(); if (args.size() == 4) { - // UNIX flavor + // UNIX socket flavor + globalParameters_.SetHost(""); globalParameters_.SetUnixSocket(args[0]); globalParameters_.SetUsername(args[1]); globalParameters_.SetPassword(args[2]); @@ -226,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 { @@ -246,9 +259,10 @@ int result = RUN_ALL_TESTS(); + Orthanc::HttpClient::GlobalFinalize(); + Orthanc::Toolbox::FinalizeOpenSsl(); + OrthancDatabases::MySQLDatabase::GlobalFinalization(); Orthanc::Logging::Finalize(); - OrthancDatabases::MySQLDatabase::GlobalFinalization(); - return result; } diff -r 4b2dab49b6ea -r 771b3c4bf5f8 PostgreSQL/CMakeLists.txt --- a/PostgreSQL/CMakeLists.txt Tue Jul 17 08:53:20 2018 +0200 +++ b/PostgreSQL/CMakeLists.txt Wed Jul 18 12:28:52 2018 +0200 @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 2.8) project(OrthancPostgreSQL) -set(ORTHANC_PLUGIN_VERSION "2.2") +set(ORTHANC_PLUGIN_VERSION "mainline") if (ORTHANC_PLUGIN_VERSION STREQUAL "mainline") set(ORTHANC_FRAMEWORK_VERSION "mainline") diff -r 4b2dab49b6ea -r 771b3c4bf5f8 Resources/CMake/DatabasesFrameworkConfiguration.cmake --- a/Resources/CMake/DatabasesFrameworkConfiguration.cmake Tue Jul 17 08:53:20 2018 +0200 +++ b/Resources/CMake/DatabasesFrameworkConfiguration.cmake Wed Jul 18 12:28:52 2018 +0200 @@ -35,11 +35,11 @@ set(ENABLE_CRYPTO_OPTIONS ON) set(ENABLE_SSL ON) set(ENABLE_ZLIB ON) - set(ENABLE_LOCALE ON) # iconv is needed + set(ENABLE_LOCALE ON) # iconv is needed + set(ENABLE_WEB_CLIENT ON) # libcurl is needed if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows") set(ENABLE_OPENSSL_ENGINES ON) - set(ENABLE_WEB_CLIENT ON) # libcurl is needed if targetting Windows endif() endif() diff -r 4b2dab49b6ea -r 771b3c4bf5f8 Resources/CMake/DatabasesPluginConfiguration.cmake --- a/Resources/CMake/DatabasesPluginConfiguration.cmake Tue Jul 17 08:53:20 2018 +0200 +++ b/Resources/CMake/DatabasesPluginConfiguration.cmake Wed Jul 18 12:28:52 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()