changeset 235:f2b32d31fc99

fix lsb build, fix backward compatibility with SDK <= 1.9.1
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 08 Apr 2021 11:42:32 +0200
parents d1b124d116c1
children d1d2edbbe6fb
files Framework/Common/DatabaseManager.cpp Framework/Plugins/DatabaseBackendAdapterV3.cpp Framework/PostgreSQL/PostgreSQLStatement.cpp
diffstat 3 files changed, 43 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/Framework/Common/DatabaseManager.cpp	Thu Apr 08 10:50:01 2021 +0200
+++ b/Framework/Common/DatabaseManager.cpp	Thu Apr 08 11:42:32 2021 +0200
@@ -58,8 +58,16 @@
     
   void DatabaseManager::CloseIfUnavailable(Orthanc::ErrorCode e)
   {
-    if (e != Orthanc::ErrorCode_Success &&
-        e != Orthanc::ErrorCode_DatabaseCannotSerialize)
+    bool failure;
+
+#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 9, 2)
+    failure = (e != Orthanc::ErrorCode_Success &&
+               e != Orthanc::ErrorCode_DatabaseCannotSerialize);
+#else
+    failure = (e != Orthanc::ErrorCode_Success);
+#endif
+
+    if (failure)
     {
       transaction_.reset(NULL);
     }
--- a/Framework/Plugins/DatabaseBackendAdapterV3.cpp	Thu Apr 08 10:50:01 2021 +0200
+++ b/Framework/Plugins/DatabaseBackendAdapterV3.cpp	Thu Apr 08 11:42:32 2021 +0200
@@ -55,9 +55,32 @@
 namespace OrthancDatabases
 {
   static bool isBackendInUse_ = false;  // Only for sanity checks
-  
 
-  // TODO - TURN THIS INTO A CONNECTION POOL
+  
+  template <typename T>
+  static void CopyListToVector(std::vector<T>& target,
+                               const std::list<T>& source)
+  {
+    /**
+     * This has the the same effect as:
+     *
+     *   target.reserve(source.size());
+     *   std::copy(std::begin(source), std::end(source), std::back_inserter(target));
+     *
+     * However, this implementation is compatible with C++03 (Linux
+     * Standard Base), whereas "std::back_inserter" requires C++11.
+     **/
+
+    target.clear();
+    target.reserve(source.size());
+
+    for (typename std::list<T>::const_iterator it = source.begin(); it != source.end(); ++it)
+    {
+      target.push_back(*it);
+    }
+  }
+    
+    
   class DatabaseBackendAdapterV3::Adapter : public boost::noncopyable
   {
   private:
@@ -704,22 +727,18 @@
       matches_.push_back(match);
     }
 
-    
+
     void AnswerIntegers32(const std::list<int32_t>& values)
     {
       SetupAnswerType(_OrthancPluginDatabaseAnswerType_Int32);
-
-      integers32_.reserve(values.size());
-      std::copy(std::begin(values), std::end(values), std::back_inserter(integers32_));
+      CopyListToVector(integers32_, values);
     }
 
     
     void AnswerIntegers64(const std::list<int64_t>& values)
     {
       SetupAnswerType(_OrthancPluginDatabaseAnswerType_Int64);
-
-      integers64_.reserve(values.size());
-      std::copy(std::begin(values), std::end(values), std::back_inserter(integers64_));
+      CopyListToVector(integers64_, values);
     }
 
 
@@ -748,9 +767,7 @@
     void AnswerStrings(const std::list<std::string>& values)
     {
       SetupAnswerType(_OrthancPluginDatabaseAnswerType_String);
-
-      stringAnswers_.reserve(values.size());
-      std::copy(std::begin(values), std::end(values), std::back_inserter(stringAnswers_));
+      CopyListToVector(stringAnswers_, values);
     }
 
 
--- a/Framework/PostgreSQL/PostgreSQLStatement.cpp	Thu Apr 08 10:50:01 2021 +0200
+++ b/Framework/PostgreSQL/PostgreSQLStatement.cpp	Thu Apr 08 11:42:32 2021 +0200
@@ -285,7 +285,11 @@
         PQclear(result);
       }
       
+#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 9, 2)
       throw Orthanc::OrthancException(Orthanc::ErrorCode_DatabaseCannotSerialize);
+#else
+      throw Orthanc::OrthancException(Orthanc::ErrorCode_Database, "Collision between multiple writers");
+#endif
     }
     else if (result == NULL)
     {