db_conn  v0.2.1-alpha
Database Connection API
statement.hpp
1 /*
2  * File: statement.hpp
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18 
19 #ifndef STATEMENT_HPP
20 #define STATEMENT_HPP
21 
22 #include "result_set.hpp"
23 
24 namespace vgi { namespace dbconn { namespace dbi {
25 
26 class connection;
27 
32 struct istatement
33 {
34  virtual ~istatement() { }
35  virtual void prepare(const std::string& sql) = 0;
36  virtual void call(const std::string& sql) = 0;
37  virtual iresult_set* execute(const std::string& sql, bool cursor = false, bool scrollable = false) = 0;
38  virtual iresult_set* execute() = 0;
39  virtual bool cancel() = 0;
40  virtual int proc_retval() = 0;
41  virtual void set_null(size_t col_idx) = 0;
42  virtual void set_short(size_t col_idx, int16_t val) = 0;
43  virtual void set_ushort(size_t col_idx, uint16_t val) = 0;
44  virtual void set_int(size_t col_idx, int32_t val) = 0;
45  virtual void set_uint(size_t col_idx, uint32_t val) = 0;
46  virtual void set_long(size_t col_idx, int64_t val) = 0;
47  virtual void set_ulong(size_t col_idx, uint64_t val) = 0;
48  virtual void set_float(size_t col_idx, float val) = 0;
49  virtual void set_double(size_t col_idx, double val) = 0;
50  virtual void set_bool(size_t col_idx, bool val) = 0;
51  virtual void set_char(size_t col_idx, char val) = 0;
52  virtual void set_string(size_t col_idx, const std::string& val) = 0;
53  virtual void set_date(size_t col_idx, int val) = 0;
54  virtual void set_time(size_t col_idx, double val) = 0;
55  virtual void set_datetime(size_t col_idx, time_t val) = 0;
56  virtual void set_u16char(size_t col_idx, char16_t val) = 0;
57  virtual void set_u16string(size_t col_idx, const std::u16string& val) = 0;
58  virtual void set_binary(size_t col_idx, const std::vector<uint8_t>& val) = 0;
59 };
60 
61 
72 class statement
73 {
74 public:
79  statement(statement&& stmt) : stmt_impl(std::move(stmt.stmt_impl))
80  {
81  }
82 
89  {
90  if (this != &stmt)
91  stmt_impl = std::move(stmt.stmt_impl);
92  return *this;
93  }
94 
99  void prepare(const std::string& sql)
100  {
101  stmt_impl->prepare(sql);
102  }
103 
108  void call(const std::string& proc)
109  {
110  stmt_impl->call(proc);
111  }
112 
118  {
119  return result_set(stmt_impl->execute());
120  }
121 
129  result_set execute(const std::string& sql, bool cursor = false, bool scrollable = false)
130  {
131  return result_set(stmt_impl->execute(sql, cursor, scrollable));
132  }
133 
138  bool cancel()
139  {
140  return stmt_impl->cancel();
141  }
142 
150  {
151  return stmt_impl->proc_retval();
152  }
153 
154  virtual void set_null(size_t col_idx)
155  {
156  stmt_impl->set_null(col_idx);
157  }
158 
159  virtual void set_short(size_t col_idx, int16_t val)
160  {
161  stmt_impl->set_short(col_idx, val);
162  }
163 
164  virtual void set_ushort(size_t col_idx, uint16_t val)
165  {
166  stmt_impl->set_ushort(col_idx, val);
167  }
168 
169  virtual void set_int(size_t col_idx, int32_t val)
170  {
171  stmt_impl->set_int(col_idx, val);
172  }
173 
174  virtual void set_uint(size_t col_idx, uint32_t val)
175  {
176  stmt_impl->set_uint(col_idx, val);
177  }
178 
179  virtual void set_long(size_t col_idx, int64_t val)
180  {
181  stmt_impl->set_long(col_idx, val);
182  }
183 
184  virtual void set_ulong(size_t col_idx, uint64_t val)
185  {
186  stmt_impl->set_ulong(col_idx, val);
187  }
188 
189  virtual void set_float(size_t col_idx, float val)
190  {
191  stmt_impl->set_float(col_idx, val);
192  }
193 
194  virtual void set_double(size_t col_idx, double val)
195  {
196  stmt_impl->set_double(col_idx, val);
197  }
198 
199  virtual void set_bool(size_t col_idx, bool val)
200  {
201  stmt_impl->set_bool(col_idx, val);
202  }
203 
204  virtual void set_char(size_t col_idx, char val)
205  {
206  stmt_impl->set_char(col_idx, val);
207  }
208 
209  virtual void set_string(size_t col_idx, const std::string& val)
210  {
211  stmt_impl->set_string(col_idx, val);
212  }
213 
214  virtual void set_date(size_t col_idx, int val)
215  {
216  stmt_impl->set_date(col_idx, val);
217  }
218 
219  virtual void set_time(size_t col_idx, double val)
220  {
221  stmt_impl->set_time(col_idx, val);
222  }
223 
224  virtual void set_datetime(size_t col_idx, time_t val)
225  {
226  stmt_impl->set_datetime(col_idx, val);
227  }
228 
229  virtual void set_u16char(size_t col_idx, char16_t val)
230  {
231  stmt_impl->set_u16char(col_idx, val);
232  }
233 
234  virtual void set_u16string(size_t col_idx, const std::u16string& val)
235  {
236  stmt_impl->set_u16string(col_idx, val);
237  }
238 
239  virtual void set_binary(size_t col_idx, const std::vector<uint8_t>& val)
240  {
241  stmt_impl->set_binary(col_idx, val);
242  }
243 
244 private:
245  friend class connection;
246  statement(istatement* stmt) : stmt_impl(stmt) { }
247  statement(const statement&) = delete;
248  statement& operator=(const statement&) = delete;
249 
250 private:
251  std::unique_ptr<istatement> stmt_impl;
252 
253 }; // statement
254 
255 } } } // namespace vgi::dbconn::dbi
256 
257 #endif // STATEMENT_HPP
258 
iresult_set - is an interface that describes common functionality for all concrete native implementat...
Definition: result_set.hpp:32
result_set execute(const std::string &sql, bool cursor=false, bool scrollable=false)
Function runs SQL statement.
Definition: statement.hpp:129
statement - is a class that manages native driver statement handle.
Definition: statement.hpp:72
STL namespace.
istatement - is an interface that describes common functionality for all concrete native implementati...
Definition: statement.hpp:32
void call(const std::string &proc)
Function prepares SQL stored procedure.
Definition: statement.hpp:108
bool cancel()
Function cancels currently running SQL statements.
Definition: statement.hpp:138
result_set execute()
Function runs last executed SQL statement.
Definition: statement.hpp:117
statement & operator=(statement &&stmt)
Assignment operator.
Definition: statement.hpp:88
statement(statement &&stmt)
Move constructor.
Definition: statement.hpp:79
result_set - is a class that manages native driver result_set handle.
Definition: result_set.hpp:78
int proc_retval()
Function returns stored procedure return value.
Definition: statement.hpp:149
void prepare(const std::string &sql)
Function prepares dynamic SQL statement.
Definition: statement.hpp:99
connection - is a class that manages native driver connection handle.
Definition: connection.hpp:62