Mercurial > hg > orthanc-databases
diff MySQL/Plugins/MySQLIndex.cpp @ 23:b2ff1cd2907a
handling of implicit transactions in DatabaseManager
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 12 Jul 2018 10:44:17 +0200 |
parents | 1e9bad493475 |
children | 17f849b2af34 |
line wrap: on
line diff
--- a/MySQL/Plugins/MySQLIndex.cpp Wed Jul 11 14:39:59 2018 +0200 +++ b/MySQL/Plugins/MySQLIndex.cpp Thu Jul 12 10:44:17 2018 +0200 @@ -56,42 +56,9 @@ throw Orthanc::OrthancException(Orthanc::ErrorCode_Plugin); } - if (parameters_.GetDatabase().empty()) - { - LOG(ERROR) << "Empty database name"; - throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); - } - - for (size_t i = 0; i < parameters_.GetDatabase().length(); i++) - { - if (!isalnum(parameters_.GetDatabase() [i])) - { - LOG(ERROR) << "Only alphanumeric characters are allowed in a " - << "MySQL database name: \"" << parameters_.GetDatabase() << "\""; - throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); - } - } - if (clearAll_) { - MySQLParameters p = parameters_; - const std::string database = p.GetDatabase(); - p.SetDatabase(""); - - MySQLDatabase db(p); - db.Open(); - - MySQLTransaction t(db); - - if (!db.DoesDatabaseExist(t, database)) - { - LOG(ERROR) << "Inexistent database, please create it first: " << database; - throw Orthanc::OrthancException(Orthanc::ErrorCode_UnknownResource); - } - - db.Execute("DROP DATABASE " + database, false); - db.Execute("CREATE DATABASE " + database, false); - t.Commit(); + MySQLDatabase::ClearDatabase(parameters_); } std::auto_ptr<MySQLDatabase> db(new MySQLDatabase(parameters_));