annotate Framework/MySQL/MySQLDatabase.h @ 583:ae7375d38607 find-refactoring tip

MySQL: fix ordering
author Alain Mazy <am@orthanc.team>
date Mon, 21 Oct 2024 18:19:51 +0200
parents 54d518dcd74a
children
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: 459
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: 459
diff changeset
6 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium
459
ecd0b719cff5 update year to 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 389
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 #pragma once
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 #if ORTHANC_ENABLE_MYSQL != 1
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 # error MySQL support must be enabled to use this file
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 #endif
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29
255
d663d9e44f8d reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 240
diff changeset
30 #include "../Common/IDatabaseFactory.h"
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 #include "MySQLParameters.h"
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 #include <mysql.h>
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 namespace OrthancDatabases
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 class MySQLTransaction;
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 class MySQLDatabase : public IDatabase
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 private:
255
d663d9e44f8d reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 240
diff changeset
42 class Factory;
d663d9e44f8d reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 240
diff changeset
43
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 MySQLParameters parameters_;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 MYSQL *mysql_;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46
23
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
47 void OpenInternal(const char* database);
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
48
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 void Close();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50
137
52b3859ee0b7 MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
51 bool RunAdvisoryLockStatement(Query& query,
52b3859ee0b7 MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
52 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
53
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 public:
186
6fe74f9a516e cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
55 explicit MySQLDatabase(const MySQLParameters& parameters);
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56
46
6a574d810b98 Compatibility with MySQL 8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
57 virtual ~MySQLDatabase();
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 void LogError();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 void CheckErrorCode(int code);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62
240
c82c2cf84ae8 added handling of CR_COMMANDS_OUT_OF_SYNC
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
63 void ThrowException();
c82c2cf84ae8 added handling of CR_COMMANDS_OUT_OF_SYNC
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
64
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 MYSQL* GetObject();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 void Open();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68
23
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
69 void OpenRoot()
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
70 {
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
71 OpenInternal(NULL);
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
72 }
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
73
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
74 static void ClearDatabase(const MySQLParameters& parameters);
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
75
16
9e419261f1c9 mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
76 bool LookupGlobalStringVariable(std::string& value,
9e419261f1c9 mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
77 const std::string& variable);
9e419261f1c9 mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
78
9e419261f1c9 mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
79 bool LookupGlobalIntegerVariable(int64_t& value,
9e419261f1c9 mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
80 const std::string& variable);
9e419261f1c9 mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
81
137
52b3859ee0b7 MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
82 bool 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
83
137
52b3859ee0b7 MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
84 bool 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
85
137
52b3859ee0b7 MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
86 void AdvisoryLock(const std::string& lock);
16
9e419261f1c9 mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
87
237
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
88 void ExecuteMultiLines(const std::string& sql,
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
89 bool arobaseSeparator);
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 bool DoesTableExist(MySQLTransaction& transaction,
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 const std::string& name);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93
22
1e9bad493475 prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
94 bool DoesDatabaseExist(MySQLTransaction& transaction,
1e9bad493475 prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
95 const std::string& name);
1e9bad493475 prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
96
144
740d9829f52e handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
97 bool DoesTriggerExist(MySQLTransaction& transaction,
740d9829f52e handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
98 const std::string& name);
740d9829f52e handling of errors if MySQL user cannot CREATE TRIGGER
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
99
186
6fe74f9a516e cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
100 virtual Dialect GetDialect() const ORTHANC_OVERRIDE
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 return Dialect_MySQL;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104
186
6fe74f9a516e cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 144
diff changeset
105 virtual IPrecompiledStatement* Compile(const Query& query) ORTHANC_OVERRIDE;
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106
215
b40b30075c51 added TransactionType_Implicit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
107 virtual ITransaction* CreateTransaction(TransactionType type) ORTHANC_OVERRIDE;
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 static void GlobalFinalization();
24
17f849b2af34 sharing plugin initialization code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 23
diff changeset
110
60
412e30336847 allowing dollars and underscores in MySQL database identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 46
diff changeset
111 static bool IsValidDatabaseIdentifier(const std::string& s);
135
e26690365c25 MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
112
e26690365c25 MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
113 class TransientAdvisoryLock
e26690365c25 MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
114 {
e26690365c25 MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
115 private:
e26690365c25 MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
116 MySQLDatabase& database_;
137
52b3859ee0b7 MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
117 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
118
e26690365c25 MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
119 public:
e26690365c25 MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
120 TransientAdvisoryLock(MySQLDatabase& database,
137
52b3859ee0b7 MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
121 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
122
e26690365c25 MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
123 ~TransientAdvisoryLock();
e26690365c25 MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
124 };
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
125
255
d663d9e44f8d reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 240
diff changeset
126 static IDatabaseFactory* CreateDatabaseFactory(const MySQLParameters& parameters);
d663d9e44f8d reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 240
diff changeset
127
d663d9e44f8d reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 240
diff changeset
128 static MySQLDatabase* CreateDatabaseConnection(const MySQLParameters& parameters);
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 };
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 }