Mercurial > hg > orthanc-databases
annotate Framework/MySQL/MySQLDatabase.cpp @ 357:fa4535e93b3d OrthancOdbc-1.1
clean NEWS in branch
author | Alain Mazy <am@osimis.io> |
---|---|
date | Mon, 06 Dec 2021 17:25:06 +0100 |
parents | b8ba198a8df3 |
children | 16aac0287485 |
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 | |
193
3236894320d6
upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
187
diff
changeset
|
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium |
0 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU Affero General Public License | |
9 * as published by the Free Software Foundation, either version 3 of | |
10 * the License, or (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Affero General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Affero General Public License | |
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 **/ | |
20 | |
21 | |
22 #include "MySQLDatabase.h" | |
23 | |
226
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
217
diff
changeset
|
24 #include "../Common/ImplicitTransaction.h" |
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
217
diff
changeset
|
25 #include "../Common/Integer64Value.h" |
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
217
diff
changeset
|
26 #include "../Common/RetryDatabaseFactory.h" |
0 | 27 #include "MySQLResult.h" |
28 #include "MySQLStatement.h" | |
29 #include "MySQLTransaction.h" | |
30 | |
157
275e14f57f1e
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
31 #include <Compatibility.h> // For std::unique_ptr<> |
152 | 32 #include <Logging.h> |
33 #include <OrthancException.h> | |
34 #include <Toolbox.h> | |
0 | 35 |
6 | 36 #include <errmsg.h> |
0 | 37 #include <mysqld_error.h> |
38 | |
39 #include <memory> | |
135
e26690365c25
MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
40 #include <boost/thread.hpp> |
0 | 41 |
42 namespace OrthancDatabases | |
43 { | |
44 void MySQLDatabase::Close() | |
45 { | |
46 if (mysql_ != NULL) | |
47 { | |
48 LOG(INFO) << "Closing connection to MySQL database"; | |
49 mysql_close(mysql_); | |
50 mysql_ = NULL; | |
51 } | |
52 } | |
53 | |
54 | |
240
c82c2cf84ae8
added handling of CR_COMMANDS_OUT_OF_SYNC
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
55 void MySQLDatabase::ThrowException() |
c82c2cf84ae8
added handling of CR_COMMANDS_OUT_OF_SYNC
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
56 { |
c82c2cf84ae8
added handling of CR_COMMANDS_OUT_OF_SYNC
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
57 LogError(); |
c82c2cf84ae8
added handling of CR_COMMANDS_OUT_OF_SYNC
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
58 |
c82c2cf84ae8
added handling of CR_COMMANDS_OUT_OF_SYNC
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
59 unsigned int error = mysql_errno(mysql_); |
c82c2cf84ae8
added handling of CR_COMMANDS_OUT_OF_SYNC
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
60 if (error == CR_SERVER_GONE_ERROR || |
c82c2cf84ae8
added handling of CR_COMMANDS_OUT_OF_SYNC
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
61 error == CR_SERVER_LOST || |
c82c2cf84ae8
added handling of CR_COMMANDS_OUT_OF_SYNC
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
62 error == ER_QUERY_INTERRUPTED) |
c82c2cf84ae8
added handling of CR_COMMANDS_OUT_OF_SYNC
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
63 { |
c82c2cf84ae8
added handling of CR_COMMANDS_OUT_OF_SYNC
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
64 throw Orthanc::OrthancException(Orthanc::ErrorCode_DatabaseUnavailable); |
c82c2cf84ae8
added handling of CR_COMMANDS_OUT_OF_SYNC
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
65 } |
c82c2cf84ae8
added handling of CR_COMMANDS_OUT_OF_SYNC
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
66 else if (error == CR_COMMANDS_OUT_OF_SYNC) |
c82c2cf84ae8
added handling of CR_COMMANDS_OUT_OF_SYNC
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
67 { |
c82c2cf84ae8
added handling of CR_COMMANDS_OUT_OF_SYNC
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
68 #if !defined(MARIADB_VERSION_ID) |
c82c2cf84ae8
added handling of CR_COMMANDS_OUT_OF_SYNC
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
69 LOG(ERROR) << "TODO - This error seems to be related to the use of libmysqlclient: Try to switch to mariadb-connector"; |
c82c2cf84ae8
added handling of CR_COMMANDS_OUT_OF_SYNC
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
70 #endif |
c82c2cf84ae8
added handling of CR_COMMANDS_OUT_OF_SYNC
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
71 |
c82c2cf84ae8
added handling of CR_COMMANDS_OUT_OF_SYNC
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
72 throw Orthanc::OrthancException(Orthanc::ErrorCode_DatabaseUnavailable); |
c82c2cf84ae8
added handling of CR_COMMANDS_OUT_OF_SYNC
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
73 } |
c82c2cf84ae8
added handling of CR_COMMANDS_OUT_OF_SYNC
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
74 else if (error == ER_LOCK_DEADLOCK) |
c82c2cf84ae8
added handling of CR_COMMANDS_OUT_OF_SYNC
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
75 { |
c82c2cf84ae8
added handling of CR_COMMANDS_OUT_OF_SYNC
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
76 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 9, 2) |
c82c2cf84ae8
added handling of CR_COMMANDS_OUT_OF_SYNC
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
77 throw Orthanc::OrthancException(Orthanc::ErrorCode_DatabaseCannotSerialize); |
c82c2cf84ae8
added handling of CR_COMMANDS_OUT_OF_SYNC
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
78 #else |
c82c2cf84ae8
added handling of CR_COMMANDS_OUT_OF_SYNC
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
79 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database, "Collision between multiple writers"); |
c82c2cf84ae8
added handling of CR_COMMANDS_OUT_OF_SYNC
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
80 #endif |
c82c2cf84ae8
added handling of CR_COMMANDS_OUT_OF_SYNC
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
81 } |
c82c2cf84ae8
added handling of CR_COMMANDS_OUT_OF_SYNC
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
82 else |
c82c2cf84ae8
added handling of CR_COMMANDS_OUT_OF_SYNC
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
83 { |
c82c2cf84ae8
added handling of CR_COMMANDS_OUT_OF_SYNC
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
84 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database); |
c82c2cf84ae8
added handling of CR_COMMANDS_OUT_OF_SYNC
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
85 } |
c82c2cf84ae8
added handling of CR_COMMANDS_OUT_OF_SYNC
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
86 } |
c82c2cf84ae8
added handling of CR_COMMANDS_OUT_OF_SYNC
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
87 |
c82c2cf84ae8
added handling of CR_COMMANDS_OUT_OF_SYNC
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
88 |
0 | 89 void MySQLDatabase::CheckErrorCode(int code) |
90 { | |
91 if (code == 0) | |
92 { | |
93 return; | |
94 } | |
95 else | |
96 { | |
240
c82c2cf84ae8
added handling of CR_COMMANDS_OUT_OF_SYNC
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
97 ThrowException(); |
0 | 98 } |
99 } | |
100 | |
101 | |
102 MySQLDatabase::MySQLDatabase(const MySQLParameters& parameters) : | |
103 parameters_(parameters), | |
104 mysql_(NULL) | |
105 { | |
106 } | |
107 | |
108 | |
46
6a574d810b98
Compatibility with MySQL 8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
109 MySQLDatabase::~MySQLDatabase() |
6a574d810b98
Compatibility with MySQL 8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
110 { |
6a574d810b98
Compatibility with MySQL 8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
111 try |
6a574d810b98
Compatibility with MySQL 8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
112 { |
6a574d810b98
Compatibility with MySQL 8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
113 Close(); |
6a574d810b98
Compatibility with MySQL 8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
114 } |
6a574d810b98
Compatibility with MySQL 8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
115 catch (Orthanc::OrthancException&) |
6a574d810b98
Compatibility with MySQL 8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
116 { |
6a574d810b98
Compatibility with MySQL 8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
117 // Ignore possible exceptions due to connection loss |
6a574d810b98
Compatibility with MySQL 8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
118 } |
6a574d810b98
Compatibility with MySQL 8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
119 } |
6a574d810b98
Compatibility with MySQL 8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
120 |
6a574d810b98
Compatibility with MySQL 8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
121 |
0 | 122 void MySQLDatabase::LogError() |
123 { | |
124 if (mysql_ != NULL) | |
125 { | |
126 LOG(ERROR) << "MySQL error (" << mysql_errno(mysql_) | |
127 << "," << mysql_sqlstate(mysql_) | |
128 << "): " << mysql_error(mysql_); | |
129 } | |
130 } | |
131 | |
132 | |
133 MYSQL* MySQLDatabase::GetObject() | |
134 { | |
135 if (mysql_ == NULL) | |
136 { | |
137 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
138 } | |
139 else | |
140 { | |
141 return mysql_; | |
142 } | |
143 } | |
144 | |
145 | |
23
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
146 void MySQLDatabase::OpenInternal(const char* db) |
0 | 147 { |
148 if (mysql_ != NULL) | |
149 { | |
150 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
151 } | |
152 | |
153 mysql_ = mysql_init(NULL); | |
154 if (mysql_ == NULL) | |
155 { | |
156 LOG(ERROR) << "Cannot initialize the MySQL connector"; | |
157 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
158 } | |
46
6a574d810b98
Compatibility with MySQL 8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
159 |
6a574d810b98
Compatibility with MySQL 8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
160 if (parameters_.GetUnixSocket().empty()) |
6a574d810b98
Compatibility with MySQL 8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
161 { |
6a574d810b98
Compatibility with MySQL 8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
162 // Fallback to TCP connection if no UNIX socket is provided |
6a574d810b98
Compatibility with MySQL 8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
163 unsigned int protocol = MYSQL_PROTOCOL_TCP; |
6a574d810b98
Compatibility with MySQL 8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
164 mysql_options(mysql_, MYSQL_OPT_PROTOCOL, (unsigned int *) &protocol); |
6a574d810b98
Compatibility with MySQL 8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
165 } |
163
4d32c9c8d6c0
Added support for TLS connections
Alain Mazy <alain@mazy.be>
parents:
157
diff
changeset
|
166 |
4d32c9c8d6c0
Added support for TLS connections
Alain Mazy <alain@mazy.be>
parents:
157
diff
changeset
|
167 if (parameters_.IsSsl()) |
4d32c9c8d6c0
Added support for TLS connections
Alain Mazy <alain@mazy.be>
parents:
157
diff
changeset
|
168 { |
4d32c9c8d6c0
Added support for TLS connections
Alain Mazy <alain@mazy.be>
parents:
157
diff
changeset
|
169 if (parameters_.IsVerifyServerCertificates()) |
4d32c9c8d6c0
Added support for TLS connections
Alain Mazy <alain@mazy.be>
parents:
157
diff
changeset
|
170 { |
187
0b78198c28d6
compatibility with mysql client 8.x
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
186
diff
changeset
|
171 #if (MYSQL_VERSION_ID > 50110 && MYSQL_VERSION_ID < 80000) // Removed in MySQL client 8.0 |
163
4d32c9c8d6c0
Added support for TLS connections
Alain Mazy <alain@mazy.be>
parents:
157
diff
changeset
|
172 my_bool verifyCert = 1; |
4d32c9c8d6c0
Added support for TLS connections
Alain Mazy <alain@mazy.be>
parents:
157
diff
changeset
|
173 mysql_options(mysql_, MYSQL_OPT_SSL_VERIFY_SERVER_CERT, (void *) &verifyCert); |
187
0b78198c28d6
compatibility with mysql client 8.x
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
186
diff
changeset
|
174 #endif |
0b78198c28d6
compatibility with mysql client 8.x
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
186
diff
changeset
|
175 |
165
0632c2408af3
fix compatiblity with mysql client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
163
diff
changeset
|
176 mysql_options(mysql_, MYSQL_OPT_SSL_CA, (void *)(parameters_.GetSslCaCertificates())); |
163
4d32c9c8d6c0
Added support for TLS connections
Alain Mazy <alain@mazy.be>
parents:
157
diff
changeset
|
177 } |
4d32c9c8d6c0
Added support for TLS connections
Alain Mazy <alain@mazy.be>
parents:
157
diff
changeset
|
178 |
187
0b78198c28d6
compatibility with mysql client 8.x
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
186
diff
changeset
|
179 #if (MYSQL_VERSION_ID > 50110 && MYSQL_VERSION_ID < 80000) // Removed in MySQL client 8.0 |
163
4d32c9c8d6c0
Added support for TLS connections
Alain Mazy <alain@mazy.be>
parents:
157
diff
changeset
|
180 my_bool enforceTls = 1; |
4d32c9c8d6c0
Added support for TLS connections
Alain Mazy <alain@mazy.be>
parents:
157
diff
changeset
|
181 mysql_options(mysql_, MYSQL_OPT_SSL_ENFORCE, (void *) &enforceTls); |
187
0b78198c28d6
compatibility with mysql client 8.x
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
186
diff
changeset
|
182 #endif |
163
4d32c9c8d6c0
Added support for TLS connections
Alain Mazy <alain@mazy.be>
parents:
157
diff
changeset
|
183 } |
4d32c9c8d6c0
Added support for TLS connections
Alain Mazy <alain@mazy.be>
parents:
157
diff
changeset
|
184 |
0 | 185 const char* socket = (parameters_.GetUnixSocket().empty() ? NULL : |
186 parameters_.GetUnixSocket().c_str()); | |
187 | |
188 if (mysql_real_connect(mysql_, | |
189 parameters_.GetHost().c_str(), | |
190 parameters_.GetUsername().c_str(), | |
191 parameters_.GetPassword().c_str(), db, | |
192 parameters_.GetPort(), socket, 0) == 0) | |
193 { | |
194 LogError(); | |
195 Close(); | |
196 throw Orthanc::OrthancException(Orthanc::ErrorCode_DatabaseUnavailable); | |
197 } | |
198 else | |
199 { | |
200 LOG(INFO) << "Successful connection to MySQL database"; | |
201 } | |
202 | |
203 if (mysql_set_character_set(mysql_, "utf8mb4") != 0) | |
204 { | |
205 LOG(ERROR) << "Cannot set the character set to UTF8"; | |
206 Close(); | |
207 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database); | |
208 } | |
16
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
209 } |
0 | 210 |
23
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
211 |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
212 void MySQLDatabase::Open() |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
213 { |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
214 if (parameters_.GetDatabase().empty()) |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
215 { |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
216 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
217 } |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
218 else |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
219 { |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
220 OpenInternal(parameters_.GetDatabase().c_str()); |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
221 } |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
222 } |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
223 |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
224 |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
225 void MySQLDatabase::ClearDatabase(const MySQLParameters& parameters) |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
226 { |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
227 MySQLDatabase db(parameters); |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
228 db.OpenRoot(); |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
229 |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
230 const std::string& database = parameters.GetDatabase(); |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
231 |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
232 { |
217
ee5858d438dc
TransactionType given to MySQLTransaction constructor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
215
diff
changeset
|
233 MySQLTransaction t(db, TransactionType_ReadWrite); |
23
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
234 |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
235 if (!db.DoesDatabaseExist(t, database)) |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
236 { |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
237 LOG(ERROR) << "Inexistent database, please create it first: " << database; |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
238 throw Orthanc::OrthancException(Orthanc::ErrorCode_UnknownResource); |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
239 } |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
240 |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
236
diff
changeset
|
241 db.ExecuteMultiLines("DROP DATABASE " + database, false); |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
236
diff
changeset
|
242 db.ExecuteMultiLines("CREATE DATABASE " + database, false); |
23
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
243 t.Commit(); |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
244 } |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
245 } |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
246 |
0 | 247 |
16
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
248 namespace |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
249 { |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
250 class ResultWrapper : public boost::noncopyable |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
251 { |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
252 private: |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
253 MYSQL_RES *result_; |
0 | 254 |
16
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
255 public: |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
256 ResultWrapper(MySQLDatabase& mysql, |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
257 const std::string& sql) : |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
258 result_(NULL) |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
259 { |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
260 if (mysql_real_query(mysql.GetObject(), sql.c_str(), sql.size())) |
0 | 261 { |
16
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
262 mysql.LogError(); |
0 | 263 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database); |
264 } | |
265 | |
16
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
266 result_ = mysql_use_result(mysql.GetObject()); |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
267 if (result_ == NULL) |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
268 { |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
269 mysql.LogError(); |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
270 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database); |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
271 } |
0 | 272 } |
16
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
273 |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
274 ~ResultWrapper() |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
275 { |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
276 if (result_ != NULL) |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
277 { |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
278 mysql_free_result(result_); |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
279 result_ = NULL; |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
280 } |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
281 } |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
282 |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
283 MYSQL_RES *GetObject() |
0 | 284 { |
16
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
285 return result_; |
0 | 286 } |
16
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
287 }; |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
288 } |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
289 |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
290 |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
291 bool MySQLDatabase::LookupGlobalStringVariable(std::string& value, |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
292 const std::string& variable) |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
293 { |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
294 ResultWrapper result(*this, "SELECT @@global." + variable); |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
295 |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
296 MYSQL_ROW row = mysql_fetch_row(result.GetObject()); |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
297 if (mysql_errno(mysql_) == 0 && |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
298 row && |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
299 row[0]) |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
300 { |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
301 value = std::string(row[0]); |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
302 return true; |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
303 } |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
304 else |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
305 { |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
306 return false; |
0 | 307 } |
308 } | |
309 | |
310 | |
16
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
311 bool MySQLDatabase::LookupGlobalIntegerVariable(int64_t& value, |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
312 const std::string& variable) |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
313 { |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
314 std::string s; |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
315 |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
316 if (LookupGlobalStringVariable(s, variable)) |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
317 { |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
318 try |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
319 { |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
320 value = boost::lexical_cast<int64_t>(s); |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
321 return true; |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
322 } |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
323 catch (boost::bad_lexical_cast&) |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
324 { |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
325 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database); |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
326 } |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
327 } |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
328 else |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
329 { |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
330 return false; |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
331 } |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
332 } |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
333 |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
334 |
137
52b3859ee0b7
MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
335 bool MySQLDatabase::RunAdvisoryLockStatement(Query& query, |
52b3859ee0b7
MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
336 const std::string& lock) |
135
e26690365c25
MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
337 { |
137
52b3859ee0b7
MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
338 const std::string& dbName = parameters_.GetDatabase(); |
52b3859ee0b7
MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
339 |
52b3859ee0b7
MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
340 // Prepend the name of the lock by the database name. This allows |
52b3859ee0b7
MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
341 // to create a namespace for advisory locks: |
52b3859ee0b7
MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
342 // https://groups.google.com/d/msg/orthanc-users/yV3LSTh_TjI/MQIcvnMlAQAJ |
52b3859ee0b7
MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
343 std::string prefix; |
52b3859ee0b7
MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
344 prefix.reserve(dbName.size()); |
52b3859ee0b7
MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
345 for (size_t i = 0; i < dbName.size(); i++) |
52b3859ee0b7
MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
346 { |
52b3859ee0b7
MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
347 if (isalnum(dbName[i]) || |
52b3859ee0b7
MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
348 dbName[i] == '$' || |
52b3859ee0b7
MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
349 dbName[i] == '_') |
52b3859ee0b7
MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
350 { |
52b3859ee0b7
MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
351 prefix.push_back(dbName[i]); |
52b3859ee0b7
MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
352 } |
52b3859ee0b7
MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
353 } |
52b3859ee0b7
MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
354 |
52b3859ee0b7
MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
355 query.SetType("lock", ValueType_Utf8String); |
52b3859ee0b7
MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
356 |
135
e26690365c25
MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
357 Dictionary args; |
137
52b3859ee0b7
MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
358 args.SetUtf8Value("lock", prefix + "." + lock); |
135
e26690365c25
MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
359 |
137
52b3859ee0b7
MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
360 bool success; |
135
e26690365c25
MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
361 |
137
52b3859ee0b7
MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
362 { |
186 | 363 MySQLStatement statement(*this, query); |
364 | |
217
ee5858d438dc
TransactionType given to MySQLTransaction constructor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
215
diff
changeset
|
365 MySQLTransaction t(*this, TransactionType_ReadWrite); |
157
275e14f57f1e
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
366 std::unique_ptr<IResult> result(t.Execute(statement, args)); |
135
e26690365c25
MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
367 |
137
52b3859ee0b7
MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
368 success = (!result->IsDone() && |
52b3859ee0b7
MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
369 result->GetField(0).GetType() == ValueType_Integer64 && |
52b3859ee0b7
MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
370 dynamic_cast<const Integer64Value&>(result->GetField(0)).GetValue() == 1); |
52b3859ee0b7
MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
371 |
52b3859ee0b7
MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
372 t.Commit(); |
52b3859ee0b7
MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
373 } |
135
e26690365c25
MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
374 |
e26690365c25
MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
375 return success; |
e26690365c25
MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
376 } |
e26690365c25
MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
377 |
e26690365c25
MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
378 |
137
52b3859ee0b7
MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
379 bool MySQLDatabase::AcquireAdvisoryLock(const std::string& lock) |
135
e26690365c25
MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
380 { |
137
52b3859ee0b7
MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
381 Query query("SELECT GET_LOCK(${lock}, 0)", false); |
52b3859ee0b7
MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
382 return RunAdvisoryLockStatement(query, lock); |
135
e26690365c25
MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
383 } |
e26690365c25
MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
384 |
e26690365c25
MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
385 |
137
52b3859ee0b7
MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
386 bool MySQLDatabase::ReleaseAdvisoryLock(const std::string& lock) |
135
e26690365c25
MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
387 { |
137
52b3859ee0b7
MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
388 Query query("SELECT RELEASE_LOCK(${lock})", false); |
52b3859ee0b7
MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
389 return RunAdvisoryLockStatement(query, lock); |
135
e26690365c25
MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
390 } |
e26690365c25
MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
391 |
e26690365c25
MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
392 |
137
52b3859ee0b7
MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
393 void MySQLDatabase::AdvisoryLock(const std::string& lock) |
16
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
394 { |
135
e26690365c25
MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
395 if (!AcquireAdvisoryLock(lock)) |
16
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
396 { |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
397 LOG(ERROR) << "The MySQL database is locked by another instance of Orthanc"; |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
398 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database); |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
399 } |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
400 } |
22
1e9bad493475
prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
401 |
1e9bad493475
prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
402 |
0 | 403 bool MySQLDatabase::DoesTableExist(MySQLTransaction& transaction, |
404 const std::string& name) | |
405 { | |
406 if (mysql_ == NULL) | |
407 { | |
408 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
409 } | |
410 | |
60
412e30336847
allowing dollars and underscores in MySQL database identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
46
diff
changeset
|
411 if (!IsValidDatabaseIdentifier(name)) |
24
17f849b2af34
sharing plugin initialization code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
412 { |
17f849b2af34
sharing plugin initialization code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
413 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
17f849b2af34
sharing plugin initialization code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
414 } |
22
1e9bad493475
prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
415 |
0 | 416 Query query("SELECT COUNT(*) FROM information_schema.TABLES WHERE " |
417 "(TABLE_SCHEMA = ${database}) AND (TABLE_NAME = ${table})", true); | |
418 query.SetType("database", ValueType_Utf8String); | |
419 query.SetType("table", ValueType_Utf8String); | |
420 | |
421 MySQLStatement statement(*this, query); | |
422 | |
423 Dictionary args; | |
424 args.SetUtf8Value("database", parameters_.GetDatabase()); | |
425 args.SetUtf8Value("table", name); | |
426 | |
157
275e14f57f1e
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
427 std::unique_ptr<IResult> result(statement.Execute(transaction, args)); |
0 | 428 return (!result->IsDone() && |
429 result->GetFieldsCount() == 1 && | |
430 result->GetField(0).GetType() == ValueType_Integer64 && | |
431 dynamic_cast<const Integer64Value&>(result->GetField(0)).GetValue() == 1); | |
432 } | |
433 | |
434 | |
22
1e9bad493475
prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
435 bool MySQLDatabase::DoesDatabaseExist(MySQLTransaction& transaction, |
1e9bad493475
prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
436 const std::string& name) |
1e9bad493475
prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
437 { |
1e9bad493475
prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
438 if (mysql_ == NULL) |
1e9bad493475
prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
439 { |
1e9bad493475
prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
440 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
1e9bad493475
prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
441 } |
1e9bad493475
prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
442 |
60
412e30336847
allowing dollars and underscores in MySQL database identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
46
diff
changeset
|
443 if (!IsValidDatabaseIdentifier(name)) |
24
17f849b2af34
sharing plugin initialization code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
444 { |
17f849b2af34
sharing plugin initialization code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
445 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
17f849b2af34
sharing plugin initialization code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
446 } |
22
1e9bad493475
prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
447 |
1e9bad493475
prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
448 Query query("SELECT COUNT(*) FROM information_schema.SCHEMATA " |
1e9bad493475
prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
449 "WHERE SCHEMA_NAME = ${database}", true); |
1e9bad493475
prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
450 query.SetType("database", ValueType_Utf8String); |
1e9bad493475
prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
451 |
1e9bad493475
prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
452 MySQLStatement statement(*this, query); |
1e9bad493475
prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
453 |
1e9bad493475
prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
454 Dictionary args; |
1e9bad493475
prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
455 args.SetUtf8Value("database", name); |
1e9bad493475
prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
456 |
157
275e14f57f1e
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
457 std::unique_ptr<IResult> result(statement.Execute(transaction, args)); |
22
1e9bad493475
prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
458 return (!result->IsDone() && |
1e9bad493475
prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
459 result->GetFieldsCount() == 1 && |
1e9bad493475
prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
460 result->GetField(0).GetType() == ValueType_Integer64 && |
1e9bad493475
prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
461 dynamic_cast<const Integer64Value&>(result->GetField(0)).GetValue() == 1); |
1e9bad493475
prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
462 } |
1e9bad493475
prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
463 |
1e9bad493475
prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
464 |
144
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
465 bool MySQLDatabase::DoesTriggerExist(MySQLTransaction& transaction, |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
466 const std::string& name) |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
467 { |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
468 if (mysql_ == NULL) |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
469 { |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
470 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
471 } |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
472 |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
473 if (!IsValidDatabaseIdentifier(name)) |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
474 { |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
475 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
476 } |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
477 |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
478 Query query("SELECT COUNT(*) FROM information_schema.TRIGGERS " |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
479 "WHERE TRIGGER_NAME = ${trigger}", true); |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
480 query.SetType("trigger", ValueType_Utf8String); |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
481 |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
482 MySQLStatement statement(*this, query); |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
483 |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
484 Dictionary args; |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
485 args.SetUtf8Value("trigger", name); |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
486 |
157
275e14f57f1e
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
487 std::unique_ptr<IResult> result(statement.Execute(transaction, args)); |
144
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
488 return (!result->IsDone() && |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
489 result->GetFieldsCount() == 1 && |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
490 result->GetField(0).GetType() == ValueType_Integer64 && |
186 | 491 dynamic_cast<const Integer64Value&>(result->GetField(0)).GetValue() != 0); |
144
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
492 } |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
493 |
740d9829f52e
handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
494 |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
236
diff
changeset
|
495 void MySQLDatabase::ExecuteMultiLines(const std::string& sql, |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
236
diff
changeset
|
496 bool arobaseSeparator) |
0 | 497 { |
498 if (mysql_ == NULL) | |
499 { | |
500 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
501 } | |
502 | |
503 // This emulates the behavior of "CLIENT_MULTI_STATEMENTS" in | |
504 // "mysql_real_connect()", avoiding to implement a loop over | |
505 // "mysql_query()" | |
506 std::vector<std::string> commands; | |
507 Orthanc::Toolbox::TokenizeString(commands, sql, ';'); | |
508 | |
509 for (size_t i = 0; i < commands.size(); i++) | |
510 { | |
511 std::string s = Orthanc::Toolbox::StripSpaces(commands[i]); | |
512 | |
513 if (!s.empty()) | |
514 { | |
16
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
515 if (arobaseSeparator) |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
516 { |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
517 // Replace the escape character "@" by a semicolon |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
518 std::replace(s.begin(), s.end(), '@', ';'); |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
519 } |
0 | 520 |
521 LOG(TRACE) << "MySQL: " << s; | |
522 CheckErrorCode(mysql_query(mysql_, s.c_str())); | |
523 } | |
524 } | |
525 } | |
526 | |
527 | |
528 IPrecompiledStatement* MySQLDatabase::Compile(const Query& query) | |
529 { | |
530 if (mysql_ == NULL) | |
531 { | |
532 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
533 } | |
534 | |
535 return new MySQLStatement(*this, query); | |
536 } | |
537 | |
538 | |
23
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
539 |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
540 namespace |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
541 { |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
542 class MySQLImplicitTransaction : public ImplicitTransaction |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
543 { |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
236
diff
changeset
|
544 private: |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
236
diff
changeset
|
545 MySQLDatabase& db_; |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
236
diff
changeset
|
546 |
23
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
547 protected: |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
548 virtual IResult* ExecuteInternal(IPrecompiledStatement& statement, |
280
b8ba198a8df3
adding missing ORTHANC_OVERRIDE
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
549 const Dictionary& parameters) ORTHANC_OVERRIDE |
23
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
550 { |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
551 return dynamic_cast<MySQLStatement&>(statement).Execute(*this, parameters); |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
552 } |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
553 |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
554 virtual void ExecuteWithoutResultInternal(IPrecompiledStatement& statement, |
280
b8ba198a8df3
adding missing ORTHANC_OVERRIDE
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
555 const Dictionary& parameters) ORTHANC_OVERRIDE |
23
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
556 { |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
557 dynamic_cast<MySQLStatement&>(statement).ExecuteWithoutResult(*this, parameters); |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
558 } |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
236
diff
changeset
|
559 |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
236
diff
changeset
|
560 public: |
252 | 561 explicit MySQLImplicitTransaction(MySQLDatabase& db) : |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
236
diff
changeset
|
562 db_(db) |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
236
diff
changeset
|
563 { |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
236
diff
changeset
|
564 } |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
236
diff
changeset
|
565 |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
236
diff
changeset
|
566 virtual bool DoesTableExist(const std::string& name) ORTHANC_OVERRIDE |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
236
diff
changeset
|
567 { |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
236
diff
changeset
|
568 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError, "An explicit transaction is needed"); |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
236
diff
changeset
|
569 } |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
236
diff
changeset
|
570 |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
236
diff
changeset
|
571 virtual bool DoesTriggerExist(const std::string& name) ORTHANC_OVERRIDE |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
236
diff
changeset
|
572 { |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
236
diff
changeset
|
573 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError, "An explicit transaction is needed"); |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
236
diff
changeset
|
574 } |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
236
diff
changeset
|
575 |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
236
diff
changeset
|
576 virtual void ExecuteMultiLines(const std::string& query) ORTHANC_OVERRIDE |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
236
diff
changeset
|
577 { |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
236
diff
changeset
|
578 db_.ExecuteMultiLines(query, false /* don't deal with arobases */); |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
236
diff
changeset
|
579 } |
23
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
580 }; |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
581 } |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
582 |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
583 |
215
b40b30075c51
added TransactionType_Implicit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
584 ITransaction* MySQLDatabase::CreateTransaction(TransactionType type) |
0 | 585 { |
586 if (mysql_ == NULL) | |
587 { | |
588 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
589 } | |
590 | |
215
b40b30075c51
added TransactionType_Implicit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
591 switch (type) |
23
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
592 { |
215
b40b30075c51
added TransactionType_Implicit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
593 case TransactionType_Implicit: |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
236
diff
changeset
|
594 return new MySQLImplicitTransaction(*this); |
215
b40b30075c51
added TransactionType_Implicit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
595 |
b40b30075c51
added TransactionType_Implicit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
596 case TransactionType_ReadOnly: |
b40b30075c51
added TransactionType_Implicit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
597 case TransactionType_ReadWrite: |
217
ee5858d438dc
TransactionType given to MySQLTransaction constructor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
215
diff
changeset
|
598 return new MySQLTransaction(*this, type); |
215
b40b30075c51
added TransactionType_Implicit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
599 |
b40b30075c51
added TransactionType_Implicit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
600 default: |
b40b30075c51
added TransactionType_Implicit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
601 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
23
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
602 } |
0 | 603 } |
604 | |
605 | |
606 void MySQLDatabase::GlobalFinalization() | |
607 { | |
608 mysql_library_end(); | |
609 } | |
24
17f849b2af34
sharing plugin initialization code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
610 |
17f849b2af34
sharing plugin initialization code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
611 |
60
412e30336847
allowing dollars and underscores in MySQL database identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
46
diff
changeset
|
612 bool MySQLDatabase::IsValidDatabaseIdentifier(const std::string& s) |
24
17f849b2af34
sharing plugin initialization code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
613 { |
17f849b2af34
sharing plugin initialization code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
614 for (size_t i = 0; i < s.length(); i++) |
17f849b2af34
sharing plugin initialization code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
615 { |
60
412e30336847
allowing dollars and underscores in MySQL database identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
46
diff
changeset
|
616 // https://dev.mysql.com/doc/refman/8.0/en/identifiers.html |
412e30336847
allowing dollars and underscores in MySQL database identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
46
diff
changeset
|
617 if (!isalnum(s[i]) && |
412e30336847
allowing dollars and underscores in MySQL database identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
46
diff
changeset
|
618 s[i] != '$' && |
412e30336847
allowing dollars and underscores in MySQL database identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
46
diff
changeset
|
619 s[i] != '_') |
24
17f849b2af34
sharing plugin initialization code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
620 { |
17f849b2af34
sharing plugin initialization code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
621 return false; |
17f849b2af34
sharing plugin initialization code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
622 } |
17f849b2af34
sharing plugin initialization code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
623 } |
17f849b2af34
sharing plugin initialization code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
624 |
17f849b2af34
sharing plugin initialization code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
625 return true; |
17f849b2af34
sharing plugin initialization code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
626 } |
135
e26690365c25
MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
627 |
e26690365c25
MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
628 |
e26690365c25
MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
629 MySQLDatabase::TransientAdvisoryLock:: |
e26690365c25
MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
630 TransientAdvisoryLock(MySQLDatabase& database, |
137
52b3859ee0b7
MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
631 const std::string& lock) : |
135
e26690365c25
MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
632 database_(database), |
e26690365c25
MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
633 lock_(lock) |
e26690365c25
MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
634 { |
e26690365c25
MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
635 bool locked = true; |
e26690365c25
MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
636 |
e26690365c25
MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
637 for (unsigned int i = 0; i < 10; i++) |
e26690365c25
MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
638 { |
e26690365c25
MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
639 if (database_.AcquireAdvisoryLock(lock_)) |
e26690365c25
MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
640 { |
e26690365c25
MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
641 locked = false; |
e26690365c25
MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
642 break; |
e26690365c25
MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
643 } |
e26690365c25
MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
644 else |
e26690365c25
MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
645 { |
e26690365c25
MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
646 boost::this_thread::sleep(boost::posix_time::milliseconds(500)); |
e26690365c25
MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
647 } |
e26690365c25
MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
648 } |
e26690365c25
MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
649 |
e26690365c25
MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
650 if (locked) |
e26690365c25
MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
651 { |
e26690365c25
MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
652 LOG(ERROR) << "Cannot acquire a transient advisory lock"; |
e26690365c25
MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
653 throw Orthanc::OrthancException(Orthanc::ErrorCode_Plugin); |
e26690365c25
MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
654 } |
e26690365c25
MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
655 } |
e26690365c25
MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
656 |
e26690365c25
MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
657 |
e26690365c25
MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
658 MySQLDatabase::TransientAdvisoryLock::~TransientAdvisoryLock() |
e26690365c25
MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
659 { |
e26690365c25
MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
660 database_.ReleaseAdvisoryLock(lock_); |
e26690365c25
MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
661 } |
226
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
217
diff
changeset
|
662 |
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
217
diff
changeset
|
663 |
255
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
664 class MySQLDatabase::Factory : public RetryDatabaseFactory |
226
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
217
diff
changeset
|
665 { |
255
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
666 private: |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
667 MySQLParameters parameters_; |
226
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
217
diff
changeset
|
668 |
255
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
669 protected: |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
670 virtual IDatabase* TryOpen() |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
671 { |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
672 std::unique_ptr<MySQLDatabase> db(new MySQLDatabase(parameters_)); |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
673 db->Open(); |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
674 db->ExecuteMultiLines("SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE", false); |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
675 return db.release(); |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
676 } |
226
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
217
diff
changeset
|
677 |
255
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
678 public: |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
679 explicit Factory(const MySQLParameters& parameters) : |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
680 RetryDatabaseFactory(parameters.GetMaxConnectionRetries(), |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
681 parameters.GetConnectionRetryInterval()), |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
682 parameters_(parameters) |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
683 { |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
684 } |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
685 }; |
226
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
217
diff
changeset
|
686 |
255
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
687 |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
688 IDatabaseFactory* MySQLDatabase::CreateDatabaseFactory(const MySQLParameters& parameters) |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
689 { |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
690 return new Factory(parameters); |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
691 } |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
692 |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
693 |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
694 MySQLDatabase* MySQLDatabase::CreateDatabaseConnection(const MySQLParameters& parameters) |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
695 { |
226
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
217
diff
changeset
|
696 Factory factory(parameters); |
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
217
diff
changeset
|
697 return dynamic_cast<MySQLDatabase*>(factory.Open()); |
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
217
diff
changeset
|
698 } |
0 | 699 } |