Mercurial > hg > orthanc-databases
annotate Framework/Common/GenericFormatter.cpp @ 176:0246923d4df9
trying to fix msvc builds with postgresql
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Sat, 12 Dec 2020 17:49:07 +0100 |
parents | 063aa53b5917 |
children | 3236894320d6 |
rev | line source |
---|---|
0 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
140
4cd7e45b671e
upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium |
0 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU Affero General Public License | |
9 * as published by the Free Software Foundation, either version 3 of | |
10 * the License, or (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Affero General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Affero General Public License | |
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 **/ | |
20 | |
21 | |
22 #include "GenericFormatter.h" | |
23 | |
152 | 24 #include <OrthancException.h> |
0 | 25 |
26 #include <boost/lexical_cast.hpp> | |
27 | |
28 namespace OrthancDatabases | |
29 { | |
30 void GenericFormatter::Format(std::string& target, | |
31 const std::string& source, | |
32 ValueType type) | |
33 { | |
34 if (source.empty()) | |
35 { | |
36 // This is the default parameter for INSERT | |
37 switch (dialect_) | |
38 { | |
39 case Dialect_PostgreSQL: | |
40 target = "DEFAULT"; | |
41 break; | |
42 | |
43 case Dialect_MySQL: | |
44 case Dialect_SQLite: | |
45 target = "NULL"; | |
46 break; | |
47 | |
48 default: | |
49 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); | |
50 } | |
51 } | |
52 else | |
53 { | |
54 switch (dialect_) | |
55 { | |
56 case Dialect_PostgreSQL: | |
57 target = "$" + boost::lexical_cast<std::string>(parametersName_.size() + 1); | |
58 break; | |
59 | |
60 case Dialect_MySQL: | |
61 case Dialect_SQLite: | |
62 target = "?"; | |
63 break; | |
64 | |
65 default: | |
66 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); | |
67 } | |
68 | |
69 parametersName_.push_back(source); | |
70 parametersType_.push_back(type); | |
71 } | |
72 } | |
73 | |
74 | |
75 const std::string& GenericFormatter::GetParameterName(size_t index) const | |
76 { | |
77 if (index >= parametersName_.size()) | |
78 { | |
79 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
80 } | |
81 else | |
82 { | |
83 return parametersName_[index]; | |
84 } | |
85 } | |
86 | |
87 | |
88 ValueType GenericFormatter::GetParameterType(size_t index) const | |
89 { | |
90 if (index >= parametersType_.size()) | |
91 { | |
92 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
93 } | |
94 else | |
95 { | |
96 return parametersType_[index]; | |
97 } | |
98 } | |
99 } |