comparison 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
comparison
equal deleted inserted replaced
22:1e9bad493475 23:b2ff1cd2907a
54 << "expecting the DB schema version " << expectedVersion 54 << "expecting the DB schema version " << expectedVersion
55 << ", but this plugin is only compatible with version 6"; 55 << ", but this plugin is only compatible with version 6";
56 throw Orthanc::OrthancException(Orthanc::ErrorCode_Plugin); 56 throw Orthanc::OrthancException(Orthanc::ErrorCode_Plugin);
57 } 57 }
58 58
59 if (parameters_.GetDatabase().empty())
60 {
61 LOG(ERROR) << "Empty database name";
62 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
63 }
64
65 for (size_t i = 0; i < parameters_.GetDatabase().length(); i++)
66 {
67 if (!isalnum(parameters_.GetDatabase() [i]))
68 {
69 LOG(ERROR) << "Only alphanumeric characters are allowed in a "
70 << "MySQL database name: \"" << parameters_.GetDatabase() << "\"";
71 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
72 }
73 }
74
75 if (clearAll_) 59 if (clearAll_)
76 { 60 {
77 MySQLParameters p = parameters_; 61 MySQLDatabase::ClearDatabase(parameters_);
78 const std::string database = p.GetDatabase();
79 p.SetDatabase("");
80
81 MySQLDatabase db(p);
82 db.Open();
83
84 MySQLTransaction t(db);
85
86 if (!db.DoesDatabaseExist(t, database))
87 {
88 LOG(ERROR) << "Inexistent database, please create it first: " << database;
89 throw Orthanc::OrthancException(Orthanc::ErrorCode_UnknownResource);
90 }
91
92 db.Execute("DROP DATABASE " + database, false);
93 db.Execute("CREATE DATABASE " + database, false);
94 t.Commit();
95 } 62 }
96 63
97 std::auto_ptr<MySQLDatabase> db(new MySQLDatabase(parameters_)); 64 std::auto_ptr<MySQLDatabase> db(new MySQLDatabase(parameters_));
98 65
99 db->Open(); 66 db->Open();