comparison 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
comparison
equal deleted inserted replaced
239:e9ba888f371b 240:c82c2cf84ae8
50 mysql_ = NULL; 50 mysql_ = NULL;
51 } 51 }
52 } 52 }
53 53
54 54
55 void MySQLDatabase::ThrowException()
56 {
57 LogError();
58
59 unsigned int error = mysql_errno(mysql_);
60 if (error == CR_SERVER_GONE_ERROR ||
61 error == CR_SERVER_LOST ||
62 error == ER_QUERY_INTERRUPTED)
63 {
64 throw Orthanc::OrthancException(Orthanc::ErrorCode_DatabaseUnavailable);
65 }
66 else if (error == CR_COMMANDS_OUT_OF_SYNC)
67 {
68 #if !defined(MARIADB_VERSION_ID)
69 LOG(ERROR) << "TODO - This error seems to be related to the use of libmysqlclient: Try to switch to mariadb-connector";
70 #endif
71
72 throw Orthanc::OrthancException(Orthanc::ErrorCode_DatabaseUnavailable);
73 }
74 else if (error == ER_LOCK_DEADLOCK)
75 {
76 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 9, 2)
77 throw Orthanc::OrthancException(Orthanc::ErrorCode_DatabaseCannotSerialize);
78 #else
79 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database, "Collision between multiple writers");
80 #endif
81 }
82 else
83 {
84 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database);
85 }
86 }
87
88
55 void MySQLDatabase::CheckErrorCode(int code) 89 void MySQLDatabase::CheckErrorCode(int code)
56 { 90 {
57 if (code == 0) 91 if (code == 0)
58 { 92 {
59 return; 93 return;
60 } 94 }
61 else 95 else
62 { 96 {
63 LogError(); 97 ThrowException();
64
65 unsigned int error = mysql_errno(mysql_);
66 if (error == CR_SERVER_GONE_ERROR ||
67 error == CR_SERVER_LOST ||
68 error == ER_QUERY_INTERRUPTED)
69 {
70 throw Orthanc::OrthancException(Orthanc::ErrorCode_DatabaseUnavailable);
71 }
72 else if (error == ER_LOCK_DEADLOCK)
73 {
74 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 9, 2)
75 throw Orthanc::OrthancException(Orthanc::ErrorCode_DatabaseCannotSerialize);
76 #else
77 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database, "Collision between multiple writers");
78 #endif
79 }
80 else
81 {
82 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database);
83 }
84 } 98 }
85 } 99 }
86 100
87 101
88 MySQLDatabase::MySQLDatabase(const MySQLParameters& parameters) : 102 MySQLDatabase::MySQLDatabase(const MySQLParameters& parameters) :