annotate MySQL/Plugins/MySQLStorageArea.cpp @ 252:33fa478c119a

cppcheck
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 14 Apr 2021 13:33:48 +0200
parents 29ac6f4a0f45
children d663d9e44f8d
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,
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 217
diff changeset
90 bool clearAll)
17
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 {
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 217
diff changeset
92 std::unique_ptr<MySQLDatabase> database(MySQLDatabase::OpenDatabaseConnection(parameters));
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 217
diff changeset
93
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 217
diff changeset
94 if (database.get() == NULL)
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 217
diff changeset
95 {
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 217
diff changeset
96 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 217
diff changeset
97 }
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 217
diff changeset
98
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 217
diff changeset
99 ConfigureDatabase(*database, parameters, clearAll);
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 217
diff changeset
100 SetDatabase(database.release());
17
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 }
242
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
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
104 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
105 {
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
106 public:
252
33fa478c119a cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 250
diff changeset
107 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
108 AccessorBase(backend)
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
109 {
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
110 }
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
111
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
112 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
113 const std::string& uuid,
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
114 OrthancPluginContentType type,
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
115 uint64_t start,
250
29ac6f4a0f45 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 242
diff changeset
116 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
117 {
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
118 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
119
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
120 {
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
121 // 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
122 DatabaseManager::CachedStatement statement(
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
123 STATEMENT_FROM_HERE, GetManager(),
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
124 "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
125
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
126 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
127 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
128 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
129 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
130
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
131 Dictionary args;
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
132 args.SetUtf8Value("uuid", uuid);
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
133 args.SetIntegerValue("type", type);
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
134 args.SetIntegerValue("length", length);
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
135
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
136 /**
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
137 * "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
138 * 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
139 * 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
140 * 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
141 **/
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
142 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
143
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
144 statement.Execute(args);
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
145
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
146 if (statement.IsDone())
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
147 {
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
148 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
149 }
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
150 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
151 {
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
152 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
153 }
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
154 else
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
155 {
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
156 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
157
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
158 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
159 {
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
160 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
161
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
162 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
163 {
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
164 visitor.Assign(content);
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
165 }
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
166 else
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 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
169 }
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
170 }
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
171 else
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 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
174 }
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
175 }
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
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
178 transaction.Commit();
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
179
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
180 if (!visitor.IsSuccess())
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 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
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 };
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
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
188 StorageBackend::IAccessor* MySQLStorageArea::CreateAccessor()
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
189 {
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
190 return new Accessor(*this);
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
191 }
17
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 }