changeset 254:8a4ce70f456a

fix crash if connection to server is lost
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 14 Apr 2021 15:33:57 +0200
parents 3bc442765b88
children d663d9e44f8d
files Framework/Common/DatabaseManager.cpp Framework/Common/DatabaseManager.h
diffstat 2 files changed, 14 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/Framework/Common/DatabaseManager.cpp	Wed Apr 14 15:08:51 2021 +0200
+++ b/Framework/Common/DatabaseManager.cpp	Wed Apr 14 15:33:57 2021 +0200
@@ -171,6 +171,19 @@
   }
 
   
+  IDatabase& DatabaseManager::GetDatabase()
+  {
+    if (database_.get() == NULL)
+    {
+      throw Orthanc::OrthancException(Orthanc::ErrorCode_DatabaseUnavailable);
+    }
+    else
+    {
+      return *database_;
+    }
+  }
+
+
   void DatabaseManager::StartTransaction(TransactionType type)
   {
     try
--- a/Framework/Common/DatabaseManager.h	Wed Apr 14 15:08:51 2021 +0200
+++ b/Framework/Common/DatabaseManager.h	Wed Apr 14 15:33:57 2021 +0200
@@ -69,10 +69,7 @@
       Close();
     }
 
-    IDatabase& GetDatabase()
-    {
-      return *database_;
-    }
+    IDatabase& GetDatabase();
 
     Dialect GetDialect() const
     {