sptk2 logo
SPTK Home Page
DatabaseStatement.h
1/*
2╔══════════════════════════════════════════════════════════════════════════════╗
3║ SIMPLY POWERFUL TOOLKIT (SPTK) ║
4╟──────────────────────────────────────────────────────────────────────────────╢
5║ copyright © 1999-2022 Alexey Parshin. All rights reserved. ║
6║ email alexeyp@gmail.com ║
7╚══════════════════════════════════════════════════════════════════════════════╝
8┌──────────────────────────────────────────────────────────────────────────────┐
9│ This library is free software; you can redistribute it and/or modify it │
10│ under the terms of the GNU Library General Public License as published by │
11│ the Free Software Foundation; either version 2 of the License, or (at your │
12│ option) any later version. │
13│ │
14│ This library is distributed in the hope that it will be useful, but │
15│ WITHOUT ANY WARRANTY; without even the implied warranty of │
16│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library │
17│ General Public License for more details. │
18│ │
19│ You should have received a copy of the GNU Library General Public License │
20│ along with this library; if not, write to the Free Software Foundation, │
21│ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. │
22│ │
23│ Please report all bugs and problems to alexeyp@gmail.com. │
24└──────────────────────────────────────────────────────────────────────────────┘
25*/
26
27#pragma once
28
29#include <sptk5/db/QueryParameterList.h>
30
31namespace sptk {
32
36template<class Connection, class Statement>
38{
39public:
40 Connection* connection() const
41 {
42 return m_connection;
43 }
44
45 void statement(Statement* stmt)
46 {
47 m_statement = stmt;
48 }
49
50 Statement* statement() const
51 {
52 return m_statement;
53 }
54
59 explicit DatabaseStatement(Connection* connection)
60 : m_connection(connection)
61 {
62 }
63
67 virtual ~DatabaseStatement() = default;
68
72 Statement* stmt() const
73 {
74 return m_statement;
75 }
76
81 virtual void enumerateParams(QueryParameterList& queryParams)
82 {
83 queryParams.enumerate(m_enumeratedParams);
84 m_state.outputParameterCount = 0;
85
86 for (auto parameter: m_enumeratedParams)
87 {
88 if (parameter->isOutput())
89 ++m_state.outputParameterCount;
90 }
91 }
92
97 {
98 return m_enumeratedParams;
99 }
100
104 size_t outputParameterCount() const
105 {
106 return m_state.outputParameterCount;
107 }
108
112 virtual void setParameterValues() = 0;
113
118 virtual void execute(bool inTransaction) = 0;
119
123 virtual void close() = 0;
124
128 virtual void fetch() = 0;
129
133 bool eof() const
134 {
135 return m_state.eof;
136 }
137
141 unsigned colCount() const
142 {
143 return m_state.columnCount;
144 }
145
146protected:
150 struct State {
154 unsigned columnCount : 12;
155
159 bool eof : 1;
160
164 bool transaction : 1;
165
170 };
171
172 State& state()
173 {
174 return m_state;
175 }
176
177private:
178 Connection* m_connection {nullptr};
179 Statement* m_statement {nullptr};
180 State m_state {};
181 CParamVector m_enumeratedParams;
182};
183
184} // namespace sptk
Definition: DatabaseStatement.h:38
virtual void enumerateParams(QueryParameterList &queryParams)
Definition: DatabaseStatement.h:81
virtual void fetch()=0
Statement * stmt() const
Definition: DatabaseStatement.h:72
virtual void execute(bool inTransaction)=0
CParamVector & enumeratedParams()
Definition: DatabaseStatement.h:96
virtual ~DatabaseStatement()=default
size_t outputParameterCount() const
Definition: DatabaseStatement.h:104
DatabaseStatement(Connection *connection)
Definition: DatabaseStatement.h:59
virtual void close()=0
virtual void setParameterValues()=0
bool eof() const
Definition: DatabaseStatement.h:133
unsigned colCount() const
Definition: DatabaseStatement.h:141
Definition: QueryParameterList.h:57
void enumerate(CParamVector &params) const
std::vector< SQueryParameter > CParamVector
Definition: QueryParameterList.h:47
Definition: DatabaseStatement.h:150
unsigned outputParameterCount
Definition: DatabaseStatement.h:169
bool transaction
Definition: DatabaseStatement.h:164
unsigned columnCount
Definition: DatabaseStatement.h:154
bool eof
Definition: DatabaseStatement.h:159

Fri Oct 14 2022 09:58:31: SPTK 5.4.1