comparison Framework/Common/DatabaseManager.h @ 569:f18e46d7dbf8 attach-custom-data

merged find-refactoring -> attach-custom-data
author Alain Mazy <am@orthanc.team>
date Tue, 24 Sep 2024 15:04:21 +0200
parents 2ab3d45c0b3c
children
comparison
equal deleted inserted replaced
368:82f73188b58d 569:f18e46d7dbf8
1 /** 1 /**
2 * Orthanc - A Lightweight, RESTful DICOM Store 2 * Orthanc - A Lightweight, RESTful DICOM Store
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
4 * Department, University Hospital of Liege, Belgium 4 * Department, University Hospital of Liege, Belgium
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium 5 * Copyright (C) 2017-2023 Osimis S.A., Belgium
6 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium
7 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
6 * 8 *
7 * This program is free software: you can redistribute it and/or 9 * This program is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU Affero General Public License 10 * modify it under the terms of the GNU Affero General Public License
9 * as published by the Free Software Foundation, either version 3 of 11 * as published by the Free Software Foundation, either version 3 of
10 * the License, or (at your option) any later version. 12 * the License, or (at your option) any later version.
20 22
21 23
22 #pragma once 24 #pragma once
23 25
24 #include "IDatabaseFactory.h" 26 #include "IDatabaseFactory.h"
25 #include "StatementLocation.h" 27 #include "StatementId.h"
26 28
27 #include <Compatibility.h> // For std::unique_ptr<> 29 #include <Compatibility.h> // For std::unique_ptr<>
28 #include <Enumerations.h> 30 #include <Enumerations.h>
29 31
30 #include <memory> 32 #include <memory>
45 * the latter gets lost. 47 * the latter gets lost.
46 **/ 48 **/
47 class DatabaseManager : public boost::noncopyable 49 class DatabaseManager : public boost::noncopyable
48 { 50 {
49 private: 51 private:
50 typedef std::map<StatementLocation, IPrecompiledStatement*> CachedStatements; 52 typedef std::map<StatementId, IPrecompiledStatement*> CachedStatements;
51 53
52 std::unique_ptr<IDatabaseFactory> factory_; 54 std::unique_ptr<IDatabaseFactory> factory_;
53 std::unique_ptr<IDatabase> database_; 55 std::unique_ptr<IDatabase> database_;
54 std::unique_ptr<ITransaction> transaction_; 56 std::unique_ptr<ITransaction> transaction_;
55 CachedStatements cachedStatements_; 57 CachedStatements cachedStatements_;
56 Dialect dialect_; 58 Dialect dialect_;
57 59
58 void CloseIfUnavailable(Orthanc::ErrorCode e); 60 void CloseIfUnavailable(Orthanc::ErrorCode e);
59 61
60 IPrecompiledStatement* LookupCachedStatement(const StatementLocation& location) const; 62 IPrecompiledStatement* LookupCachedStatement(const StatementId& statementId) const;
61 63
62 IPrecompiledStatement& CacheStatement(const StatementLocation& location, 64 IPrecompiledStatement& CacheStatement(const StatementId& statementId,
63 const Query& query); 65 const Query& query);
64 66
65 ITransaction& GetTransaction(); 67 ITransaction& GetTransaction();
66 68
67 void ReleaseImplicitTransaction(); 69 void ReleaseImplicitTransaction();
183 int32_t ReadInteger32(size_t field) const; 185 int32_t ReadInteger32(size_t field) const;
184 186
185 int64_t ReadInteger64(size_t field) const; 187 int64_t ReadInteger64(size_t field) const;
186 188
187 std::string ReadString(size_t field) const; 189 std::string ReadString(size_t field) const;
190
191 std::string ReadStringOrNull(size_t field) const;
192
193 bool IsNull(size_t field) const;
188 194
189 void PrintResult(std::ostream& stream) 195 void PrintResult(std::ostream& stream)
190 { 196 {
191 IResult::Print(stream, GetResult()); 197 IResult::Print(stream, GetResult());
192 } 198 }
201 * present. 207 * present.
202 **/ 208 **/
203 class CachedStatement : public StatementBase 209 class CachedStatement : public StatementBase
204 { 210 {
205 private: 211 private:
206 StatementLocation location_; 212 StatementId statementId_;
207 IPrecompiledStatement* statement_; 213 IPrecompiledStatement* statement_;
208 214
209 public: 215 public:
210 CachedStatement(const StatementLocation& location, 216 CachedStatement(const StatementId& statementId,
211 DatabaseManager& manager, 217 DatabaseManager& manager,
212 const std::string& sql); 218 const std::string& sql);
213 219
214 void Execute() 220 void Execute()
215 { 221 {
216 Dictionary parameters; 222 Dictionary parameters;
217 Execute(parameters); 223 Execute(parameters);
218 } 224 }
219 225
220 void Execute(const Dictionary& parameters); 226 void Execute(const Dictionary& parameters);
227
228 void ExecuteWithoutResult()
229 {
230 Dictionary parameters;
231 ExecuteWithoutResult(parameters);
232 }
233
234 void ExecuteWithoutResult(const Dictionary& parameters);
235
236 private:
237 void ExecuteInternal(const Dictionary& parameters, bool withResults);
221 }; 238 };
222 239
223 240
224 class StandaloneStatement : public StatementBase 241 class StandaloneStatement : public StatementBase
225 { 242 {
237 Dictionary parameters; 254 Dictionary parameters;
238 Execute(parameters); 255 Execute(parameters);
239 } 256 }
240 257
241 void Execute(const Dictionary& parameters); 258 void Execute(const Dictionary& parameters);
259
260 void ExecuteWithoutResult()
261 {
262 Dictionary parameters;
263 ExecuteWithoutResult(parameters);
264 }
265
266 void ExecuteWithoutResult(const Dictionary& parameters);
267
268 private:
269 void ExecuteInternal(const Dictionary& parameters, bool withResults);
242 }; 270 };
243 }; 271 };
244 } 272 }