Mercurial > hg > orthanc-databases
diff Framework/MySQL/MySQLDatabase.cpp @ 144:740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 12 Mar 2020 12:10:52 +0100 |
parents | 4cd7e45b671e |
children | 063aa53b5917 |
line wrap: on
line diff
--- a/Framework/MySQL/MySQLDatabase.cpp Tue Feb 04 09:34:56 2020 +0100 +++ b/Framework/MySQL/MySQLDatabase.cpp Thu Mar 12 12:10:52 2020 +0100 @@ -420,6 +420,36 @@ } + bool MySQLDatabase::DoesTriggerExist(MySQLTransaction& transaction, + const std::string& name) + { + if (mysql_ == NULL) + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); + } + + if (!IsValidDatabaseIdentifier(name)) + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); + } + + Query query("SELECT COUNT(*) FROM information_schema.TRIGGERS " + "WHERE TRIGGER_NAME = ${trigger}", true); + query.SetType("trigger", ValueType_Utf8String); + + MySQLStatement statement(*this, query); + + Dictionary args; + args.SetUtf8Value("trigger", name); + + std::auto_ptr<IResult> result(statement.Execute(transaction, args)); + return (!result->IsDone() && + result->GetFieldsCount() == 1 && + result->GetField(0).GetType() == ValueType_Integer64 && + dynamic_cast<const Integer64Value&>(result->GetField(0)).GetValue() == 1); + } + + void MySQLDatabase::Execute(const std::string& sql, bool arobaseSeparator) {