AnCH Framework 0.1
Another C++ Hack Framework
 
Loading...
Searching...
No Matches
preparedStatement.hpp
1/*
2 ANCH Framework: ANother C++ Hack is a C++ framework based on C++11 standard
3 Copyright (C) 2012 Vincent Lachenal
4
5 This file is part of ANCH Framework.
6
7 ANCH Framework is free software: you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 ANCH Framework is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with ANCH Framework. If not, see <http://www.gnu.org/licenses/>.
19*/
20#pragma once
21
22#include <set>
23#include <string>
24
25#include "sql/sqlException.hpp"
26#include "sql/resultSet.hpp"
27#include "sql/types/date.hpp"
28#include "sql/types/time.hpp"
29#include "sql/types/timestamp.hpp"
30
31
32namespace anch::sql {
33
44
45 // Attributes +
46 protected:
48 std::map<std::size_t,std::string> _values;
49
51 std::size_t _nbPlaceholders;
52 // Attributes -
53
54 // Constructors +
55 public:
60 // Constructors -
61
62 // Destructor +
63 public:
67 virtual ~PreparedStatement() noexcept;
68 // Destructor -
69
70 // Methods +
71 public:
79 virtual ResultSet* executeQuery() = 0;
80
88 virtual uint64_t executeUpdate() = 0;
89
98 void set(std::size_t idx, int16_t value);
99
108 void set(std::size_t idx, uint16_t value);
109
118 void set(std::size_t idx, int32_t value);
119
128 void set(std::size_t idx, uint32_t value);
129
138 void set(std::size_t idx, int64_t value);
139
148 void set(std::size_t idx, uint64_t value);
149
158 void set(std::size_t idx, const std::string& value);
159
168 void set(std::size_t idx, const char* const value);
169
178 virtual void set(std::size_t idx, const anch::sql::Date& value);
179
188 virtual void set(std::size_t idx, const anch::sql::Time& value);
189
198 virtual void set(std::size_t idx, const anch::sql::Timestamp& value);
199
200 protected:
208 std::set<std::size_t> getPlaceholders(const std::string& query) const;
209
217 inline void checkIndex(std::size_t index) const {
218 if(index > _nbPlaceholders) {
219 std::ostringstream oss;
220 oss << "Index " << index << " is upper than number of wildcards " << _nbPlaceholders;
221 throw SqlException(oss.str(), true);
222 }
223 }
224 // Methods -
225
226 };
227
228}
SQL date type.
Definition date.hpp:38
std::set< std::size_t > getPlaceholders(const std::string &query) const
virtual uint64_t executeUpdate()=0
std::size_t _nbPlaceholders
Definition preparedStatement.hpp:51
void set(std::size_t idx, int16_t value)
std::map< std::size_t, std::string > _values
Definition preparedStatement.hpp:48
virtual ResultSet * executeQuery()=0
void checkIndex(std::size_t index) const
Definition preparedStatement.hpp:217
SQL result representation.
Definition resultSet.hpp:50
SQL exception.
Definition sqlException.hpp:38
SQL time type.
Definition time.hpp:38
SQL timestamp type.
Definition timestamp.hpp:38
SQL namespace.
Definition clauses.hpp:26
AnCH framework base namespace.
Definition app.hpp:28