annotate MySQL/Plugins/MySQLStorageArea.cpp @ 263:29d2b76516f6

fix mysql and postgresql builds
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 20 Apr 2021 15:08:09 +0200
parents d663d9e44f8d
children 567761f0c1ea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
17
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * the License, or (at your option) any later version.
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * Affero General Public License for more details.
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 *
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 **/
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 #include "MySQLStorageArea.h"
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
242
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
24 #include "../../Framework/Common/BinaryStringValue.h"
17
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 #include "../../Framework/MySQL/MySQLDatabase.h"
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #include "../../Framework/MySQL/MySQLTransaction.h"
137
52b3859ee0b7 MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
27 #include "MySQLDefinitions.h"
17
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28
157
275e14f57f1e replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 152
diff changeset
29 #include <Compatibility.h> // For std::unique_ptr<>
152
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
30 #include <Logging.h>
17
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 #include <boost/math/special_functions/round.hpp>
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 namespace OrthancDatabases
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 {
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 217
diff changeset
37 void MySQLStorageArea::ConfigureDatabase(MySQLDatabase& db,
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 217
diff changeset
38 const MySQLParameters& parameters,
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 217
diff changeset
39 bool clearAll)
17
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 {
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 {
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 217
diff changeset
42 MySQLDatabase::TransientAdvisoryLock lock(db, MYSQL_LOCK_DATABASE_SETUP);
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 217
diff changeset
43 MySQLTransaction t(db, TransactionType_ReadWrite);
17
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 int64_t size;
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 217
diff changeset
46 if (db.LookupGlobalIntegerVariable(size, "max_allowed_packet"))
17
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 {
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 int mb = boost::math::iround(static_cast<double>(size) /
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 static_cast<double>(1024 * 1024));
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 LOG(WARNING) << "Your MySQL server cannot "
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 << "store DICOM files larger than " << mb << "MB";
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 LOG(WARNING) << " => Consider increasing \"max_allowed_packet\" "
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 << "in \"my.cnf\" if this limit is insufficient for your use";
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 }
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 else
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 {
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 LOG(WARNING) << "Unable to auto-detect the maximum size of DICOM "
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 << "files that can be stored in this MySQL server";
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 }
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 217
diff changeset
61 if (clearAll)
17
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 {
237
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
63 db.ExecuteMultiLines("DROP TABLE IF EXISTS StorageArea", false);
17
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 }
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65
237
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
66 db.ExecuteMultiLines("CREATE TABLE IF NOT EXISTS StorageArea("
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
67 "uuid VARCHAR(64) NOT NULL PRIMARY KEY,"
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
68 "content LONGBLOB NOT NULL,"
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
69 "type INTEGER NOT NULL)", false);
17
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 t.Commit();
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 }
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73
137
52b3859ee0b7 MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
74 /**
52b3859ee0b7 MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
75 * WARNING: This lock must be acquired after
52b3859ee0b7 MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
76 * "MYSQL_LOCK_DATABASE_SETUP" is released. Indeed, in MySQL <
52b3859ee0b7 MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
77 * 5.7, it is impossible to acquire more than one lock at a time,
52b3859ee0b7 MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
78 * as calling "SELECT GET_LOCK()" releases all the
52b3859ee0b7 MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
79 * previously-acquired locks.
52b3859ee0b7 MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
80 * https://dev.mysql.com/doc/refman/5.7/en/locking-functions.html
52b3859ee0b7 MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
81 **/
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 217
diff changeset
82 if (parameters.HasLock())
137
52b3859ee0b7 MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
83 {
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 217
diff changeset
84 db.AdvisoryLock(MYSQL_LOCK_STORAGE);
137
52b3859ee0b7 MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
85 }
17
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 }
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 217
diff changeset
89 MySQLStorageArea::MySQLStorageArea(const MySQLParameters& parameters,
255
d663d9e44f8d reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
90 bool clearAll) :
d663d9e44f8d reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
91 StorageBackend(MySQLDatabase::CreateDatabaseFactory(parameters))
17
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 {
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 217
diff changeset
93 {
255
d663d9e44f8d reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
94 AccessorBase accessor(*this);
d663d9e44f8d reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
95 MySQLDatabase& database = dynamic_cast<MySQLDatabase&>(accessor.GetManager().GetDatabase());
d663d9e44f8d reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
96 ConfigureDatabase(database, parameters, clearAll);
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 217
diff changeset
97 }
17
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 }
242
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
99
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
100
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
101 class MySQLStorageArea::Accessor : public StorageBackend::AccessorBase
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
102 {
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
103 public:
252
33fa478c119a cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 250
diff changeset
104 explicit Accessor(MySQLStorageArea& backend) :
242
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
105 AccessorBase(backend)
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
106 {
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
107 }
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
108
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
109 virtual void ReadRange(IFileContentVisitor& visitor,
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
110 const std::string& uuid,
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
111 OrthancPluginContentType type,
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
112 uint64_t start,
250
29ac6f4a0f45 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 242
diff changeset
113 size_t length) ORTHANC_OVERRIDE
242
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
114 {
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
115 DatabaseManager::Transaction transaction(GetManager(), TransactionType_ReadOnly);
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
116
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
117 {
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
118 // https://stackoverflow.com/a/6545557/881731
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
119 DatabaseManager::CachedStatement statement(
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
120 STATEMENT_FROM_HERE, GetManager(),
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
121 "SELECT SUBSTRING(content, ${start}, ${length}) FROM StorageArea WHERE uuid=${uuid} AND type=${type}");
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
122
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
123 statement.SetParameterType("uuid", ValueType_Utf8String);
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
124 statement.SetParameterType("type", ValueType_Integer64);
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
125 statement.SetParameterType("start", ValueType_Integer64);
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
126 statement.SetParameterType("length", ValueType_Integer64);
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
127
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
128 Dictionary args;
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
129 args.SetUtf8Value("uuid", uuid);
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
130 args.SetIntegerValue("type", type);
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
131 args.SetIntegerValue("length", length);
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
132
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
133 /**
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
134 * "For all forms of SUBSTRING(), the position of the first
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
135 * character in the string from which the substring is to be
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
136 * extracted is reckoned as 1." => hence the "+ 1"
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
137 * https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_substring
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
138 **/
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
139 args.SetIntegerValue("start", start + 1);
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
140
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
141 statement.Execute(args);
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
142
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
143 if (statement.IsDone())
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
144 {
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
145 throw Orthanc::OrthancException(Orthanc::ErrorCode_UnknownResource);
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
146 }
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
147 else if (statement.GetResultFieldsCount() != 1)
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
148 {
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
149 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database);
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
150 }
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
151 else
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
152 {
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
153 const IValue& value = statement.GetResultField(0);
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
154
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
155 if (value.GetType() == ValueType_BinaryString)
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
156 {
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
157 const std::string& content = dynamic_cast<const BinaryStringValue&>(value).GetContent();
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
158
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
159 if (static_cast<uint64_t>(content.size()) == length)
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
160 {
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
161 visitor.Assign(content);
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
162 }
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
163 else
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
164 {
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
165 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadRange);
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
166 }
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
167 }
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
168 else
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
169 {
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
170 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database);
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
171 }
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
172 }
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
173 }
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
174
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
175 transaction.Commit();
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
176
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
177 if (!visitor.IsSuccess())
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
178 {
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
179 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database, "Could not read range from the storage area");
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
180 }
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
181 }
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
182 };
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
183
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
184
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
185 StorageBackend::IAccessor* MySQLStorageArea::CreateAccessor()
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
186 {
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
187 return new Accessor(*this);
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
188 }
17
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 }