Mercurial > hg > orthanc-databases
annotate Framework/Common/DatabaseManager.h @ 336:c0c12b3974b2
fix URLs to the old repositories
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 11 Aug 2021 11:48:52 +0200 |
parents | 6a668f5d1069 |
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:
157
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 #pragma once | |
23 | |
255
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
254
diff
changeset
|
24 #include "IDatabaseFactory.h" |
0 | 25 #include "StatementLocation.h" |
26 | |
157
275e14f57f1e
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
27 #include <Compatibility.h> // For std::unique_ptr<> |
152 | 28 #include <Enumerations.h> |
0 | 29 |
30 #include <memory> | |
31 | |
221
73cc85f3d9c1
implementation of the "serverIdentifier" information for global properties
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
207
diff
changeset
|
32 |
0 | 33 namespace OrthancDatabases |
34 { | |
231
0a9b48d19643
removed mutex out of DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
35 /** |
0a9b48d19643
removed mutex out of DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
36 * WARNING: In PostgreSQL releases <= 3.3 and in MySQL releases <= |
0a9b48d19643
removed mutex out of DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
37 * 3.0, this class was protected by a mutex. It is now assumed that |
0a9b48d19643
removed mutex out of DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
38 * locking must be implemented at a higher level. |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
39 * |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
40 * This class maintains a list of precompiled statements. At any |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
41 * time, this class handles 0 or 1 active transaction. |
255
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
254
diff
changeset
|
42 * |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
254
diff
changeset
|
43 * "DatabaseManager" takes a "IDatabaseFactory" as input, in order |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
254
diff
changeset
|
44 * to be able to automatically re-open the database connection if |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
254
diff
changeset
|
45 * the latter gets lost. |
231
0a9b48d19643
removed mutex out of DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
46 **/ |
0 | 47 class DatabaseManager : public boost::noncopyable |
48 { | |
49 private: | |
50 typedef std::map<StatementLocation, IPrecompiledStatement*> CachedStatements; | |
51 | |
255
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
254
diff
changeset
|
52 std::unique_ptr<IDatabaseFactory> factory_; |
226
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
53 std::unique_ptr<IDatabase> database_; |
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
54 std::unique_ptr<ITransaction> transaction_; |
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
55 CachedStatements cachedStatements_; |
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
56 Dialect dialect_; |
0 | 57 |
58 void CloseIfUnavailable(Orthanc::ErrorCode e); | |
59 | |
60 IPrecompiledStatement* LookupCachedStatement(const StatementLocation& location) const; | |
61 | |
62 IPrecompiledStatement& CacheStatement(const StatementLocation& location, | |
63 const Query& query); | |
64 | |
65 ITransaction& GetTransaction(); | |
14
9774802fd05f
PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
12
diff
changeset
|
66 |
23
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
67 void ReleaseImplicitTransaction(); |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
68 |
0 | 69 public: |
255
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
254
diff
changeset
|
70 explicit DatabaseManager(IDatabaseFactory* factory); // Takes ownership |
0 | 71 |
72 ~DatabaseManager() | |
73 { | |
74 Close(); | |
75 } | |
76 | |
254
8a4ce70f456a
fix crash if connection to server is lost
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
241
diff
changeset
|
77 IDatabase& GetDatabase(); |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
78 |
255
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
254
diff
changeset
|
79 Dialect GetDialect() const; |
0 | 80 |
81 void Close(); | |
82 | |
207
d9ef3f16e6a2
wrapping transactions in API v3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
83 void StartTransaction(TransactionType type); |
0 | 84 |
85 void CommitTransaction(); | |
86 | |
87 void RollbackTransaction(); | |
88 | |
12
41543239072d
transactions for storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
89 |
241
a063bbf10a3e
simplification of class DatabaseManager::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
90 // This class is only used in the "StorageBackend" and in |
a063bbf10a3e
simplification of class DatabaseManager::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
91 // "IDatabaseBackend::ConfigureDatabase()" |
12
41543239072d
transactions for storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
92 class Transaction : public boost::noncopyable |
41543239072d
transactions for storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
93 { |
41543239072d
transactions for storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
94 private: |
231
0a9b48d19643
removed mutex out of DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
95 DatabaseManager& manager_; |
0a9b48d19643
removed mutex out of DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
96 IDatabase& database_; |
241
a063bbf10a3e
simplification of class DatabaseManager::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
97 bool active_; |
12
41543239072d
transactions for storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
98 |
41543239072d
transactions for storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
99 public: |
207
d9ef3f16e6a2
wrapping transactions in API v3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
100 explicit Transaction(DatabaseManager& manager, |
d9ef3f16e6a2
wrapping transactions in API v3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
101 TransactionType type); |
12
41543239072d
transactions for storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
102 |
23
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
103 ~Transaction(); |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
104 |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
105 void Commit(); |
12
41543239072d
transactions for storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
106 |
241
a063bbf10a3e
simplification of class DatabaseManager::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
107 void Rollback(); |
12
41543239072d
transactions for storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
108 |
241
a063bbf10a3e
simplification of class DatabaseManager::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
109 /** |
a063bbf10a3e
simplification of class DatabaseManager::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
110 * WARNING: Don't call "GetDatabaseTransaction().Commit()" and |
a063bbf10a3e
simplification of class DatabaseManager::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
111 * "GetDatabaseTransaction().Rollback()", but use the "Commit()" |
a063bbf10a3e
simplification of class DatabaseManager::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
112 * and "Rollback()" methods above. |
a063bbf10a3e
simplification of class DatabaseManager::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
113 **/ |
a063bbf10a3e
simplification of class DatabaseManager::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
114 ITransaction& GetDatabaseTransaction() |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
115 { |
241
a063bbf10a3e
simplification of class DatabaseManager::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
116 return manager_.GetTransaction(); |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
117 } |
12
41543239072d
transactions for storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
118 }; |
41543239072d
transactions for storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
119 |
41543239072d
transactions for storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
120 |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
121 class StatementBase : public boost::noncopyable |
0 | 122 { |
123 private: | |
231
0a9b48d19643
removed mutex out of DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
124 DatabaseManager& manager_; |
0a9b48d19643
removed mutex out of DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
125 ITransaction& transaction_; |
0a9b48d19643
removed mutex out of DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
126 std::unique_ptr<Query> query_; |
0a9b48d19643
removed mutex out of DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
127 std::unique_ptr<IResult> result_; |
0 | 128 |
129 IResult& GetResult() const; | |
130 | |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
131 protected: |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
132 DatabaseManager& GetManager() const |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
133 { |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
134 return manager_; |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
135 } |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
136 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
137 ITransaction& GetTransaction() const |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
138 { |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
139 return transaction_; |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
140 } |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
141 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
142 void SetQuery(Query* query); |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
143 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
144 void SetResult(IResult* result); |
0 | 145 |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
146 void ClearResult() |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
147 { |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
148 result_.reset(); |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
149 } |
12
41543239072d
transactions for storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
150 |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
151 Query* ReleaseQuery() |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
152 { |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
153 return query_.release(); |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
154 } |
23
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
155 |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
156 public: |
96 | 157 explicit StatementBase(DatabaseManager& manager); |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
158 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
159 virtual ~StatementBase(); |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
160 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
161 // Used only by SQLite |
18 | 162 IDatabase& GetDatabase() |
163 { | |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
164 return manager_.GetDatabase(); |
18 | 165 } |
166 | |
0 | 167 void SetReadOnly(bool readOnly); |
168 | |
169 void SetParameterType(const std::string& parameter, | |
170 ValueType type); | |
171 | |
172 bool IsDone() const; | |
173 | |
174 void Next(); | |
175 | |
176 size_t GetResultFieldsCount() const; | |
177 | |
178 void SetResultFieldType(size_t field, | |
179 ValueType type); | |
180 | |
181 const IValue& GetResultField(size_t index) const; | |
263
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
182 |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
183 int32_t ReadInteger32(size_t field) const; |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
184 |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
185 int64_t ReadInteger64(size_t field) const; |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
186 |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
187 std::string ReadString(size_t field) const; |
307
8de3a1ecac11
MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
188 |
8de3a1ecac11
MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
189 void PrintResult(std::ostream& stream) |
8de3a1ecac11
MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
190 { |
8de3a1ecac11
MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
191 IResult::Print(stream, GetResult()); |
8de3a1ecac11
MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
192 } |
0 | 193 }; |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
194 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
195 |
308
6a668f5d1069
added warning comment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
307
diff
changeset
|
196 /** |
6a668f5d1069
added warning comment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
307
diff
changeset
|
197 * WARNING: At any given time, there must be at most 1 object of |
6a668f5d1069
added warning comment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
307
diff
changeset
|
198 * the "CachedStatement" class in the scope, otherwise error |
6a668f5d1069
added warning comment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
307
diff
changeset
|
199 * "Cannot execute more than one statement in an implicit |
6a668f5d1069
added warning comment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
307
diff
changeset
|
200 * transaction" is generated if no explicit transaction is |
6a668f5d1069
added warning comment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
307
diff
changeset
|
201 * present. |
6a668f5d1069
added warning comment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
307
diff
changeset
|
202 **/ |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
203 class CachedStatement : public StatementBase |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
204 { |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
205 private: |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
206 StatementLocation location_; |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
207 IPrecompiledStatement* statement_; |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
208 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
209 public: |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
210 CachedStatement(const StatementLocation& location, |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
211 DatabaseManager& manager, |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
212 const std::string& sql); |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
213 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
214 void Execute() |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
215 { |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
216 Dictionary parameters; |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
217 Execute(parameters); |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
218 } |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
219 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
220 void Execute(const Dictionary& parameters); |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
221 }; |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
222 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
223 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
224 class StandaloneStatement : public StatementBase |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
225 { |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
226 private: |
157
275e14f57f1e
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
227 std::unique_ptr<IPrecompiledStatement> statement_; |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
228 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
229 public: |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
230 StandaloneStatement(DatabaseManager& manager, |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
231 const std::string& sql); |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
232 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
233 virtual ~StandaloneStatement(); |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
234 |
75
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
70
diff
changeset
|
235 void Execute() |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
70
diff
changeset
|
236 { |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
70
diff
changeset
|
237 Dictionary parameters; |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
70
diff
changeset
|
238 Execute(parameters); |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
70
diff
changeset
|
239 } |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
70
diff
changeset
|
240 |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
241 void Execute(const Dictionary& parameters); |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
242 }; |
0 | 243 }; |
244 } |