comparison Framework/Common/Query.h @ 0:7cea966b6829

initial commit
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 04 Jul 2018 08:16:29 +0200
parents
children 2fb9cd42af14
comparison
equal deleted inserted replaced
-1:000000000000 0:7cea966b6829
1 /**
2 * Orthanc - A Lightweight, RESTful DICOM Store
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
4 * Department, University Hospital of Liege, Belgium
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium
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 #pragma once
23
24 #include "DatabasesEnumerations.h"
25
26 #include <map>
27 #include <vector>
28 #include <string>
29 #include <boost/noncopyable.hpp>
30
31
32 namespace OrthancDatabases
33 {
34 class Query : public boost::noncopyable
35 {
36 public:
37 class IParameterFormatter : public boost::noncopyable
38 {
39 public:
40 virtual ~IParameterFormatter()
41 {
42 }
43
44 virtual void Format(std::string& target,
45 const std::string& source,
46 ValueType type) = 0;
47 };
48
49 private:
50 typedef std::map<std::string, ValueType> Parameters;
51
52 class Token;
53
54 std::vector<Token*> tokens_;
55 Parameters parameters_;
56 bool readOnly_;
57
58 void Setup(const std::string& sql);
59
60 public:
61 Query(const std::string& sql);
62
63 Query(const std::string& sql,
64 bool isReadOnly);
65
66 ~Query();
67
68 bool IsReadOnly() const
69 {
70 return readOnly_;
71 }
72
73 void SetReadOnly(bool isReadOnly)
74 {
75 readOnly_ = isReadOnly;
76 }
77
78 bool HasParameter(const std::string& parameter) const;
79
80 ValueType GetType(const std::string& parameter) const;
81
82 void SetType(const std::string& parameter,
83 ValueType type);
84
85 void Format(std::string& result,
86 IParameterFormatter& formatter) const;
87 };
88 }