annotate OrthancServer/Sources/Search/ISqlLookupFormatter.cpp @ 5248:a7d95f951f8a db-protobuf

replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 07 Apr 2023 22:18:37 +0200
parents 988dab8deb1c
children 261ce0ed85e6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3058
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
5185
0ea402b4d901 upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium
0ea402b4d901 upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
6 * Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
3058
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 *
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * This program is free software: you can redistribute it and/or
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * modify it under the terms of the GNU General Public License as
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * published by the Free Software Foundation, either version 3 of the
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * License, or (at your option) any later version.
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 *
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful, but
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * General Public License for more details.
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 *
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 **/
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
4096
d633e5bb7ba3 reusing of ISqlLookupFormatter and DatabaseConstraint in orthanc-databases project
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
23 #if !defined(ORTHANC_BUILDING_SERVER_LIBRARY)
d633e5bb7ba3 reusing of ISqlLookupFormatter and DatabaseConstraint in orthanc-databases project
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
24 # error Macro ORTHANC_BUILDING_SERVER_LIBRARY must be defined
d633e5bb7ba3 reusing of ISqlLookupFormatter and DatabaseConstraint in orthanc-databases project
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
25 #endif
d633e5bb7ba3 reusing of ISqlLookupFormatter and DatabaseConstraint in orthanc-databases project
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
26
d633e5bb7ba3 reusing of ISqlLookupFormatter and DatabaseConstraint in orthanc-databases project
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
27 #if ORTHANC_BUILDING_SERVER_LIBRARY == 1
d633e5bb7ba3 reusing of ISqlLookupFormatter and DatabaseConstraint in orthanc-databases project
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
28 # include "../PrecompiledHeadersServer.h"
d633e5bb7ba3 reusing of ISqlLookupFormatter and DatabaseConstraint in orthanc-databases project
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
29 #endif
d633e5bb7ba3 reusing of ISqlLookupFormatter and DatabaseConstraint in orthanc-databases project
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
30
3058
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 #include "ISqlLookupFormatter.h"
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
4096
d633e5bb7ba3 reusing of ISqlLookupFormatter and DatabaseConstraint in orthanc-databases project
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
33 #if ORTHANC_BUILDING_SERVER_LIBRARY == 1
d633e5bb7ba3 reusing of ISqlLookupFormatter and DatabaseConstraint in orthanc-databases project
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
34 # include "../../../OrthancFramework/Sources/OrthancException.h"
d633e5bb7ba3 reusing of ISqlLookupFormatter and DatabaseConstraint in orthanc-databases project
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
35 #else
d633e5bb7ba3 reusing of ISqlLookupFormatter and DatabaseConstraint in orthanc-databases project
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
36 # include <OrthancException.h>
d633e5bb7ba3 reusing of ISqlLookupFormatter and DatabaseConstraint in orthanc-databases project
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
37 #endif
d633e5bb7ba3 reusing of ISqlLookupFormatter and DatabaseConstraint in orthanc-databases project
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
38
3100
f6de9d25b20d removing build dependency on plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3079
diff changeset
39 #include "DatabaseConstraint.h"
3058
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40
4304
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4096
diff changeset
41 #include <boost/lexical_cast.hpp>
5227
988dab8deb1c "/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
42 #include <list>
4304
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4096
diff changeset
43
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4096
diff changeset
44
3058
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 namespace Orthanc
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 {
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 static std::string FormatLevel(ResourceType level)
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 {
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 switch (level)
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 {
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 case ResourceType_Patient:
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 return "patients";
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 case ResourceType_Study:
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 return "studies";
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 case ResourceType_Series:
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 return "series";
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 case ResourceType_Instance:
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 return "instances";
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 default:
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 throw OrthancException(ErrorCode_InternalError);
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 }
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 }
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 static bool FormatComparison(std::string& target,
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 ISqlLookupFormatter& formatter,
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 const DatabaseConstraint& constraint,
4817
b8fcd331b4b3 added ISqlLookupFormatter::IsEscapeBrackets()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
72 size_t index,
b8fcd331b4b3 added ISqlLookupFormatter::IsEscapeBrackets()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
73 bool escapeBrackets)
3058
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 {
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 std::string tag = "t" + boost::lexical_cast<std::string>(index);
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 std::string comparison;
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 switch (constraint.GetConstraintType())
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 {
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 case ConstraintType_Equal:
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 case ConstraintType_SmallerOrEqual:
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 case ConstraintType_GreaterOrEqual:
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 {
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 std::string op;
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 switch (constraint.GetConstraintType())
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 {
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 case ConstraintType_Equal:
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 op = "=";
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 break;
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 case ConstraintType_SmallerOrEqual:
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 op = "<=";
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 break;
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 case ConstraintType_GreaterOrEqual:
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 op = ">=";
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 break;
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 default:
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 throw OrthancException(ErrorCode_InternalError);
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 }
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 std::string parameter = formatter.GenerateParameter(constraint.GetSingleValue());
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 if (constraint.IsCaseSensitive())
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 {
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 comparison = tag + ".value " + op + " " + parameter;
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 }
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 else
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 {
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 comparison = "lower(" + tag + ".value) " + op + " lower(" + parameter + ")";
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 }
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 break;
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 }
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 case ConstraintType_List:
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 {
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 for (size_t i = 0; i < constraint.GetValuesCount(); i++)
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 {
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 if (!comparison.empty())
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 {
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 comparison += ", ";
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 }
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 std::string parameter = formatter.GenerateParameter(constraint.GetValue(i));
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 if (constraint.IsCaseSensitive())
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 {
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 comparison += parameter;
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 }
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 else
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 {
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 comparison += "lower(" + parameter + ")";
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 }
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 }
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 if (constraint.IsCaseSensitive())
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 {
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 comparison = tag + ".value IN (" + comparison + ")";
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 }
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 else
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 {
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 comparison = "lower(" + tag + ".value) IN (" + comparison + ")";
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 }
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 break;
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 }
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 case ConstraintType_Wildcard:
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 {
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 const std::string value = constraint.GetSingleValue();
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 if (value == "*")
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 {
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 if (!constraint.IsMandatory())
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 {
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 // Universal constraint on an optional tag, ignore it
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 return false;
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 }
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 }
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 else
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 {
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 std::string escaped;
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 escaped.reserve(value.size());
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 for (size_t i = 0; i < value.size(); i++)
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 {
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 if (value[i] == '*')
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 {
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 escaped += "%";
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 }
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 else if (value[i] == '?')
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 {
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 escaped += "_";
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 }
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 else if (value[i] == '%')
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 {
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 escaped += "\\%";
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 }
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 else if (value[i] == '_')
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 {
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 escaped += "\\_";
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 }
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 else if (value[i] == '\\')
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 {
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 escaped += "\\\\";
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 }
4817
b8fcd331b4b3 added ISqlLookupFormatter::IsEscapeBrackets()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
190 else if (escapeBrackets && value[i] == '[')
b8fcd331b4b3 added ISqlLookupFormatter::IsEscapeBrackets()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
191 {
b8fcd331b4b3 added ISqlLookupFormatter::IsEscapeBrackets()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
192 escaped += "\\[";
b8fcd331b4b3 added ISqlLookupFormatter::IsEscapeBrackets()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
193 }
b8fcd331b4b3 added ISqlLookupFormatter::IsEscapeBrackets()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
194 else if (escapeBrackets && value[i] == ']')
b8fcd331b4b3 added ISqlLookupFormatter::IsEscapeBrackets()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
195 {
b8fcd331b4b3 added ISqlLookupFormatter::IsEscapeBrackets()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
196 escaped += "\\]";
b8fcd331b4b3 added ISqlLookupFormatter::IsEscapeBrackets()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
197 }
3058
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 else
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 {
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 escaped += value[i];
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 }
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 }
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 std::string parameter = formatter.GenerateParameter(escaped);
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 if (constraint.IsCaseSensitive())
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 {
3079
65e2bfa953ef ISqlLookupFormatter::FormatWildcardEscape()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3078
diff changeset
208 comparison = (tag + ".value LIKE " + parameter + " " +
65e2bfa953ef ISqlLookupFormatter::FormatWildcardEscape()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3078
diff changeset
209 formatter.FormatWildcardEscape());
3058
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 }
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 else
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 {
3079
65e2bfa953ef ISqlLookupFormatter::FormatWildcardEscape()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3078
diff changeset
213 comparison = ("lower(" + tag + ".value) LIKE lower(" +
65e2bfa953ef ISqlLookupFormatter::FormatWildcardEscape()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3078
diff changeset
214 parameter + ") " + formatter.FormatWildcardEscape());
3058
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 }
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 }
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 break;
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 }
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 default:
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 return false;
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 }
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 if (constraint.IsMandatory())
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 {
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227 target = comparison;
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 }
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 else if (comparison.empty())
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 {
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 target = tag + ".value IS NULL";
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 }
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 else
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 {
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 target = tag + ".value IS NULL OR " + comparison;
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 }
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238 return true;
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 }
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242 static void FormatJoin(std::string& target,
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 const DatabaseConstraint& constraint,
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244 size_t index)
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 {
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246 std::string tag = "t" + boost::lexical_cast<std::string>(index);
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248 if (constraint.IsMandatory())
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 {
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 target = " INNER JOIN ";
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 }
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 else
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253 {
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254 target = " LEFT JOIN ";
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 }
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257 if (constraint.IsIdentifier())
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258 {
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259 target += "DicomIdentifiers ";
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260 }
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261 else
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262 {
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263 target += "MainDicomTags ";
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264 }
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266 target += (tag + " ON " + tag + ".id = " + FormatLevel(constraint.GetLevel()) +
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267 ".internalId AND " + tag + ".tagGroup = " +
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268 boost::lexical_cast<std::string>(constraint.GetTag().GetGroup()) +
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269 " AND " + tag + ".tagElement = " +
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
270 boost::lexical_cast<std::string>(constraint.GetTag().GetElement()));
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
271 }
5227
988dab8deb1c "/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
272
988dab8deb1c "/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
273
988dab8deb1c "/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
274 static std::string Join(const std::list<std::string>& values,
988dab8deb1c "/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
275 const std::string& prefix,
988dab8deb1c "/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
276 const std::string& separator)
988dab8deb1c "/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
277 {
988dab8deb1c "/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
278 if (values.empty())
988dab8deb1c "/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
279 {
988dab8deb1c "/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
280 return "";
988dab8deb1c "/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
281 }
988dab8deb1c "/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
282 else
988dab8deb1c "/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
283 {
988dab8deb1c "/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
284 std::string s = prefix;
988dab8deb1c "/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
285
988dab8deb1c "/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
286 bool first = true;
988dab8deb1c "/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
287 for (std::list<std::string>::const_iterator it = values.begin(); it != values.end(); ++it)
988dab8deb1c "/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
288 {
988dab8deb1c "/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
289 if (first)
988dab8deb1c "/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
290 {
988dab8deb1c "/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
291 first = false;
988dab8deb1c "/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
292 }
988dab8deb1c "/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
293 else
988dab8deb1c "/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
294 {
988dab8deb1c "/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
295 s += separator;
988dab8deb1c "/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
296 }
988dab8deb1c "/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
297
988dab8deb1c "/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
298 s += *it;
988dab8deb1c "/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
299 }
988dab8deb1c "/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
300
988dab8deb1c "/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
301 return s;
988dab8deb1c "/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
302 }
988dab8deb1c "/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
303 }
3058
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
304
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
305
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
306 void ISqlLookupFormatter::Apply(std::string& sql,
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
307 ISqlLookupFormatter& formatter,
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
308 const std::vector<DatabaseConstraint>& lookup,
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
309 ResourceType queryLevel,
5248
a7d95f951f8a replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5227
diff changeset
310 const std::set<std::string>& labels,
a7d95f951f8a replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5227
diff changeset
311 LabelsConstraint labelsConstraint,
3058
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
312 size_t limit)
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
313 {
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
314 assert(ResourceType_Patient < ResourceType_Study &&
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
315 ResourceType_Study < ResourceType_Series &&
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
316 ResourceType_Series < ResourceType_Instance);
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
317
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
318 ResourceType upperLevel = queryLevel;
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
319 ResourceType lowerLevel = queryLevel;
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
320
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
321 for (size_t i = 0; i < lookup.size(); i++)
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
322 {
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
323 ResourceType level = lookup[i].GetLevel();
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
324
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
325 if (level < upperLevel)
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
326 {
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
327 upperLevel = level;
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
328 }
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
329
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
330 if (level > lowerLevel)
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
331 {
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
332 lowerLevel = level;
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
333 }
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
334 }
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
335
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
336 assert(upperLevel <= queryLevel &&
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
337 queryLevel <= lowerLevel);
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
338
4817
b8fcd331b4b3 added ISqlLookupFormatter::IsEscapeBrackets()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
339 const bool escapeBrackets = formatter.IsEscapeBrackets();
b8fcd331b4b3 added ISqlLookupFormatter::IsEscapeBrackets()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
340
3058
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
341 std::string joins, comparisons;
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
342
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
343 size_t count = 0;
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
344
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
345 for (size_t i = 0; i < lookup.size(); i++)
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
346 {
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
347 std::string comparison;
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
348
4817
b8fcd331b4b3 added ISqlLookupFormatter::IsEscapeBrackets()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
349 if (FormatComparison(comparison, formatter, lookup[i], count, escapeBrackets))
3058
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
350 {
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
351 std::string join;
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
352 FormatJoin(join, lookup[i], count);
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
353 joins += join;
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
354
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
355 if (!comparison.empty())
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
356 {
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
357 comparisons += " AND " + comparison;
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
358 }
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
359
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
360 count ++;
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
361 }
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
362 }
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
363
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
364 sql = ("SELECT " +
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
365 FormatLevel(queryLevel) + ".publicId, " +
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
366 FormatLevel(queryLevel) + ".internalId" +
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
367 " FROM Resources AS " + FormatLevel(queryLevel));
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
368
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
369 for (int level = queryLevel - 1; level >= upperLevel; level--)
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
370 {
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
371 sql += (" INNER JOIN Resources " +
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
372 FormatLevel(static_cast<ResourceType>(level)) + " ON " +
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
373 FormatLevel(static_cast<ResourceType>(level)) + ".internalId=" +
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
374 FormatLevel(static_cast<ResourceType>(level + 1)) + ".parentId");
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
375 }
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
376
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
377 for (int level = queryLevel + 1; level <= lowerLevel; level++)
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
378 {
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
379 sql += (" INNER JOIN Resources " +
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
380 FormatLevel(static_cast<ResourceType>(level)) + " ON " +
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
381 FormatLevel(static_cast<ResourceType>(level - 1)) + ".internalId=" +
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
382 FormatLevel(static_cast<ResourceType>(level)) + ".parentId");
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
383 }
5227
988dab8deb1c "/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
384
988dab8deb1c "/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
385 std::list<std::string> where;
988dab8deb1c "/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
386
5248
a7d95f951f8a replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5227
diff changeset
387 if (!labels.empty())
5227
988dab8deb1c "/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
388 {
988dab8deb1c "/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
389 /**
988dab8deb1c "/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
390 * "In SQL Server, NOT EXISTS and NOT IN predicates are the best
988dab8deb1c "/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
391 * way to search for missing values, as long as both columns in
988dab8deb1c "/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
392 * question are NOT NULL."
988dab8deb1c "/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
393 * https://explainextended.com/2009/09/15/not-in-vs-not-exists-vs-left-join-is-null-sql-server/
988dab8deb1c "/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
394 **/
5248
a7d95f951f8a replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5227
diff changeset
395
a7d95f951f8a replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5227
diff changeset
396 std::list<std::string> formattedLabels;
a7d95f951f8a replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5227
diff changeset
397 for (std::set<std::string>::const_iterator it = labels.begin(); it != labels.end(); ++it)
5227
988dab8deb1c "/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
398 {
5248
a7d95f951f8a replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5227
diff changeset
399 formattedLabels.push_back(formatter.GenerateParameter(*it));
5227
988dab8deb1c "/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
400 }
988dab8deb1c "/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
401
5248
a7d95f951f8a replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5227
diff changeset
402 std::string condition;
a7d95f951f8a replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5227
diff changeset
403 switch (labelsConstraint)
a7d95f951f8a replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5227
diff changeset
404 {
a7d95f951f8a replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5227
diff changeset
405 case LabelsConstraint_Any:
a7d95f951f8a replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5227
diff changeset
406 condition = "> 0";
a7d95f951f8a replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5227
diff changeset
407 break;
a7d95f951f8a replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5227
diff changeset
408
a7d95f951f8a replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5227
diff changeset
409 case LabelsConstraint_All:
a7d95f951f8a replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5227
diff changeset
410 condition = "= " + boost::lexical_cast<std::string>(labels.size());
a7d95f951f8a replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5227
diff changeset
411 break;
a7d95f951f8a replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5227
diff changeset
412
a7d95f951f8a replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5227
diff changeset
413 case LabelsConstraint_None:
a7d95f951f8a replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5227
diff changeset
414 condition = "= 0";
a7d95f951f8a replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5227
diff changeset
415 break;
a7d95f951f8a replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5227
diff changeset
416
a7d95f951f8a replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5227
diff changeset
417 default:
a7d95f951f8a replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5227
diff changeset
418 throw OrthancException(ErrorCode_ParameterOutOfRange);
a7d95f951f8a replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5227
diff changeset
419 }
a7d95f951f8a replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5227
diff changeset
420
a7d95f951f8a replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5227
diff changeset
421 where.push_back("(SELECT COUNT(1) FROM Labels WHERE internalId = " + FormatLevel(queryLevel) +
a7d95f951f8a replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5227
diff changeset
422 ".internalId AND label IN (" + Join(formattedLabels, "", ", ") + ")) " + condition);
5227
988dab8deb1c "/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
423 }
988dab8deb1c "/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
424
988dab8deb1c "/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
425 where.push_back(FormatLevel(queryLevel) + ".resourceType = " +
988dab8deb1c "/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
426 formatter.FormatResourceType(queryLevel) + comparisons);
988dab8deb1c "/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
427
988dab8deb1c "/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
428 sql += joins + Join(where, " WHERE ", " AND ");
3058
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
429
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
430 if (limit != 0)
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
431 {
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
432 sql += " LIMIT " + boost::lexical_cast<std::string>(limit);
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
433 }
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
434 }
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
435 }