diff Framework/MySQL/MySQLDatabase.cpp @ 240:c82c2cf84ae8

added handling of CR_COMMANDS_OUT_OF_SYNC
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 12 Apr 2021 17:07:06 +0200
parents 35598014f140
children 33fa478c119a
line wrap: on
line diff
--- a/Framework/MySQL/MySQLDatabase.cpp	Thu Apr 08 20:30:15 2021 +0200
+++ b/Framework/MySQL/MySQLDatabase.cpp	Mon Apr 12 17:07:06 2021 +0200
@@ -52,6 +52,40 @@
   }
 
 
+  void MySQLDatabase::ThrowException()
+  {
+    LogError();
+
+    unsigned int error = mysql_errno(mysql_);
+    if (error == CR_SERVER_GONE_ERROR ||
+        error == CR_SERVER_LOST ||
+        error == ER_QUERY_INTERRUPTED)
+    {
+      throw Orthanc::OrthancException(Orthanc::ErrorCode_DatabaseUnavailable);
+    }
+    else if (error == CR_COMMANDS_OUT_OF_SYNC)
+    {
+#if !defined(MARIADB_VERSION_ID)
+      LOG(ERROR) << "TODO - This error seems to be related to the use of libmysqlclient: Try to switch to mariadb-connector";
+#endif
+      
+      throw Orthanc::OrthancException(Orthanc::ErrorCode_DatabaseUnavailable);
+    }
+    else if (error == ER_LOCK_DEADLOCK)
+    {
+#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
+    {
+      throw Orthanc::OrthancException(Orthanc::ErrorCode_Database);
+    }
+  }
+
+
   void MySQLDatabase::CheckErrorCode(int code)
   {
     if (code == 0)
@@ -60,27 +94,7 @@
     }
     else
     {
-      LogError();
-      
-      unsigned int error = mysql_errno(mysql_);
-      if (error == CR_SERVER_GONE_ERROR ||
-          error == CR_SERVER_LOST ||
-          error == ER_QUERY_INTERRUPTED)
-      {
-        throw Orthanc::OrthancException(Orthanc::ErrorCode_DatabaseUnavailable);
-      }
-      else if (error == ER_LOCK_DEADLOCK)
-      {
-#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
-      {
-        throw Orthanc::OrthancException(Orthanc::ErrorCode_Database);
-      }
+      ThrowException();
     }
   }