changeset 305:87f0e29a1dc1

added Dictionary::Clear()
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 12 Jul 2021 09:40:01 +0200
parents dd4b0edd1661
children 544e0c943b40
files Framework/Common/DatabaseManager.cpp Framework/Common/Dictionary.cpp Framework/Common/Dictionary.h MySQL/Plugins/MySQLIndex.cpp
diffstat 4 files changed, 20 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/Framework/Common/DatabaseManager.cpp	Fri Jul 09 17:23:24 2021 +0200
+++ b/Framework/Common/DatabaseManager.cpp	Mon Jul 12 09:40:01 2021 +0200
@@ -356,20 +356,14 @@
   
   void DatabaseManager::StatementBase::SetResult(IResult* result)
   {
-    std::unique_ptr<IResult> protection(result);
-    
-    if (result_.get() != NULL)
-    {
-      LOG(ERROR) << "Cannot execute twice a statement";
-      throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
-    }
-
     if (result == NULL)
     {
       throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
     }
-
-    result_.reset(protection.release());
+    else
+    {
+      result_.reset(result);
+    }
   }
 
   
--- a/Framework/Common/Dictionary.cpp	Fri Jul 09 17:23:24 2021 +0200
+++ b/Framework/Common/Dictionary.cpp	Mon Jul 12 09:40:01 2021 +0200
@@ -34,7 +34,7 @@
 
 namespace OrthancDatabases
 {
-  Dictionary::~Dictionary()
+  void Dictionary::Clear()
   {
     for (Values::iterator it = values_.begin(); 
          it != values_.end(); ++it)
@@ -42,8 +42,10 @@
       assert(it->second != NULL);
       delete it->second;
     }
+
+    values_.clear();
   }
-
+  
 
   bool Dictionary::HasKey(const std::string& key) const
   {
--- a/Framework/Common/Dictionary.h	Fri Jul 09 17:23:24 2021 +0200
+++ b/Framework/Common/Dictionary.h	Mon Jul 12 09:40:01 2021 +0200
@@ -36,7 +36,12 @@
     Values  values_;
 
   public:
-    ~Dictionary();
+    ~Dictionary()
+    {
+      Clear();
+    }
+
+    void Clear();
 
     bool HasKey(const std::string& key) const;
 
--- a/MySQL/Plugins/MySQLIndex.cpp	Fri Jul 09 17:23:24 2021 +0200
+++ b/MySQL/Plugins/MySQLIndex.cpp	Mon Jul 12 09:40:01 2021 +0200
@@ -352,6 +352,12 @@
                                   DatabaseManager& manager,
                                   int64_t id)
   {
+    /**
+     * Contrarily to PostgreSQL and SQLite, the MySQL dialect doesn't
+     * support cascaded delete inside the same table. This has to be
+     * manually reimplemented.
+     **/
+    
     ClearDeletedFiles(manager);
 
     // Recursive exploration of resources to be deleted, from the "id"