diff OrthancServer/DatabaseWrapper.cpp @ 310:6ab6cdeedf4e

global sequences
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 21 Dec 2012 11:18:27 +0100
parents 4eea080e6e7a
children 42e87c17cab8
line wrap: on
line diff
--- a/OrthancServer/DatabaseWrapper.cpp	Fri Dec 21 10:49:15 2012 +0100
+++ b/OrthancServer/DatabaseWrapper.cpp	Fri Dec 21 11:18:27 2012 +0100
@@ -866,4 +866,32 @@
       // Nothing to do: The patient is already unprotected
     }
   }
+
+
+  uint64_t DatabaseWrapper::IncrementGlobalSequence(GlobalProperty property)
+  {
+    std::string oldValue;
+
+    if (LookupGlobalProperty(oldValue, property))
+    {
+      uint64_t oldNumber;
+
+      try
+      {
+        oldNumber = boost::lexical_cast<uint64_t>(oldValue);
+        SetGlobalProperty(property, boost::lexical_cast<std::string>(oldNumber + 1));
+        return oldNumber + 1;
+      }
+      catch (boost::bad_lexical_cast&)
+      {
+        throw OrthancException(ErrorCode_InternalError);
+      }
+    }
+    else
+    {
+      // Initialize the sequence at "1"
+      SetGlobalProperty(property, "1");
+      return 1;
+    }
+  }
 }