Mercurial > hg > orthanc-databases
annotate Framework/PostgreSQL/PostgreSQLStatement.h @ 31:00b9ab7e26a0
fix
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 16 Jul 2018 16:16:02 +0200 |
parents | b2ff1cd2907a |
children | 6a574d810b98 |
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 | |
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 | |
23
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
112 IResult* Execute(ITransaction& transaction, |
0 | 113 const Dictionary& parameters); |
114 | |
23
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
115 void ExecuteWithoutResult(ITransaction& transaction, |
0 | 116 const Dictionary& parameters); |
117 }; | |
118 } |