Mercurial > hg > orthanc-databases
comparison MySQL/Plugins/MySQLIndex.cpp @ 16:9e419261f1c9
mysql storage area working
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 10 Jul 2018 10:10:35 +0200 |
parents | 7cea966b6829 |
children | 1e9bad493475 |
comparison
equal
deleted
inserted
replaced
15:dfc7002add9c | 16:9e419261f1c9 |
---|---|
80 | 80 |
81 MySQLDatabase db(p); | 81 MySQLDatabase db(p); |
82 db.Open(); | 82 db.Open(); |
83 | 83 |
84 MySQLTransaction t(db); | 84 MySQLTransaction t(db); |
85 db.Execute("DROP DATABASE IF EXISTS " + database); | 85 db.Execute("DROP DATABASE IF EXISTS " + database, false); |
86 db.Execute("CREATE DATABASE " + database); | 86 db.Execute("CREATE DATABASE " + database, false); |
87 t.Commit(); | 87 t.Commit(); |
88 } | 88 } |
89 | 89 |
90 std::auto_ptr<MySQLDatabase> db(new MySQLDatabase(parameters_)); | 90 std::auto_ptr<MySQLDatabase> db(new MySQLDatabase(parameters_)); |
91 | 91 |
92 db->Open(); | 92 db->Open(); |
93 db->Execute("ALTER DATABASE " + parameters_.GetDatabase() + | 93 |
94 " CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci"); | 94 db->Execute("SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE", false); |
95 db->Execute("SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE"); | 95 |
96 | 96 if (parameters_.HasLock()) |
97 { | |
98 db->AdvisoryLock(42 /* some arbitrary constant */); | |
99 } | |
100 | |
97 { | 101 { |
98 MySQLTransaction t(*db); | 102 MySQLTransaction t(*db); |
99 | 103 |
104 db->Execute("ALTER DATABASE " + parameters_.GetDatabase() + | |
105 " CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci", false); | |
106 | |
100 if (!db->DoesTableExist(t, "Resources")) | 107 if (!db->DoesTableExist(t, "Resources")) |
101 { | 108 { |
102 std::string query; | 109 std::string query; |
103 | 110 |
104 Orthanc::EmbeddedResources::GetFileResource | 111 Orthanc::EmbeddedResources::GetFileResource |
105 (query, Orthanc::EmbeddedResources::MYSQL_PREPARE_INDEX); | 112 (query, Orthanc::EmbeddedResources::MYSQL_PREPARE_INDEX); |
106 db->Execute(query); | 113 db->Execute(query, true); |
107 | 114 |
108 SetGlobalIntegerProperty(*db, t, Orthanc::GlobalProperty_DatabaseSchemaVersion, expectedVersion); | 115 SetGlobalIntegerProperty(*db, t, Orthanc::GlobalProperty_DatabaseSchemaVersion, expectedVersion); |
109 SetGlobalIntegerProperty(*db, t, Orthanc::GlobalProperty_DatabasePatchLevel, 1); | 116 SetGlobalIntegerProperty(*db, t, Orthanc::GlobalProperty_DatabasePatchLevel, 1); |
110 } | 117 } |
111 | |
112 t.Commit(); | |
113 } | |
114 | |
115 { | |
116 MySQLTransaction t(*db); | |
117 | 118 |
118 if (!db->DoesTableExist(t, "Resources")) | 119 if (!db->DoesTableExist(t, "Resources")) |
119 { | 120 { |
120 LOG(ERROR) << "Corrupted MySQL database"; | 121 LOG(ERROR) << "Corrupted MySQL database"; |
121 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | 122 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
140 { | 141 { |
141 LOG(ERROR) << "PostgreSQL plugin is incompatible with database schema revision: " << revision; | 142 LOG(ERROR) << "PostgreSQL plugin is incompatible with database schema revision: " << revision; |
142 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database); | 143 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database); |
143 } | 144 } |
144 | 145 |
145 t.Rollback(); | 146 t.Commit(); |
146 } | 147 } |
147 | 148 |
148 return db.release(); | 149 return db.release(); |
149 } | 150 } |
150 | 151 |