Mercurial > hg > orthanc-databases
annotate MySQL/Plugins/MySQLIndex.cpp @ 359:16aac0287485
copyright upgraded to 2022
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 21 Feb 2022 09:32:46 +0100 |
parents | eb0b04c10bc4 |
children | 3d6886f3e5b3 |
rev | line source |
---|---|
0 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
359
16aac0287485
copyright upgraded to 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
321
diff
changeset
|
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium |
16aac0287485
copyright upgraded to 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
321
diff
changeset
|
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
0 | 7 * |
8 * This program is free software: you can redistribute it and/or | |
9 * modify it under the terms of the GNU Affero General Public License | |
10 * as published by the Free Software Foundation, either version 3 of | |
11 * the License, or (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, but | |
14 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 * Affero General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU Affero General Public License | |
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
20 **/ | |
21 | |
22 | |
23 #include "MySQLIndex.h" | |
24 | |
25 #include "../../Framework/Plugins/GlobalProperties.h" | |
26 #include "../../Framework/MySQL/MySQLDatabase.h" | |
27 #include "../../Framework/MySQL/MySQLTransaction.h" | |
137
52b3859ee0b7
MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
28 #include "MySQLDefinitions.h" |
0 | 29 |
30 #include <EmbeddedResources.h> // Auto-generated file | |
31 | |
157
275e14f57f1e
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
32 #include <Compatibility.h> // For std::unique_ptr<> |
152 | 33 #include <Logging.h> |
34 #include <OrthancException.h> | |
0 | 35 |
36 #include <ctype.h> | |
37 | |
38 namespace OrthancDatabases | |
39 { | |
226
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
40 MySQLIndex::MySQLIndex(OrthancPluginContext* context, |
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
41 const MySQLParameters& parameters) : |
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
42 IndexBackend(context), |
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
43 parameters_(parameters), |
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
44 clearAll_(false) |
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
45 { |
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
46 } |
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
47 |
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
48 |
255
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
49 IDatabaseFactory* MySQLIndex::CreateDatabaseFactory() |
226
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
50 { |
255
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
51 return MySQLDatabase::CreateDatabaseFactory(parameters_); |
226
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
52 } |
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
53 |
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
54 |
144
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
55 static void ThrowCannotCreateTrigger() |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
56 { |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
57 LOG(ERROR) << "The MySQL user is not allowed to create triggers => 2 possible solutions:"; |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
58 LOG(ERROR) << " 1- Give the SUPER privilege to the MySQL database user, or"; |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
59 LOG(ERROR) << " 2- Run \"set global log_bin_trust_function_creators=1;\" as MySQL root user."; |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
60 LOG(ERROR) << "Once you are done, drop and recreate the MySQL database"; |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
61 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database, |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
62 "Need to fix the MySQL permissions for \"CREATE TRIGGER\""); |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
63 } |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
64 |
226
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
65 |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
66 void MySQLIndex::ConfigureDatabase(DatabaseManager& manager) |
0 | 67 { |
68 uint32_t expectedVersion = 6; | |
199 | 69 |
70 if (GetContext()) // "GetContext()" can possibly be NULL in the unit tests | |
0 | 71 { |
199 | 72 expectedVersion = OrthancPluginGetExpectedDatabaseVersion(GetContext()); |
0 | 73 } |
74 | |
75 // Check the expected version of the database | |
76 if (expectedVersion != 6) | |
77 { | |
78 LOG(ERROR) << "This database plugin is incompatible with your version of Orthanc " | |
79 << "expecting the DB schema version " << expectedVersion | |
80 << ", but this plugin is only compatible with version 6"; | |
81 throw Orthanc::OrthancException(Orthanc::ErrorCode_Plugin); | |
82 } | |
83 | |
60
412e30336847
allowing dollars and underscores in MySQL database identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
84 if (!MySQLDatabase::IsValidDatabaseIdentifier(parameters_.GetDatabase())) |
24
17f849b2af34
sharing plugin initialization code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
85 { |
17f849b2af34
sharing plugin initialization code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
86 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
17f849b2af34
sharing plugin initialization code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
87 } |
17f849b2af34
sharing plugin initialization code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
88 |
0 | 89 if (clearAll_) |
90 { | |
23
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
91 MySQLDatabase::ClearDatabase(parameters_); |
0 | 92 } |
93 | |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
94 MySQLDatabase& db = dynamic_cast<MySQLDatabase&>(manager.GetDatabase()); |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
95 |
16
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
96 { |
226
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
97 MySQLDatabase::TransientAdvisoryLock lock(db, MYSQL_LOCK_DATABASE_SETUP); |
0 | 98 |
144
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
99 /** |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
100 * In a first transaction, we create the tables. Such a |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
101 * transaction cannot be rollback: "The CREATE TABLE statement |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
102 * in InnoDB is processed as a single transaction. This means |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
103 * that a ROLLBACK from the user does not undo CREATE TABLE |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
104 * statements the user made during that transaction." |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
105 * https://dev.mysql.com/doc/refman/8.0/en/implicit-commit.html |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
106 * |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
107 * As a consequence, we delay the initial population of the |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
108 * tables in a sequence of transactions below. This solves the |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
109 * error message "MySQL plugin is incompatible with database |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
110 * schema version: 0" that was reported in the forum: |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
111 * https://groups.google.com/d/msg/orthanc-users/OCFFkm1qm0k/Mbroy8VWAQAJ |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
112 **/ |
0 | 113 { |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
114 DatabaseManager::Transaction t(manager, TransactionType_ReadWrite); |
144
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
115 |
241
a063bbf10a3e
simplification of class DatabaseManager::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
116 t.GetDatabaseTransaction().ExecuteMultiLines("ALTER DATABASE " + parameters_.GetDatabase() + |
a063bbf10a3e
simplification of class DatabaseManager::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
117 " CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci"); |
0 | 118 |
144
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
119 // This is the first table to be created |
241
a063bbf10a3e
simplification of class DatabaseManager::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
120 if (!t.GetDatabaseTransaction().DoesTableExist("GlobalProperties")) |
144
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
121 { |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
122 std::string query; |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
123 |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
124 Orthanc::EmbeddedResources::GetFileResource |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
125 (query, Orthanc::EmbeddedResources::MYSQL_PREPARE_INDEX); |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
126 |
241
a063bbf10a3e
simplification of class DatabaseManager::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
127 // Need to escape arobases: Don't use "t.GetDatabaseTransaction().ExecuteMultiLines()" here |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
128 db.ExecuteMultiLines(query, true); |
144
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
129 } |
0 | 130 |
144
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
131 t.Commit(); |
0 | 132 } |
133 | |
144
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
134 /** |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
135 * This is the sequence of transactions that initially populate |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
136 * the database. WARNING - As table creation cannot be rollback, |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
137 * don't forget to add "IF NOT EXISTS" if some table must be |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
138 * created below this point (in order to recover from failed |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
139 * transaction). |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
140 **/ |
0 | 141 |
142 { | |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
143 DatabaseManager::Transaction t(manager, TransactionType_ReadWrite); |
144
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
144 |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
145 // This is the last table to be created |
241
a063bbf10a3e
simplification of class DatabaseManager::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
146 if (!t.GetDatabaseTransaction().DoesTableExist("PatientRecyclingOrder")) |
144
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
147 { |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
148 LOG(ERROR) << "Corrupted MySQL database"; |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
149 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
150 } |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
151 |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
152 // This is the last item to be created |
241
a063bbf10a3e
simplification of class DatabaseManager::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
153 if (!t.GetDatabaseTransaction().DoesTriggerExist("PatientAdded")) |
144
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
154 { |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
155 ThrowCannotCreateTrigger(); |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
156 } |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
157 |
290 | 158 int version = 0; |
159 | |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
160 if (!LookupGlobalIntegerProperty(version, manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabaseSchemaVersion)) |
144
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
161 { |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
162 SetGlobalIntegerProperty(manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabaseSchemaVersion, expectedVersion); |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
163 SetGlobalIntegerProperty(manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabasePatchLevel, 1); |
144
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
164 version = expectedVersion; |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
165 } |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
166 |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
167 if (version != 6) |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
168 { |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
169 LOG(ERROR) << "MySQL plugin is incompatible with database schema version: " << version; |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
170 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database); |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
171 } |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
172 |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
173 t.Commit(); |
0 | 174 } |
175 | |
144
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
176 int revision = 0; |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
177 |
0 | 178 { |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
179 DatabaseManager::Transaction t(manager, TransactionType_ReadWrite); |
144
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
180 |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
181 if (!LookupGlobalIntegerProperty(revision, manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabasePatchLevel)) |
144
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
182 { |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
183 revision = 1; |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
184 SetGlobalIntegerProperty(manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabasePatchLevel, revision); |
144
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
185 } |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
186 |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
187 t.Commit(); |
0 | 188 } |
189 | |
84
b96446b8718b
Fix serialization of jobs if many of them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
190 if (revision == 1) |
b96446b8718b
Fix serialization of jobs if many of them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
191 { |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
192 DatabaseManager::Transaction t(manager, TransactionType_ReadWrite); |
144
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
193 |
84
b96446b8718b
Fix serialization of jobs if many of them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
194 // The serialization of jobs as a global property can lead to |
b96446b8718b
Fix serialization of jobs if many of them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
195 // very long values => switch to the LONGTEXT type that can |
b96446b8718b
Fix serialization of jobs if many of them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
196 // store up to 4GB: |
b96446b8718b
Fix serialization of jobs if many of them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
197 // https://stackoverflow.com/a/13932834/881731 |
241
a063bbf10a3e
simplification of class DatabaseManager::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
198 t.GetDatabaseTransaction().ExecuteMultiLines("ALTER TABLE GlobalProperties MODIFY value LONGTEXT"); |
144
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
199 |
84
b96446b8718b
Fix serialization of jobs if many of them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
200 revision = 2; |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
201 SetGlobalIntegerProperty(manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabasePatchLevel, revision); |
144
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
202 |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
203 t.Commit(); |
84
b96446b8718b
Fix serialization of jobs if many of them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
204 } |
b96446b8718b
Fix serialization of jobs if many of them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
205 |
87
48d445f756db
new extension implemented for MySQL: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
84
diff
changeset
|
206 if (revision == 2) |
144
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
207 { |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
208 DatabaseManager::Transaction t(manager, TransactionType_ReadWrite); |
144
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
209 |
110
441a472bfd93
new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
109
diff
changeset
|
210 // Install the "GetLastChangeIndex" extension |
87
48d445f756db
new extension implemented for MySQL: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
84
diff
changeset
|
211 std::string query; |
48d445f756db
new extension implemented for MySQL: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
84
diff
changeset
|
212 |
48d445f756db
new extension implemented for MySQL: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
84
diff
changeset
|
213 Orthanc::EmbeddedResources::GetFileResource |
48d445f756db
new extension implemented for MySQL: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
84
diff
changeset
|
214 (query, Orthanc::EmbeddedResources::MYSQL_GET_LAST_CHANGE_INDEX); |
144
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
215 |
241
a063bbf10a3e
simplification of class DatabaseManager::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
216 // Need to escape arobases: Don't use "t.GetDatabaseTransaction().ExecuteMultiLines()" here |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
217 db.ExecuteMultiLines(query, true); |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
218 |
241
a063bbf10a3e
simplification of class DatabaseManager::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
219 if (!t.GetDatabaseTransaction().DoesTriggerExist("ChangeAdded")) |
144
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
220 { |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
221 ThrowCannotCreateTrigger(); |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
222 } |
87
48d445f756db
new extension implemented for MySQL: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
84
diff
changeset
|
223 |
48d445f756db
new extension implemented for MySQL: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
84
diff
changeset
|
224 revision = 3; |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
225 SetGlobalIntegerProperty(manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabasePatchLevel, revision); |
144
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
226 |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
227 t.Commit(); |
87
48d445f756db
new extension implemented for MySQL: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
84
diff
changeset
|
228 } |
144
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
229 |
109
3f31e3fa5114
MySQL: metadata can store larger values
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
230 if (revision == 3) |
3f31e3fa5114
MySQL: metadata can store larger values
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
231 { |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
232 DatabaseManager::Transaction t(manager, TransactionType_ReadWrite); |
144
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
233 |
109
3f31e3fa5114
MySQL: metadata can store larger values
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
234 // Reconfiguration of "Metadata" from TEXT type (up to 64KB) |
3f31e3fa5114
MySQL: metadata can store larger values
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
235 // to the LONGTEXT type (up to 4GB). This might be important |
3f31e3fa5114
MySQL: metadata can store larger values
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
236 // for applications such as the Osimis Web viewer that stores |
3f31e3fa5114
MySQL: metadata can store larger values
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
237 // large amount of metadata. |
3f31e3fa5114
MySQL: metadata can store larger values
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
238 // http://book.orthanc-server.com/faq/features.html#central-registry-of-metadata-and-attachments |
241
a063bbf10a3e
simplification of class DatabaseManager::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
239 t.GetDatabaseTransaction().ExecuteMultiLines("ALTER TABLE Metadata MODIFY value LONGTEXT"); |
144
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
240 |
109
3f31e3fa5114
MySQL: metadata can store larger values
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
241 revision = 4; |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
242 SetGlobalIntegerProperty(manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabasePatchLevel, revision); |
144
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
243 |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
244 t.Commit(); |
109
3f31e3fa5114
MySQL: metadata can store larger values
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
245 } |
144
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
246 |
110
441a472bfd93
new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
109
diff
changeset
|
247 if (revision == 4) |
441a472bfd93
new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
109
diff
changeset
|
248 { |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
249 DatabaseManager::Transaction t(manager, TransactionType_ReadWrite); |
144
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
250 |
110
441a472bfd93
new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
109
diff
changeset
|
251 // Install the "CreateInstance" extension |
441a472bfd93
new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
109
diff
changeset
|
252 std::string query; |
144
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
253 |
110
441a472bfd93
new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
109
diff
changeset
|
254 Orthanc::EmbeddedResources::GetFileResource |
441a472bfd93
new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
109
diff
changeset
|
255 (query, Orthanc::EmbeddedResources::MYSQL_CREATE_INSTANCE); |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
256 |
241
a063bbf10a3e
simplification of class DatabaseManager::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
257 // Need to escape arobases: Don't use "t.GetDatabaseTransaction().ExecuteMultiLines()" here |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
258 db.ExecuteMultiLines(query, true); |
144
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
259 |
110
441a472bfd93
new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
109
diff
changeset
|
260 revision = 5; |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
261 SetGlobalIntegerProperty(manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabasePatchLevel, revision); |
144
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
262 |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
263 t.Commit(); |
110
441a472bfd93
new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
109
diff
changeset
|
264 } |
289
0868500060f3
Fix serialization of large jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
265 |
0868500060f3
Fix serialization of large jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
266 if (revision == 5) |
0868500060f3
Fix serialization of large jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
267 { |
0868500060f3
Fix serialization of large jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
268 // Added new table "ServerProperties" since release 4.0 to deal with multiple writers |
0868500060f3
Fix serialization of large jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
269 DatabaseManager::Transaction t(manager, TransactionType_ReadWrite); |
0868500060f3
Fix serialization of large jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
270 |
0868500060f3
Fix serialization of large jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
271 if (t.GetDatabaseTransaction().DoesTableExist("ServerProperties")) |
0868500060f3
Fix serialization of large jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
272 { |
0868500060f3
Fix serialization of large jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
273 /** |
0868500060f3
Fix serialization of large jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
274 * Patch for MySQL plugin 4.0, where the column "value" was |
0868500060f3
Fix serialization of large jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
275 * "TEXT" instead of "LONGTEXT", which prevented |
0868500060f3
Fix serialization of large jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
276 * serialization of large jobs. This was giving error "MySQL |
0868500060f3
Fix serialization of large jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
277 * error (1406,22001): Data too long for column 'value' at |
0868500060f3
Fix serialization of large jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
278 * row 1" after log message "Serializing the content of the |
0868500060f3
Fix serialization of large jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
279 * jobs engine" (in --trace mode). |
0868500060f3
Fix serialization of large jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
280 * https://groups.google.com/g/orthanc-users/c/1Y3nTBdr0uE/m/K7PA5pboAgAJ |
0868500060f3
Fix serialization of large jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
281 **/ |
0868500060f3
Fix serialization of large jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
282 t.GetDatabaseTransaction().ExecuteMultiLines("ALTER TABLE ServerProperties MODIFY value LONGTEXT"); |
0868500060f3
Fix serialization of large jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
283 } |
0868500060f3
Fix serialization of large jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
284 else |
0868500060f3
Fix serialization of large jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
285 { |
0868500060f3
Fix serialization of large jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
286 t.GetDatabaseTransaction().ExecuteMultiLines("CREATE TABLE ServerProperties(server VARCHAR(64) NOT NULL, " |
0868500060f3
Fix serialization of large jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
287 "property INTEGER, value LONGTEXT, PRIMARY KEY(server, property))"); |
0868500060f3
Fix serialization of large jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
288 } |
0868500060f3
Fix serialization of large jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
289 |
0868500060f3
Fix serialization of large jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
290 // Revision 6 indicates that "value" of "ServerProperties" is |
0868500060f3
Fix serialization of large jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
291 // "LONGTEXT", whereas revision 5 corresponds to "TEXT" |
0868500060f3
Fix serialization of large jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
292 revision = 6; |
0868500060f3
Fix serialization of large jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
293 SetGlobalIntegerProperty(manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabasePatchLevel, revision); |
0868500060f3
Fix serialization of large jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
294 |
0868500060f3
Fix serialization of large jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
295 t.Commit(); |
0868500060f3
Fix serialization of large jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
296 } |
0868500060f3
Fix serialization of large jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
297 |
0868500060f3
Fix serialization of large jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
298 if (revision != 6) |
0 | 299 { |
53 | 300 LOG(ERROR) << "MySQL plugin is incompatible with database schema revision: " << revision; |
0 | 301 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database); |
302 } | |
303 } | |
137
52b3859ee0b7
MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
304 |
238
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
305 |
137
52b3859ee0b7
MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
306 /** |
52b3859ee0b7
MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
307 * WARNING: This lock must be acquired after |
52b3859ee0b7
MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
308 * "MYSQL_LOCK_DATABASE_SETUP" is released. Indeed, in MySQL < |
52b3859ee0b7
MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
309 * 5.7, it is impossible to acquire more than one lock at a time, |
52b3859ee0b7
MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
310 * as calling "SELECT GET_LOCK()" releases all the |
52b3859ee0b7
MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
311 * previously-acquired locks. |
52b3859ee0b7
MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
312 * https://dev.mysql.com/doc/refman/5.7/en/locking-functions.html |
52b3859ee0b7
MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
313 **/ |
52b3859ee0b7
MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
314 if (parameters_.HasLock()) |
52b3859ee0b7
MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
315 { |
226
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
316 db.AdvisoryLock(MYSQL_LOCK_INDEX); |
137
52b3859ee0b7
MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
317 } |
0 | 318 } |
319 | |
320 | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
321 int64_t MySQLIndex::CreateResource(DatabaseManager& manager, |
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
322 const char* publicId, |
0 | 323 OrthancPluginResourceType type) |
324 { | |
325 { | |
326 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
327 STATEMENT_FROM_HERE, manager, |
302
3a52e27a2d80
in GenericFormatter, replaced ${} by ${AUTOINCREMENT}
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
290
diff
changeset
|
328 "INSERT INTO Resources VALUES(NULL, ${type}, ${id}, NULL)"); |
0 | 329 |
330 statement.SetParameterType("id", ValueType_Utf8String); | |
331 statement.SetParameterType("type", ValueType_Integer64); | |
332 | |
333 Dictionary args; | |
334 args.SetUtf8Value("id", publicId); | |
335 args.SetIntegerValue("type", static_cast<int>(type)); | |
336 | |
337 statement.Execute(args); | |
338 } | |
339 | |
340 { | |
341 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
342 STATEMENT_FROM_HERE, manager, |
0 | 343 "SELECT LAST_INSERT_ID()"); |
344 | |
345 statement.Execute(); | |
346 | |
263
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
347 return statement.ReadInteger64(0); |
0 | 348 } |
349 } | |
350 | |
351 | |
203
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
352 void MySQLIndex::DeleteResource(IDatabaseBackendOutput& output, |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
353 DatabaseManager& manager, |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
199
diff
changeset
|
354 int64_t id) |
0 | 355 { |
305
87f0e29a1dc1
added Dictionary::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
302
diff
changeset
|
356 /** |
87f0e29a1dc1
added Dictionary::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
302
diff
changeset
|
357 * Contrarily to PostgreSQL and SQLite, the MySQL dialect doesn't |
87f0e29a1dc1
added Dictionary::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
302
diff
changeset
|
358 * support cascaded delete inside the same table. This has to be |
87f0e29a1dc1
added Dictionary::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
302
diff
changeset
|
359 * manually reimplemented. |
87f0e29a1dc1
added Dictionary::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
302
diff
changeset
|
360 **/ |
87f0e29a1dc1
added Dictionary::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
302
diff
changeset
|
361 |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
362 ClearDeletedFiles(manager); |
0 | 363 |
364 // Recursive exploration of resources to be deleted, from the "id" | |
365 // resource to the top of the tree of resources | |
366 | |
367 bool done = false; | |
368 | |
369 while (!done) | |
370 { | |
307
8de3a1ecac11
MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
371 bool hasSibling = false; |
321 | 372 int64_t parentId = -1; // Dummy initialization |
307
8de3a1ecac11
MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
373 |
0 | 374 { |
375 DatabaseManager::CachedStatement lookupSiblings( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
376 STATEMENT_FROM_HERE, manager, |
0 | 377 "SELECT parentId FROM Resources " |
378 "WHERE parentId = (SELECT parentId FROM Resources WHERE internalId=${id});"); | |
379 | |
380 lookupSiblings.SetParameterType("id", ValueType_Integer64); | |
381 | |
382 Dictionary args; | |
383 args.SetIntegerValue("id", id); | |
384 | |
385 lookupSiblings.Execute(args); | |
386 | |
387 if (lookupSiblings.IsDone()) | |
388 { | |
389 // "id" is a root node | |
390 done = true; | |
391 } | |
392 else | |
393 { | |
307
8de3a1ecac11
MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
394 parentId = lookupSiblings.ReadInteger64(0); |
0 | 395 lookupSiblings.Next(); |
396 | |
397 if (lookupSiblings.IsDone()) | |
398 { | |
399 // "id" has no sibling node, recursively remove | |
400 done = false; | |
401 id = parentId; | |
402 } | |
403 else | |
404 { | |
405 // "id" has at least one sibling node: the parent node is the remaining ancestor | |
406 done = true; | |
307
8de3a1ecac11
MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
407 hasSibling = true; |
0 | 408 } |
409 } | |
410 } | |
307
8de3a1ecac11
MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
411 |
8de3a1ecac11
MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
412 if (hasSibling) |
8de3a1ecac11
MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
413 { |
8de3a1ecac11
MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
414 // This cannot be executed in the same scope as another |
8de3a1ecac11
MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
415 // DatabaseManager::CachedStatement |
8de3a1ecac11
MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
416 |
8de3a1ecac11
MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
417 DatabaseManager::CachedStatement parent( |
8de3a1ecac11
MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
418 STATEMENT_FROM_HERE, manager, |
8de3a1ecac11
MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
419 "SELECT publicId, resourceType FROM Resources WHERE internalId=${id};"); |
8de3a1ecac11
MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
420 |
8de3a1ecac11
MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
421 parent.SetParameterType("id", ValueType_Integer64); |
8de3a1ecac11
MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
422 |
8de3a1ecac11
MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
423 Dictionary args2; |
8de3a1ecac11
MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
424 args2.SetIntegerValue("id", parentId); |
8de3a1ecac11
MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
425 |
8de3a1ecac11
MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
426 parent.Execute(args2); |
8de3a1ecac11
MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
427 |
8de3a1ecac11
MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
428 output.SignalRemainingAncestor( |
8de3a1ecac11
MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
429 parent.ReadString(0), |
8de3a1ecac11
MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
430 static_cast<OrthancPluginResourceType>(parent.ReadInteger32(1))); |
8de3a1ecac11
MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
431 } |
8de3a1ecac11
MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
432 } |
8de3a1ecac11
MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
433 |
8de3a1ecac11
MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
434 { |
8de3a1ecac11
MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
435 DatabaseManager::CachedStatement dropTemporaryTable( |
8de3a1ecac11
MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
436 STATEMENT_FROM_HERE, manager, |
8de3a1ecac11
MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
437 "DROP TEMPORARY TABLE IF EXISTS DeletedResources"); |
8de3a1ecac11
MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
438 dropTemporaryTable.Execute(); |
8de3a1ecac11
MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
439 } |
8de3a1ecac11
MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
440 |
8de3a1ecac11
MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
441 { |
8de3a1ecac11
MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
442 DatabaseManager::CachedStatement lookupResourcesToDelete( |
8de3a1ecac11
MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
443 STATEMENT_FROM_HERE, manager, |
8de3a1ecac11
MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
444 "CREATE TEMPORARY TABLE DeletedResources SELECT * FROM (SELECT internalId, resourceType, publicId FROM Resources WHERE internalId=${id} OR parentId=${id} OR parentId IN (SELECT internalId FROM Resources WHERE parentId=${id}) OR parentId IN (SELECT internalId FROM Resources WHERE parentId IN (SELECT internalId FROM Resources WHERE parentId=${id}))) AS t"); |
8de3a1ecac11
MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
445 lookupResourcesToDelete.SetParameterType("id", ValueType_Integer64); |
8de3a1ecac11
MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
446 |
8de3a1ecac11
MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
447 Dictionary args; |
8de3a1ecac11
MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
448 args.SetIntegerValue("id", id); |
8de3a1ecac11
MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
449 lookupResourcesToDelete.Execute(args); |
0 | 450 } |
451 | |
452 { | |
453 DatabaseManager::CachedStatement deleteHierarchy( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
454 STATEMENT_FROM_HERE, manager, |
307
8de3a1ecac11
MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
455 "DELETE FROM Resources WHERE internalId IN (SELECT internalId FROM DeletedResources)"); |
8de3a1ecac11
MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
456 deleteHierarchy.Execute(); |
0 | 457 } |
458 | |
307
8de3a1ecac11
MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
459 SignalDeletedResources(output, manager); |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
460 SignalDeletedFiles(output, manager); |
0 | 461 } |
87
48d445f756db
new extension implemented for MySQL: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
84
diff
changeset
|
462 |
48d445f756db
new extension implemented for MySQL: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
84
diff
changeset
|
463 |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
464 int64_t MySQLIndex::GetLastChangeIndex(DatabaseManager& manager) |
87
48d445f756db
new extension implemented for MySQL: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
84
diff
changeset
|
465 { |
48d445f756db
new extension implemented for MySQL: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
84
diff
changeset
|
466 DatabaseManager::CachedStatement statement( |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
467 STATEMENT_FROM_HERE, manager, |
87
48d445f756db
new extension implemented for MySQL: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
84
diff
changeset
|
468 "SELECT value FROM GlobalIntegers WHERE property = 0"); |
48d445f756db
new extension implemented for MySQL: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
84
diff
changeset
|
469 |
48d445f756db
new extension implemented for MySQL: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
84
diff
changeset
|
470 statement.SetReadOnly(true); |
48d445f756db
new extension implemented for MySQL: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
84
diff
changeset
|
471 statement.Execute(); |
48d445f756db
new extension implemented for MySQL: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
84
diff
changeset
|
472 |
263
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
473 return statement.ReadInteger64(0); |
87
48d445f756db
new extension implemented for MySQL: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
84
diff
changeset
|
474 } |
110
441a472bfd93
new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
109
diff
changeset
|
475 |
441a472bfd93
new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
109
diff
changeset
|
476 |
441a472bfd93
new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
109
diff
changeset
|
477 #if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1 |
441a472bfd93
new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
109
diff
changeset
|
478 void MySQLIndex::CreateInstance(OrthancPluginCreateInstanceResult& result, |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
479 DatabaseManager& manager, |
110
441a472bfd93
new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
109
diff
changeset
|
480 const char* hashPatient, |
441a472bfd93
new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
109
diff
changeset
|
481 const char* hashStudy, |
441a472bfd93
new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
109
diff
changeset
|
482 const char* hashSeries, |
441a472bfd93
new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
109
diff
changeset
|
483 const char* hashInstance) |
441a472bfd93
new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
109
diff
changeset
|
484 { |
441a472bfd93
new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
109
diff
changeset
|
485 { |
441a472bfd93
new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
109
diff
changeset
|
486 DatabaseManager::CachedStatement statement( |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
487 STATEMENT_FROM_HERE, manager, |
110
441a472bfd93
new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
109
diff
changeset
|
488 "CALL CreateInstance(${patient}, ${study}, ${series}, ${instance}, " |
441a472bfd93
new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
109
diff
changeset
|
489 "@isNewPatient, @isNewStudy, @isNewSeries, @isNewInstance, " |
441a472bfd93
new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
109
diff
changeset
|
490 "@patientKey, @studyKey, @seriesKey, @instanceKey)"); |
441a472bfd93
new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
109
diff
changeset
|
491 |
441a472bfd93
new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
109
diff
changeset
|
492 statement.SetParameterType("patient", ValueType_Utf8String); |
441a472bfd93
new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
109
diff
changeset
|
493 statement.SetParameterType("study", ValueType_Utf8String); |
441a472bfd93
new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
109
diff
changeset
|
494 statement.SetParameterType("series", ValueType_Utf8String); |
441a472bfd93
new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
109
diff
changeset
|
495 statement.SetParameterType("instance", ValueType_Utf8String); |
441a472bfd93
new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
109
diff
changeset
|
496 |
441a472bfd93
new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
109
diff
changeset
|
497 Dictionary args; |
441a472bfd93
new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
109
diff
changeset
|
498 args.SetUtf8Value("patient", hashPatient); |
441a472bfd93
new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
109
diff
changeset
|
499 args.SetUtf8Value("study", hashStudy); |
441a472bfd93
new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
109
diff
changeset
|
500 args.SetUtf8Value("series", hashSeries); |
441a472bfd93
new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
109
diff
changeset
|
501 args.SetUtf8Value("instance", hashInstance); |
441a472bfd93
new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
109
diff
changeset
|
502 |
441a472bfd93
new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
109
diff
changeset
|
503 statement.Execute(args); |
441a472bfd93
new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
109
diff
changeset
|
504 |
441a472bfd93
new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
109
diff
changeset
|
505 if (!statement.IsDone()) |
441a472bfd93
new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
109
diff
changeset
|
506 { |
441a472bfd93
new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
109
diff
changeset
|
507 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database); |
441a472bfd93
new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
109
diff
changeset
|
508 } |
441a472bfd93
new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
109
diff
changeset
|
509 } |
441a472bfd93
new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
109
diff
changeset
|
510 |
441a472bfd93
new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
109
diff
changeset
|
511 { |
441a472bfd93
new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
109
diff
changeset
|
512 DatabaseManager::CachedStatement statement( |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
513 STATEMENT_FROM_HERE, manager, |
110
441a472bfd93
new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
109
diff
changeset
|
514 "SELECT @isNewPatient, @isNewStudy, @isNewSeries, @isNewInstance, " |
441a472bfd93
new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
109
diff
changeset
|
515 "@patientKey, @studyKey, @seriesKey, @instanceKey"); |
441a472bfd93
new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
109
diff
changeset
|
516 |
441a472bfd93
new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
109
diff
changeset
|
517 statement.Execute(); |
441a472bfd93
new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
109
diff
changeset
|
518 |
441a472bfd93
new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
109
diff
changeset
|
519 for (size_t i = 0; i < 8; i++) |
441a472bfd93
new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
109
diff
changeset
|
520 { |
441a472bfd93
new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
109
diff
changeset
|
521 statement.SetResultFieldType(i, ValueType_Integer64); |
441a472bfd93
new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
109
diff
changeset
|
522 } |
441a472bfd93
new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
109
diff
changeset
|
523 |
263
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
524 result.isNewInstance = (statement.ReadInteger64(3) == 1); |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
525 result.instanceId = statement.ReadInteger64(7); |
110
441a472bfd93
new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
109
diff
changeset
|
526 |
441a472bfd93
new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
109
diff
changeset
|
527 if (result.isNewInstance) |
441a472bfd93
new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
109
diff
changeset
|
528 { |
263
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
529 result.isNewPatient = (statement.ReadInteger64(0) == 1); |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
530 result.isNewStudy = (statement.ReadInteger64(1) == 1); |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
531 result.isNewSeries = (statement.ReadInteger64(2) == 1); |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
532 result.patientId = statement.ReadInteger64(4); |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
533 result.studyId = statement.ReadInteger64(5); |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
534 result.seriesId = statement.ReadInteger64(6); |
110
441a472bfd93
new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
109
diff
changeset
|
535 } |
441a472bfd93
new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
109
diff
changeset
|
536 } |
441a472bfd93
new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
109
diff
changeset
|
537 } |
441a472bfd93
new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
109
diff
changeset
|
538 #endif |
0 | 539 } |