comparison Framework/PostgreSQL/PostgreSQLStatement.h @ 0:7cea966b6829

initial commit
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 04 Jul 2018 08:16:29 +0200
parents
children b2ff1cd2907a
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 #if ORTHANC_ENABLE_POSTGRESQL != 1
25 # error PostgreSQL support must be enabled to use this file
26 #endif
27
28 #include "../Common/IPrecompiledStatement.h"
29 #include "../Common/Query.h"
30 #include "../Common/GenericFormatter.h"
31
32 #include "PostgreSQLDatabase.h"
33 #include "PostgreSQLLargeObject.h"
34 #include "PostgreSQLTransaction.h"
35
36 #include <vector>
37 #include <memory>
38 #include <boost/shared_ptr.hpp>
39
40 namespace OrthancDatabases
41 {
42 class PostgreSQLStatement : public IPrecompiledStatement
43 {
44 private:
45 class ResultWrapper;
46 class Inputs;
47 friend class PostgreSQLResult;
48
49 PostgreSQLDatabase& database_;
50 bool readOnly_;
51 std::string id_;
52 std::string sql_;
53 std::vector<unsigned int /*Oid*/> oids_;
54 std::vector<int> binary_;
55 boost::shared_ptr<Inputs> inputs_;
56 GenericFormatter formatter_;
57
58 void Prepare();
59
60 void Unprepare();
61
62 void DeclareInputInternal(unsigned int param,
63 unsigned int /*Oid*/ type);
64
65 void* /* PGresult* */ Execute();
66
67 public:
68 PostgreSQLStatement(PostgreSQLDatabase& database,
69 const std::string& sql,
70 bool readOnly);
71
72 PostgreSQLStatement(PostgreSQLDatabase& database,
73 const Query& query);
74
75 ~PostgreSQLStatement()
76 {
77 Unprepare();
78 }
79
80 virtual bool IsReadOnly() const
81 {
82 return readOnly_;
83 }
84
85 void DeclareInputInteger(unsigned int param);
86
87 void DeclareInputInteger64(unsigned int param);
88
89 void DeclareInputString(unsigned int param);
90
91 void DeclareInputBinary(unsigned int param);
92
93 void DeclareInputLargeObject(unsigned int param);
94
95 void Run();
96
97 void BindNull(unsigned int param);
98
99 void BindInteger(unsigned int param, int value);
100
101 void BindInteger64(unsigned int param, int64_t value);
102
103 void BindString(unsigned int param, const std::string& value);
104
105 void BindLargeObject(unsigned int param, const PostgreSQLLargeObject& value);
106
107 PostgreSQLDatabase& GetDatabase() const
108 {
109 return database_;
110 }
111
112 IResult* Execute(PostgreSQLTransaction& transaction,
113 const Dictionary& parameters);
114
115 void ExecuteWithoutResult(PostgreSQLTransaction& transaction,
116 const Dictionary& parameters);
117 };
118 }