annotate Resources/Orthanc/Databases/ISqlLookupFormatter.h @ 524:48aba35fe64e large-queries

merged BEGIN and SET TRANSACTION statements
author Alain Mazy <am@orthanc.team>
date Tue, 09 Jul 2024 16:30:52 +0200
parents 54d518dcd74a
children 4ecf50a4521c aff02ad9fbbc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
152
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
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: 426
diff changeset
7 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
152
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 *
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * This program is free software: you can redistribute it and/or
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * modify it under the terms of the GNU General Public License as
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * published by the Free Software Foundation, either version 3 of the
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * License, or (at your option) any later version.
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 *
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * This program is distributed in the hope that it will be useful, but
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * General Public License for more details.
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 *
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * You should have received a copy of the GNU General Public License
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 **/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #pragma once
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #if ORTHANC_BUILDING_SERVER_LIBRARY == 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 # include "../../../OrthancFramework/Sources/Enumerations.h"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 #else
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 # include <Enumerations.h>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 #endif
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 #include <boost/noncopyable.hpp>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 #include <vector>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 namespace Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 class DatabaseConstraint;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38
405
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 358
diff changeset
39 enum LabelsConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 358
diff changeset
40 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 358
diff changeset
41 LabelsConstraint_All,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 358
diff changeset
42 LabelsConstraint_Any,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 358
diff changeset
43 LabelsConstraint_None
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 358
diff changeset
44 };
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 358
diff changeset
45
152
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 // This class is also used by the "orthanc-databases" project
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 class ISqlLookupFormatter : public boost::noncopyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 public:
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 virtual ~ISqlLookupFormatter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 virtual std::string GenerateParameter(const std::string& value) = 0;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 virtual std::string FormatResourceType(ResourceType level) = 0;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 virtual std::string FormatWildcardEscape() = 0;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59
354
2a3bbb4104fa fix changeset 389c037387ea
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
60 /**
2a3bbb4104fa fix changeset 389c037387ea
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
61 * Whether to escape '[' and ']', which is only needed for
405
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 358
diff changeset
62 * MSSQL. New in Orthanc 1.10.0, from the following changeset:
426
d700c8f9fc24 migration to UCLouvain servers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 415
diff changeset
63 * https://orthanc.uclouvain.be/hg/orthanc-databases/rev/389c037387ea
354
2a3bbb4104fa fix changeset 389c037387ea
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
64 **/
2a3bbb4104fa fix changeset 389c037387ea
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
65 virtual bool IsEscapeBrackets() const = 0;
2a3bbb4104fa fix changeset 389c037387ea
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
66
415
7e123f047771 LookupResources optimization continued
Alain Mazy <am@osimis.io>
parents: 414
diff changeset
67 static void GetLookupLevels(ResourceType& lowerLevel, ResourceType& upperLevel, const ResourceType& queryLevel, const std::vector<DatabaseConstraint>& lookup);
7e123f047771 LookupResources optimization continued
Alain Mazy <am@osimis.io>
parents: 414
diff changeset
68
152
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 static void Apply(std::string& sql,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 ISqlLookupFormatter& formatter,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 const std::vector<DatabaseConstraint>& lookup,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 ResourceType queryLevel,
405
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 358
diff changeset
73 const std::set<std::string>& labels, // New in Orthanc 1.12.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 358
diff changeset
74 LabelsConstraint labelsConstraint, // New in Orthanc 1.12.0
152
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 size_t limit);
414
f2d3b5c5a68d Optimizing tools/find at studies level only. Integ Tests are ok with PG
Alain Mazy <am@osimis.io>
parents: 406
diff changeset
76
415
7e123f047771 LookupResources optimization continued
Alain Mazy <am@osimis.io>
parents: 414
diff changeset
77 static void ApplySingleLevel(std::string& sql,
7e123f047771 LookupResources optimization continued
Alain Mazy <am@osimis.io>
parents: 414
diff changeset
78 ISqlLookupFormatter& formatter,
7e123f047771 LookupResources optimization continued
Alain Mazy <am@osimis.io>
parents: 414
diff changeset
79 const std::vector<DatabaseConstraint>& lookup,
7e123f047771 LookupResources optimization continued
Alain Mazy <am@osimis.io>
parents: 414
diff changeset
80 ResourceType queryLevel,
7e123f047771 LookupResources optimization continued
Alain Mazy <am@osimis.io>
parents: 414
diff changeset
81 const std::set<std::string>& labels, // New in Orthanc 1.12.0
7e123f047771 LookupResources optimization continued
Alain Mazy <am@osimis.io>
parents: 414
diff changeset
82 LabelsConstraint labelsConstraint, // New in Orthanc 1.12.0
7e123f047771 LookupResources optimization continued
Alain Mazy <am@osimis.io>
parents: 414
diff changeset
83 size_t limit);
152
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 };
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 }