annotate MySQL/Plugins/MySQLIndex.cpp @ 518:e3102bad13a4

fix SDK 1.12.4 protobuf
author Alain Mazy <am@orthanc.team>
date Thu, 06 Jun 2024 12:38:28 +0200
parents 54d518dcd74a
children 451125122692
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
507
54d518dcd74a updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium
54d518dcd74a updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
6 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium
459
ecd0b719cff5 update year to 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 426
diff changeset
7 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 *
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * This program is free software: you can redistribute it and/or
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * modify it under the terms of the GNU Affero General Public License
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * as published by the Free Software Foundation, either version 3 of
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * the License, or (at your option) any later version.
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 *
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * This program is distributed in the hope that it will be useful, but
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * Affero General Public License for more details.
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 *
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * You should have received a copy of the GNU Affero General Public License
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 **/
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #include "MySQLIndex.h"
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #include "../../Framework/Plugins/GlobalProperties.h"
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 #include "../../Framework/MySQL/MySQLDatabase.h"
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 #include "../../Framework/MySQL/MySQLTransaction.h"
137
52b3859ee0b7 MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
29 #include "MySQLDefinitions.h"
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 #include <EmbeddedResources.h> // Auto-generated file
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
157
275e14f57f1e replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 152
diff changeset
33 #include <Compatibility.h> // For std::unique_ptr<>
152
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
34 #include <Logging.h>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
35 #include <OrthancException.h>
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 #include <ctype.h>
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 namespace OrthancDatabases
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 {
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
41 MySQLIndex::MySQLIndex(OrthancPluginContext* context,
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
42 const MySQLParameters& parameters) :
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
43 IndexBackend(context),
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
44 parameters_(parameters),
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
45 clearAll_(false)
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
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
49
255
d663d9e44f8d reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
50 IDatabaseFactory* MySQLIndex::CreateDatabaseFactory()
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
51 {
255
d663d9e44f8d reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
52 return MySQLDatabase::CreateDatabaseFactory(parameters_);
226
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
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
55
144
740d9829f52e handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
56 static void ThrowCannotCreateTrigger()
740d9829f52e handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
57 {
740d9829f52e handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
58 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
59 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
60 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
61 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
62 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
63 "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
64 }
740d9829f52e handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
65
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
66
403
91124cc8a8c7 database plugins are informed about the identifier tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 400
diff changeset
67 void MySQLIndex::ConfigureDatabase(DatabaseManager& manager,
91124cc8a8c7 database plugins are informed about the identifier tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 400
diff changeset
68 bool hasIdentifierTags,
91124cc8a8c7 database plugins are informed about the identifier tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 400
diff changeset
69 const std::list<IdentifierTag>& identifierTags)
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 uint32_t expectedVersion = 6;
199
8cae98f73d53 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
72
8cae98f73d53 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
73 if (GetContext()) // "GetContext()" can possibly be NULL in the unit tests
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 {
199
8cae98f73d53 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
75 expectedVersion = OrthancPluginGetExpectedDatabaseVersion(GetContext());
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 // Check the expected version of the database
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 if (expectedVersion != 6)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 LOG(ERROR) << "This database plugin is incompatible with your version of Orthanc "
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 << "expecting the DB schema version " << expectedVersion
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 << ", but this plugin is only compatible with version 6";
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 throw Orthanc::OrthancException(Orthanc::ErrorCode_Plugin);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86
60
412e30336847 allowing dollars and underscores in MySQL database identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 53
diff changeset
87 if (!MySQLDatabase::IsValidDatabaseIdentifier(parameters_.GetDatabase()))
24
17f849b2af34 sharing plugin initialization code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 23
diff changeset
88 {
17f849b2af34 sharing plugin initialization code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 23
diff changeset
89 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
17f849b2af34 sharing plugin initialization code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 23
diff changeset
90 }
17f849b2af34 sharing plugin initialization code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 23
diff changeset
91
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 if (clearAll_)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 {
23
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
94 MySQLDatabase::ClearDatabase(parameters_);
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96
237
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
97 MySQLDatabase& db = dynamic_cast<MySQLDatabase&>(manager.GetDatabase());
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
98
16
9e419261f1c9 mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
99 {
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
100 MySQLDatabase::TransientAdvisoryLock lock(db, MYSQL_LOCK_DATABASE_SETUP);
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101
144
740d9829f52e handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
102 /**
740d9829f52e handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
103 * 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
104 * 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
105 * 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
106 * 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
107 * 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
108 * 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
109 *
740d9829f52e handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
110 * 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
111 * 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
112 * 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
113 * 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
114 * 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
115 **/
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 {
237
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
117 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
118
241
a063bbf10a3e simplification of class DatabaseManager::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
119 t.GetDatabaseTransaction().ExecuteMultiLines("ALTER DATABASE " + parameters_.GetDatabase() +
a063bbf10a3e simplification of class DatabaseManager::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
120 " CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci");
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121
144
740d9829f52e handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
122 // 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
123 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
124 {
740d9829f52e handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
125 std::string query;
740d9829f52e handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
126
740d9829f52e handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
127 Orthanc::EmbeddedResources::GetFileResource
740d9829f52e handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
128 (query, Orthanc::EmbeddedResources::MYSQL_PREPARE_INDEX);
237
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
129
241
a063bbf10a3e simplification of class DatabaseManager::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
130 // 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
131 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
132 }
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133
144
740d9829f52e handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
134 t.Commit();
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136
144
740d9829f52e handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
137 /**
740d9829f52e handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
138 * 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
139 * 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
140 * 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
141 * 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
142 * transaction).
740d9829f52e handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
143 **/
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 {
237
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
146 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
147
740d9829f52e handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
148 // 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
149 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
150 {
740d9829f52e handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
151 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
152 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
153 }
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 // 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
156 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
157 {
740d9829f52e handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
158 ThrowCannotCreateTrigger();
740d9829f52e handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
159 }
740d9829f52e handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
160
290
2790bafe3b3d cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 289
diff changeset
161 int version = 0;
2790bafe3b3d cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 289
diff changeset
162
237
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
163 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
164 {
237
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
165 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
166 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
167 version = expectedVersion;
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
740d9829f52e handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
170 if (version != 6)
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 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
173 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
174 }
740d9829f52e handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
175
740d9829f52e handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
176 t.Commit();
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178
144
740d9829f52e handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
179 int revision = 0;
740d9829f52e handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
180
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 {
237
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
182 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
183
237
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
184 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
185 {
740d9829f52e handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
186 revision = 1;
237
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
187 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
188 }
740d9829f52e handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
189
740d9829f52e handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
190 t.Commit();
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192
84
b96446b8718b Fix serialization of jobs if many of them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
193 if (revision == 1)
b96446b8718b Fix serialization of jobs if many of them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
194 {
237
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
195 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
196
84
b96446b8718b Fix serialization of jobs if many of them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
197 // 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
198 // 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
199 // store up to 4GB:
b96446b8718b Fix serialization of jobs if many of them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
200 // https://stackoverflow.com/a/13932834/881731
241
a063bbf10a3e simplification of class DatabaseManager::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
201 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
202
84
b96446b8718b Fix serialization of jobs if many of them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
203 revision = 2;
237
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
204 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
205
740d9829f52e handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
206 t.Commit();
84
b96446b8718b Fix serialization of jobs if many of them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
207 }
b96446b8718b Fix serialization of jobs if many of them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
208
87
48d445f756db new extension implemented for MySQL: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 84
diff changeset
209 if (revision == 2)
144
740d9829f52e handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
210 {
237
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
211 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
212
110
441a472bfd93 new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 109
diff changeset
213 // Install the "GetLastChangeIndex" extension
87
48d445f756db new extension implemented for MySQL: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 84
diff changeset
214 std::string query;
48d445f756db new extension implemented for MySQL: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 84
diff changeset
215
48d445f756db new extension implemented for MySQL: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 84
diff changeset
216 Orthanc::EmbeddedResources::GetFileResource
48d445f756db new extension implemented for MySQL: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 84
diff changeset
217 (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
218
241
a063bbf10a3e simplification of class DatabaseManager::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
219 // 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
220 db.ExecuteMultiLines(query, true);
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
221
241
a063bbf10a3e simplification of class DatabaseManager::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
222 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
223 {
740d9829f52e handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
224 ThrowCannotCreateTrigger();
740d9829f52e handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
225 }
87
48d445f756db new extension implemented for MySQL: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 84
diff changeset
226
48d445f756db new extension implemented for MySQL: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 84
diff changeset
227 revision = 3;
237
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
228 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
229
740d9829f52e handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
230 t.Commit();
87
48d445f756db new extension implemented for MySQL: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 84
diff changeset
231 }
144
740d9829f52e handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
232
109
3f31e3fa5114 MySQL: metadata can store larger values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 87
diff changeset
233 if (revision == 3)
3f31e3fa5114 MySQL: metadata can store larger values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 87
diff changeset
234 {
237
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
235 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
236
109
3f31e3fa5114 MySQL: metadata can store larger values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 87
diff changeset
237 // 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
238 // 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
239 // 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
240 // large amount of metadata.
426
d700c8f9fc24 migration to UCLouvain servers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 403
diff changeset
241 // https://orthanc.uclouvain.be/book/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
242 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
243
109
3f31e3fa5114 MySQL: metadata can store larger values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 87
diff changeset
244 revision = 4;
237
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
245 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
246
740d9829f52e handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
247 t.Commit();
109
3f31e3fa5114 MySQL: metadata can store larger values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 87
diff changeset
248 }
144
740d9829f52e handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
249
110
441a472bfd93 new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 109
diff changeset
250 if (revision == 4)
441a472bfd93 new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 109
diff changeset
251 {
237
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
252 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
253
110
441a472bfd93 new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 109
diff changeset
254 // Install the "CreateInstance" extension
441a472bfd93 new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 109
diff changeset
255 std::string query;
144
740d9829f52e handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
256
110
441a472bfd93 new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 109
diff changeset
257 Orthanc::EmbeddedResources::GetFileResource
441a472bfd93 new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 109
diff changeset
258 (query, Orthanc::EmbeddedResources::MYSQL_CREATE_INSTANCE);
237
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
259
241
a063bbf10a3e simplification of class DatabaseManager::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
260 // 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
261 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
262
110
441a472bfd93 new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 109
diff changeset
263 revision = 5;
237
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
264 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
265
740d9829f52e handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
266 t.Commit();
110
441a472bfd93 new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 109
diff changeset
267 }
289
0868500060f3 Fix serialization of large jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 263
diff changeset
268
0868500060f3 Fix serialization of large jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 263
diff changeset
269 if (revision == 5)
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 // 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
272 DatabaseManager::Transaction t(manager, TransactionType_ReadWrite);
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 if (t.GetDatabaseTransaction().DoesTableExist("ServerProperties"))
0868500060f3 Fix serialization of large jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 263
diff changeset
275 {
0868500060f3 Fix serialization of large jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 263
diff changeset
276 /**
0868500060f3 Fix serialization of large jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 263
diff changeset
277 * 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
278 * "TEXT" instead of "LONGTEXT", which prevented
0868500060f3 Fix serialization of large jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 263
diff changeset
279 * 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
280 * 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
281 * 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
282 * jobs engine" (in --trace mode).
0868500060f3 Fix serialization of large jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 263
diff changeset
283 * 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
284 **/
0868500060f3 Fix serialization of large jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 263
diff changeset
285 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
286 }
0868500060f3 Fix serialization of large jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 263
diff changeset
287 else
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 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
290 "property INTEGER, value LONGTEXT, PRIMARY KEY(server, property))");
0868500060f3 Fix serialization of large jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 263
diff changeset
291 }
0868500060f3 Fix serialization of large jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 263
diff changeset
292
0868500060f3 Fix serialization of large jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 263
diff changeset
293 // Revision 6 indicates that "value" of "ServerProperties" is
0868500060f3 Fix serialization of large jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 263
diff changeset
294 // "LONGTEXT", whereas revision 5 corresponds to "TEXT"
0868500060f3 Fix serialization of large jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 263
diff changeset
295 revision = 6;
0868500060f3 Fix serialization of large jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 263
diff changeset
296 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
297
0868500060f3 Fix serialization of large jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 263
diff changeset
298 t.Commit();
0868500060f3 Fix serialization of large jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 263
diff changeset
299 }
0868500060f3 Fix serialization of large jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 263
diff changeset
300
400
897253c21208 support for labels in mysql
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 389
diff changeset
301 if (revision == 6)
897253c21208 support for labels in mysql
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 389
diff changeset
302 {
897253c21208 support for labels in mysql
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 389
diff changeset
303 // Added new table "Labels" since release 5.0 to deal with
897253c21208 support for labels in mysql
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 389
diff changeset
304 // labels that were introduced in Orthanc 1.12.0
897253c21208 support for labels in mysql
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 389
diff changeset
305 DatabaseManager::Transaction t(manager, TransactionType_ReadWrite);
897253c21208 support for labels in mysql
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 389
diff changeset
306
897253c21208 support for labels in mysql
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 389
diff changeset
307 t.GetDatabaseTransaction().ExecuteMultiLines(
897253c21208 support for labels in mysql
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 389
diff changeset
308 "CREATE TABLE Labels(id BIGINT NOT NULL,"
897253c21208 support for labels in mysql
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 389
diff changeset
309 "label VARCHAR(64) NOT NULL,"
897253c21208 support for labels in mysql
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 389
diff changeset
310 "PRIMARY KEY(id, label),"
897253c21208 support for labels in mysql
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 389
diff changeset
311 "CONSTRAINT Labels1 FOREIGN KEY (id) REFERENCES Resources(internalId) ON DELETE CASCADE);"
897253c21208 support for labels in mysql
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 389
diff changeset
312 "CREATE INDEX LabelsIndex1 ON Labels(id);"
897253c21208 support for labels in mysql
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 389
diff changeset
313 "CREATE INDEX LabelsIndex2 ON Labels(label);");
897253c21208 support for labels in mysql
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 389
diff changeset
314
897253c21208 support for labels in mysql
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 389
diff changeset
315 revision = 7;
897253c21208 support for labels in mysql
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 389
diff changeset
316 SetGlobalIntegerProperty(manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabasePatchLevel, revision);
897253c21208 support for labels in mysql
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 389
diff changeset
317
897253c21208 support for labels in mysql
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 389
diff changeset
318 t.Commit();
897253c21208 support for labels in mysql
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 389
diff changeset
319 }
897253c21208 support for labels in mysql
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 389
diff changeset
320
424
95c413106a66 Introduced a procedure to delete resources (to be tested)
Alain Mazy <am@osimis.io>
parents: 403
diff changeset
321 if (revision == 7)
95c413106a66 Introduced a procedure to delete resources (to be tested)
Alain Mazy <am@osimis.io>
parents: 403
diff changeset
322 {
95c413106a66 Introduced a procedure to delete resources (to be tested)
Alain Mazy <am@osimis.io>
parents: 403
diff changeset
323 DatabaseManager::Transaction t(manager, TransactionType_ReadWrite);
95c413106a66 Introduced a procedure to delete resources (to be tested)
Alain Mazy <am@osimis.io>
parents: 403
diff changeset
324
95c413106a66 Introduced a procedure to delete resources (to be tested)
Alain Mazy <am@osimis.io>
parents: 403
diff changeset
325 // Install the "CreateInstance" extension
95c413106a66 Introduced a procedure to delete resources (to be tested)
Alain Mazy <am@osimis.io>
parents: 403
diff changeset
326 std::string query;
95c413106a66 Introduced a procedure to delete resources (to be tested)
Alain Mazy <am@osimis.io>
parents: 403
diff changeset
327
95c413106a66 Introduced a procedure to delete resources (to be tested)
Alain Mazy <am@osimis.io>
parents: 403
diff changeset
328 Orthanc::EmbeddedResources::GetFileResource
95c413106a66 Introduced a procedure to delete resources (to be tested)
Alain Mazy <am@osimis.io>
parents: 403
diff changeset
329 (query, Orthanc::EmbeddedResources::MYSQL_DELETE_RESOURCES);
95c413106a66 Introduced a procedure to delete resources (to be tested)
Alain Mazy <am@osimis.io>
parents: 403
diff changeset
330
95c413106a66 Introduced a procedure to delete resources (to be tested)
Alain Mazy <am@osimis.io>
parents: 403
diff changeset
331 // Need to escape arobases: Don't use "t.GetDatabaseTransaction().ExecuteMultiLines()" here
95c413106a66 Introduced a procedure to delete resources (to be tested)
Alain Mazy <am@osimis.io>
parents: 403
diff changeset
332 db.ExecuteMultiLines(query, true);
95c413106a66 Introduced a procedure to delete resources (to be tested)
Alain Mazy <am@osimis.io>
parents: 403
diff changeset
333
95c413106a66 Introduced a procedure to delete resources (to be tested)
Alain Mazy <am@osimis.io>
parents: 403
diff changeset
334 revision = 8;
95c413106a66 Introduced a procedure to delete resources (to be tested)
Alain Mazy <am@osimis.io>
parents: 403
diff changeset
335 SetGlobalIntegerProperty(manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabasePatchLevel, revision);
95c413106a66 Introduced a procedure to delete resources (to be tested)
Alain Mazy <am@osimis.io>
parents: 403
diff changeset
336
95c413106a66 Introduced a procedure to delete resources (to be tested)
Alain Mazy <am@osimis.io>
parents: 403
diff changeset
337 t.Commit();
95c413106a66 Introduced a procedure to delete resources (to be tested)
Alain Mazy <am@osimis.io>
parents: 403
diff changeset
338 }
95c413106a66 Introduced a procedure to delete resources (to be tested)
Alain Mazy <am@osimis.io>
parents: 403
diff changeset
339
95c413106a66 Introduced a procedure to delete resources (to be tested)
Alain Mazy <am@osimis.io>
parents: 403
diff changeset
340
95c413106a66 Introduced a procedure to delete resources (to be tested)
Alain Mazy <am@osimis.io>
parents: 403
diff changeset
341 if (revision != 8)
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
342 {
53
am@osimis.io
parents: 24
diff changeset
343 LOG(ERROR) << "MySQL plugin is incompatible with database schema revision: " << revision;
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
344 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
345 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
346 }
137
52b3859ee0b7 MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
347
238
f033cc039264 new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
348
137
52b3859ee0b7 MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
349 /**
52b3859ee0b7 MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
350 * 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
351 * "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
352 * 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
353 * 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
354 * previously-acquired locks.
52b3859ee0b7 MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
355 * 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
356 **/
52b3859ee0b7 MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
357 if (parameters_.HasLock())
52b3859ee0b7 MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
358 {
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
359 db.AdvisoryLock(MYSQL_LOCK_INDEX);
137
52b3859ee0b7 MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
360 }
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
361 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
362
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
363
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 221
diff changeset
364 int64_t MySQLIndex::CreateResource(DatabaseManager& manager,
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 221
diff changeset
365 const char* publicId,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
366 OrthancPluginResourceType type)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
367 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
368 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
369 DatabaseManager::CachedStatement statement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 221
diff changeset
370 STATEMENT_FROM_HERE, manager,
302
3a52e27a2d80 in GenericFormatter, replaced ${} by ${AUTOINCREMENT}
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 290
diff changeset
371 "INSERT INTO Resources VALUES(NULL, ${type}, ${id}, NULL)");
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
372
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
373 statement.SetParameterType("id", ValueType_Utf8String);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
374 statement.SetParameterType("type", ValueType_Integer64);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
375
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
376 Dictionary args;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
377 args.SetUtf8Value("id", publicId);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
378 args.SetIntegerValue("type", static_cast<int>(type));
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
379
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
380 statement.Execute(args);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
381 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
382
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
383 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
384 DatabaseManager::CachedStatement statement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 221
diff changeset
385 STATEMENT_FROM_HERE, manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
386 "SELECT LAST_INSERT_ID()");
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
387
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
388 statement.Execute();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
389
263
29d2b76516f6 fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 255
diff changeset
390 return statement.ReadInteger64(0);
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
391 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
392 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
393
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
394
203
2089d4071408 moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
395 void MySQLIndex::DeleteResource(IDatabaseBackendOutput& output,
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 221
diff changeset
396 DatabaseManager& manager,
201
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 199
diff changeset
397 int64_t id)
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
398 {
305
87f0e29a1dc1 added Dictionary::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 302
diff changeset
399 /**
87f0e29a1dc1 added Dictionary::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 302
diff changeset
400 * Contrarily to PostgreSQL and SQLite, the MySQL dialect doesn't
87f0e29a1dc1 added Dictionary::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 302
diff changeset
401 * 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
402 * manually reimplemented.
87f0e29a1dc1 added Dictionary::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 302
diff changeset
403 **/
87f0e29a1dc1 added Dictionary::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 302
diff changeset
404
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 221
diff changeset
405 ClearDeletedFiles(manager);
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
406
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
407 // Recursive exploration of resources to be deleted, from the "id"
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
408 // resource to the top of the tree of resources
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
409
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
410 bool done = false;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
411
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
412 while (!done)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
413 {
307
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
414 bool hasSibling = false;
321
eb0b04c10bc4 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 307
diff changeset
415 int64_t parentId = -1; // Dummy initialization
307
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
416
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
417 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
418 DatabaseManager::CachedStatement lookupSiblings(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 221
diff changeset
419 STATEMENT_FROM_HERE, manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
420 "SELECT parentId FROM Resources "
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
421 "WHERE parentId = (SELECT parentId FROM Resources WHERE internalId=${id});");
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
422
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
423 lookupSiblings.SetParameterType("id", ValueType_Integer64);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
424
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
425 Dictionary args;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
426 args.SetIntegerValue("id", id);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
427
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
428 lookupSiblings.Execute(args);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
429
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
430 if (lookupSiblings.IsDone())
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
431 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
432 // "id" is a root node
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
433 done = true;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
434 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
435 else
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
436 {
307
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
437 parentId = lookupSiblings.ReadInteger64(0);
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
438 lookupSiblings.Next();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
439
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
440 if (lookupSiblings.IsDone())
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
441 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
442 // "id" has no sibling node, recursively remove
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
443 done = false;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
444 id = parentId;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
445 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
446 else
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
447 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
448 // "id" has at least one sibling node: the parent node is the remaining ancestor
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
449 done = true;
307
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
450 hasSibling = true;
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
451 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
452 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
453 }
307
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
454
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
455 if (hasSibling)
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
456 {
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
457 // 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
458 // DatabaseManager::CachedStatement
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
459
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
460 DatabaseManager::CachedStatement parent(
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
461 STATEMENT_FROM_HERE, manager,
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
462 "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
463
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
464 parent.SetParameterType("id", ValueType_Integer64);
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
465
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
466 Dictionary args2;
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
467 args2.SetIntegerValue("id", parentId);
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
468
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
469 parent.Execute(args2);
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
470
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
471 output.SignalRemainingAncestor(
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
472 parent.ReadString(0),
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
473 static_cast<OrthancPluginResourceType>(parent.ReadInteger32(1)));
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
474 }
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
475 }
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
476
455
d0dd95ff0662 move temp table creation out of the procedure
Alain Mazy <am@osimis.io>
parents: 454
diff changeset
477 {
d0dd95ff0662 move temp table creation out of the procedure
Alain Mazy <am@osimis.io>
parents: 454
diff changeset
478 DatabaseManager::CachedStatement dropTemporaryTable(
d0dd95ff0662 move temp table creation out of the procedure
Alain Mazy <am@osimis.io>
parents: 454
diff changeset
479 STATEMENT_FROM_HERE, manager,
d0dd95ff0662 move temp table creation out of the procedure
Alain Mazy <am@osimis.io>
parents: 454
diff changeset
480 "DROP TEMPORARY TABLE IF EXISTS DeletedResources");
d0dd95ff0662 move temp table creation out of the procedure
Alain Mazy <am@osimis.io>
parents: 454
diff changeset
481 dropTemporaryTable.Execute();
d0dd95ff0662 move temp table creation out of the procedure
Alain Mazy <am@osimis.io>
parents: 454
diff changeset
482 }
424
95c413106a66 Introduced a procedure to delete resources (to be tested)
Alain Mazy <am@osimis.io>
parents: 403
diff changeset
483
455
d0dd95ff0662 move temp table creation out of the procedure
Alain Mazy <am@osimis.io>
parents: 454
diff changeset
484 {
d0dd95ff0662 move temp table creation out of the procedure
Alain Mazy <am@osimis.io>
parents: 454
diff changeset
485 DatabaseManager::CachedStatement lookupResourcesToDelete(
d0dd95ff0662 move temp table creation out of the procedure
Alain Mazy <am@osimis.io>
parents: 454
diff changeset
486 STATEMENT_FROM_HERE, manager,
d0dd95ff0662 move temp table creation out of the procedure
Alain Mazy <am@osimis.io>
parents: 454
diff changeset
487 "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");
d0dd95ff0662 move temp table creation out of the procedure
Alain Mazy <am@osimis.io>
parents: 454
diff changeset
488 lookupResourcesToDelete.SetParameterType("id", ValueType_Integer64);
424
95c413106a66 Introduced a procedure to delete resources (to be tested)
Alain Mazy <am@osimis.io>
parents: 403
diff changeset
489
455
d0dd95ff0662 move temp table creation out of the procedure
Alain Mazy <am@osimis.io>
parents: 454
diff changeset
490 Dictionary args;
d0dd95ff0662 move temp table creation out of the procedure
Alain Mazy <am@osimis.io>
parents: 454
diff changeset
491 args.SetIntegerValue("id", id);
d0dd95ff0662 move temp table creation out of the procedure
Alain Mazy <am@osimis.io>
parents: 454
diff changeset
492 lookupResourcesToDelete.Execute(args);
d0dd95ff0662 move temp table creation out of the procedure
Alain Mazy <am@osimis.io>
parents: 454
diff changeset
493 }
424
95c413106a66 Introduced a procedure to delete resources (to be tested)
Alain Mazy <am@osimis.io>
parents: 403
diff changeset
494
95c413106a66 Introduced a procedure to delete resources (to be tested)
Alain Mazy <am@osimis.io>
parents: 403
diff changeset
495 // {
95c413106a66 Introduced a procedure to delete resources (to be tested)
Alain Mazy <am@osimis.io>
parents: 403
diff changeset
496 // DatabaseManager::CachedStatement deleteHierarchy(
95c413106a66 Introduced a procedure to delete resources (to be tested)
Alain Mazy <am@osimis.io>
parents: 403
diff changeset
497 // STATEMENT_FROM_HERE, manager,
95c413106a66 Introduced a procedure to delete resources (to be tested)
Alain Mazy <am@osimis.io>
parents: 403
diff changeset
498 // "DELETE FROM Resources WHERE internalId IN (SELECT internalId FROM DeletedResources)");
95c413106a66 Introduced a procedure to delete resources (to be tested)
Alain Mazy <am@osimis.io>
parents: 403
diff changeset
499 // deleteHierarchy.Execute();
95c413106a66 Introduced a procedure to delete resources (to be tested)
Alain Mazy <am@osimis.io>
parents: 403
diff changeset
500 // }
95c413106a66 Introduced a procedure to delete resources (to be tested)
Alain Mazy <am@osimis.io>
parents: 403
diff changeset
501
307
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
502
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
503 {
424
95c413106a66 Introduced a procedure to delete resources (to be tested)
Alain Mazy <am@osimis.io>
parents: 403
diff changeset
504 DatabaseManager::CachedStatement deleteResources(
307
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
505 STATEMENT_FROM_HERE, manager,
424
95c413106a66 Introduced a procedure to delete resources (to be tested)
Alain Mazy <am@osimis.io>
parents: 403
diff changeset
506 "CALL DeleteResources(${id})");
95c413106a66 Introduced a procedure to delete resources (to be tested)
Alain Mazy <am@osimis.io>
parents: 403
diff changeset
507
95c413106a66 Introduced a procedure to delete resources (to be tested)
Alain Mazy <am@osimis.io>
parents: 403
diff changeset
508 deleteResources.SetParameterType("id", ValueType_Integer64);
307
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
509
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
510 Dictionary args;
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
511 args.SetIntegerValue("id", id);
424
95c413106a66 Introduced a procedure to delete resources (to be tested)
Alain Mazy <am@osimis.io>
parents: 403
diff changeset
512
95c413106a66 Introduced a procedure to delete resources (to be tested)
Alain Mazy <am@osimis.io>
parents: 403
diff changeset
513 deleteResources.Execute(args);
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
514 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
515
307
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
516 SignalDeletedResources(output, manager);
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 221
diff changeset
517 SignalDeletedFiles(output, manager);
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
518 }
87
48d445f756db new extension implemented for MySQL: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 84
diff changeset
519
48d445f756db new extension implemented for MySQL: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 84
diff changeset
520
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 221
diff changeset
521 int64_t MySQLIndex::GetLastChangeIndex(DatabaseManager& manager)
87
48d445f756db new extension implemented for MySQL: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 84
diff changeset
522 {
48d445f756db new extension implemented for MySQL: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 84
diff changeset
523 DatabaseManager::CachedStatement statement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 221
diff changeset
524 STATEMENT_FROM_HERE, manager,
87
48d445f756db new extension implemented for MySQL: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 84
diff changeset
525 "SELECT value FROM GlobalIntegers WHERE property = 0");
48d445f756db new extension implemented for MySQL: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 84
diff changeset
526
48d445f756db new extension implemented for MySQL: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 84
diff changeset
527 statement.SetReadOnly(true);
48d445f756db new extension implemented for MySQL: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 84
diff changeset
528 statement.Execute();
48d445f756db new extension implemented for MySQL: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 84
diff changeset
529
263
29d2b76516f6 fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 255
diff changeset
530 return statement.ReadInteger64(0);
87
48d445f756db new extension implemented for MySQL: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 84
diff changeset
531 }
110
441a472bfd93 new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 109
diff changeset
532
441a472bfd93 new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 109
diff changeset
533
441a472bfd93 new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 109
diff changeset
534 #if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1
441a472bfd93 new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 109
diff changeset
535 void MySQLIndex::CreateInstance(OrthancPluginCreateInstanceResult& result,
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 221
diff changeset
536 DatabaseManager& manager,
110
441a472bfd93 new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 109
diff changeset
537 const char* hashPatient,
441a472bfd93 new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 109
diff changeset
538 const char* hashStudy,
441a472bfd93 new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 109
diff changeset
539 const char* hashSeries,
441a472bfd93 new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 109
diff changeset
540 const char* hashInstance)
441a472bfd93 new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 109
diff changeset
541 {
441a472bfd93 new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 109
diff changeset
542 {
441a472bfd93 new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 109
diff changeset
543 DatabaseManager::CachedStatement statement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 221
diff changeset
544 STATEMENT_FROM_HERE, manager,
110
441a472bfd93 new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 109
diff changeset
545 "CALL CreateInstance(${patient}, ${study}, ${series}, ${instance}, "
441a472bfd93 new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 109
diff changeset
546 "@isNewPatient, @isNewStudy, @isNewSeries, @isNewInstance, "
441a472bfd93 new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 109
diff changeset
547 "@patientKey, @studyKey, @seriesKey, @instanceKey)");
441a472bfd93 new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 109
diff changeset
548
441a472bfd93 new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 109
diff changeset
549 statement.SetParameterType("patient", ValueType_Utf8String);
441a472bfd93 new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 109
diff changeset
550 statement.SetParameterType("study", ValueType_Utf8String);
441a472bfd93 new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 109
diff changeset
551 statement.SetParameterType("series", ValueType_Utf8String);
441a472bfd93 new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 109
diff changeset
552 statement.SetParameterType("instance", ValueType_Utf8String);
441a472bfd93 new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 109
diff changeset
553
441a472bfd93 new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 109
diff changeset
554 Dictionary args;
441a472bfd93 new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 109
diff changeset
555 args.SetUtf8Value("patient", hashPatient);
441a472bfd93 new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 109
diff changeset
556 args.SetUtf8Value("study", hashStudy);
441a472bfd93 new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 109
diff changeset
557 args.SetUtf8Value("series", hashSeries);
441a472bfd93 new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 109
diff changeset
558 args.SetUtf8Value("instance", hashInstance);
441a472bfd93 new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 109
diff changeset
559
441a472bfd93 new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 109
diff changeset
560 statement.Execute(args);
441a472bfd93 new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 109
diff changeset
561
441a472bfd93 new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 109
diff changeset
562 if (!statement.IsDone())
441a472bfd93 new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 109
diff changeset
563 {
441a472bfd93 new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 109
diff changeset
564 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database);
441a472bfd93 new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 109
diff changeset
565 }
441a472bfd93 new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 109
diff changeset
566 }
441a472bfd93 new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 109
diff changeset
567
441a472bfd93 new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 109
diff changeset
568 {
441a472bfd93 new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 109
diff changeset
569 DatabaseManager::CachedStatement statement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 221
diff changeset
570 STATEMENT_FROM_HERE, manager,
110
441a472bfd93 new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 109
diff changeset
571 "SELECT @isNewPatient, @isNewStudy, @isNewSeries, @isNewInstance, "
441a472bfd93 new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 109
diff changeset
572 "@patientKey, @studyKey, @seriesKey, @instanceKey");
441a472bfd93 new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 109
diff changeset
573
441a472bfd93 new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 109
diff changeset
574 statement.Execute();
441a472bfd93 new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 109
diff changeset
575
441a472bfd93 new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 109
diff changeset
576 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
577 {
441a472bfd93 new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 109
diff changeset
578 statement.SetResultFieldType(i, ValueType_Integer64);
441a472bfd93 new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 109
diff changeset
579 }
441a472bfd93 new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 109
diff changeset
580
263
29d2b76516f6 fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 255
diff changeset
581 result.isNewInstance = (statement.ReadInteger64(3) == 1);
29d2b76516f6 fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 255
diff changeset
582 result.instanceId = statement.ReadInteger64(7);
110
441a472bfd93 new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 109
diff changeset
583
441a472bfd93 new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 109
diff changeset
584 if (result.isNewInstance)
441a472bfd93 new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 109
diff changeset
585 {
263
29d2b76516f6 fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 255
diff changeset
586 result.isNewPatient = (statement.ReadInteger64(0) == 1);
29d2b76516f6 fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 255
diff changeset
587 result.isNewStudy = (statement.ReadInteger64(1) == 1);
29d2b76516f6 fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 255
diff changeset
588 result.isNewSeries = (statement.ReadInteger64(2) == 1);
29d2b76516f6 fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 255
diff changeset
589 result.patientId = statement.ReadInteger64(4);
29d2b76516f6 fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 255
diff changeset
590 result.studyId = statement.ReadInteger64(5);
29d2b76516f6 fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 255
diff changeset
591 result.seriesId = statement.ReadInteger64(6);
110
441a472bfd93 new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 109
diff changeset
592 }
441a472bfd93 new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 109
diff changeset
593 }
441a472bfd93 new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 109
diff changeset
594 }
441a472bfd93 new extension implemented for MySQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 109
diff changeset
595 #endif
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
596 }