comparison 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
comparison
equal deleted inserted replaced
142:bbd57f5672fa 144:740d9829f52e
418 result->GetField(0).GetType() == ValueType_Integer64 && 418 result->GetField(0).GetType() == ValueType_Integer64 &&
419 dynamic_cast<const Integer64Value&>(result->GetField(0)).GetValue() == 1); 419 dynamic_cast<const Integer64Value&>(result->GetField(0)).GetValue() == 1);
420 } 420 }
421 421
422 422
423 bool MySQLDatabase::DoesTriggerExist(MySQLTransaction& transaction,
424 const std::string& name)
425 {
426 if (mysql_ == NULL)
427 {
428 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
429 }
430
431 if (!IsValidDatabaseIdentifier(name))
432 {
433 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
434 }
435
436 Query query("SELECT COUNT(*) FROM information_schema.TRIGGERS "
437 "WHERE TRIGGER_NAME = ${trigger}", true);
438 query.SetType("trigger", ValueType_Utf8String);
439
440 MySQLStatement statement(*this, query);
441
442 Dictionary args;
443 args.SetUtf8Value("trigger", name);
444
445 std::auto_ptr<IResult> result(statement.Execute(transaction, args));
446 return (!result->IsDone() &&
447 result->GetFieldsCount() == 1 &&
448 result->GetField(0).GetType() == ValueType_Integer64 &&
449 dynamic_cast<const Integer64Value&>(result->GetField(0)).GetValue() == 1);
450 }
451
452
423 void MySQLDatabase::Execute(const std::string& sql, 453 void MySQLDatabase::Execute(const std::string& sql,
424 bool arobaseSeparator) 454 bool arobaseSeparator)
425 { 455 {
426 if (mysql_ == NULL) 456 if (mysql_ == NULL)
427 { 457 {