MySQL++ Reference Manual

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

qparms.h
Go to the documentation of this file.
1
8 /***********************************************************************
9 Copyright (c) 1998 by Kevin Atkinson, (c) 1999-2001 by MySQL AB, and
10 (c) 2004-2007 by Educational Technology Resources, Inc. Others may
11 also hold copyrights on code in this file. See the CREDITS.txt file
12 in the top directory of the distribution for details.
13
14 This file is part of MySQL++.
15
16 MySQL++ is free software; you can redistribute it and/or modify it
17 under the terms of the GNU Lesser General Public License as published
18 by the Free Software Foundation; either version 2.1 of the License, or
19 (at your option) any later version.
20
21 MySQL++ is distributed in the hope that it will be useful, but WITHOUT
22 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
24 License for more details.
25
26 You should have received a copy of the GNU Lesser General Public
27 License along with MySQL++; if not, write to the Free Software
28 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
29 USA
30 ***********************************************************************/
31
32 #ifndef MYSQLPP_QPARMS_H
33 #define MYSQLPP_QPARMS_H
34
35 #include "stadapter.h"
36
37 #include <vector>
38
39 namespace mysqlpp {
40
41 #if !defined(DOXYGEN_IGNORE)
42 // Make Doxygen ignore this
43 class MYSQLPP_EXPORT Query;
44 #endif
45
48 class MYSQLPP_EXPORT SQLQueryParms : public std::vector<SQLTypeAdapter>
49 {
50 public:
53 typedef const SQLTypeAdapter& sta;
54
56 SQLQueryParms() :
57 parent_(0),
58 processing_(false)
59 {
60 }
61
66 SQLQueryParms(Query* p) :
67 parent_(p),
68 processing_(false)
69 {
70 }
71
75 bool bound() { return parent_ != 0; }
76
78 void clear() { erase(begin(), end()); }
79
88 size_t escape_string(std::string* ps, const char* original = 0,
89 size_t length = 0) const;
90
95 size_t escape_string(char* escaped, const char* original,
96 size_t length) const;
97
99 SQLTypeAdapter& operator [](size_type n)
100 {
101 if (n >= size()) {
102 insert(end(), (n + 1) - size(), "");
103 }
104 return std::vector<SQLTypeAdapter>::operator [](n);
105 }
106
108 const SQLTypeAdapter& operator [](size_type n) const
109 { return std::vector<SQLTypeAdapter>::operator [](n); }
110
112 SQLTypeAdapter& operator [](const char *str);
113
115 const SQLTypeAdapter& operator [](const char *str) const;
116
118 SQLQueryParms& operator <<(const SQLTypeAdapter& str)
119 {
120 push_back(str);
121 return *this;
122 }
123
125 SQLQueryParms& operator +=(const SQLTypeAdapter& str)
126 {
127 push_back(str);
128 return *this;
129 }
130
140 SQLQueryParms operator +(
141 const SQLQueryParms& other) const;
142
143 #if !defined(DOXYGEN_IGNORE)
144 // Doxygen will not generate documentation for this section.
145 void set(sta a)
146 {
147 clear();
148 *this << a;
149 }
150 void set(sta a, sta b)
151 {
152 clear();
153 *this << a << b;
154 }
155 void set(sta a, sta b, sta c)
156 {
157 clear();
158 *this << a << b << c;
159 }
160 void set(sta a, sta b, sta c, sta d)
161 {
162 clear();
163 *this << a << b << c << d;
164 }
165 void set(sta a, sta b, sta c, sta d, sta e)
166 {
167 clear();
168 *this << a << b << c << d << e;
169 }
170 void set(sta a, sta b, sta c, sta d, sta e, sta f)
171 {
172 clear();
173 *this << a << b << c << d << e << f;
174 }
175 void set(sta a, sta b, sta c, sta d, sta e, sta f, sta g)
176 {
177 clear();
178 *this << a << b << c << d << e << f << g;
179 }
180 void set(sta a, sta b, sta c, sta d, sta e, sta f, sta g, sta h)
181 {
182 clear();
183 *this << a << b << c << d << e << f << g << h;
184 }
185 void set(sta a, sta b, sta c, sta d, sta e, sta f, sta g, sta h, sta i)
186 {
187 clear();
188 *this << a << b << c << d << e << f << g << h << i;
189 }
190 void set(sta a, sta b, sta c, sta d, sta e, sta f, sta g, sta h, sta i, sta j)
191 {
192 clear();
193 *this << a << b << c << d << e << f << g << h << i << j;
194 }
195 void set(sta a, sta b, sta c, sta d, sta e, sta f, sta g, sta h, sta i, sta j, sta k)
196 {
197 clear();
198 *this << a << b << c << d << e << f << g << h << i << j << k;
199 }
200 #endif // !defined(DOXYGEN_IGNORE)
201
207 void set(sta a, sta b, sta c, sta d, sta e, sta f, sta g,
208 sta h, sta i, sta j, sta k, sta l)
209 {
210 clear();
211 *this << a << b << c << d << e << f << g << h << i << j << k << l;
212 }
213
214 private:
215 friend class Query;
216
217 Query* parent_;
218 bool processing_;
219 };
220
221
243
244 struct SQLParseElement
245 {
251 SQLParseElement(std::string b, char o, signed char n) :
252 before(b),
253 option(o),
254 num(n)
255 {
256 }
257
258 std::string before;
259 char option;
260 signed char num;
261 };
262
263 } // end namespace mysqlpp
264
265 #endif // !defined(MYSQLPP_QPARMS_H)
266
stadapter.h
Declares the SQLTypeAdapter class.
mysqlpp::SQLQueryParms::SQLQueryParms
SQLQueryParms()
Default constructor.
Definition: qparms.h:56
mysqlpp::SQLParseElement::num
signed char num
the parameter position to use
Definition: qparms.h:260
mysqlpp::SQLQueryParms::sta
const SQLTypeAdapter & sta
Abbreviation so some of the declarations below don&#39;t span many lines.
Definition: qparms.h:53
mysqlpp::SQLParseElement::SQLParseElement
SQLParseElement(std::string b, char o, signed char n)
Create object.
Definition: qparms.h:251
mysqlpp::SQLParseElement::before
std::string before
string inserted before the parameter
Definition: qparms.h:258
mysqlpp::SQLQueryParms::clear
void clear()
Clears the list.
Definition: qparms.h:78
mysqlpp::SQLParseElement::option
char option
the parameter option, or blank if none
Definition: qparms.h:259
mysqlpp::SQLQueryParms::bound
bool bound()
Returns true if we are bound to a query object.
Definition: qparms.h:75
mysqlpp::SQLQueryParms::SQLQueryParms
SQLQueryParms(Query *p)
Create object.
Definition: qparms.h:66
mysqlpp::SQLParseElement
Used within Query to hold elements for parameterized queries.
Definition: qparms.h:244
mysqlpp::SQLQueryParms::set
void set(sta a, sta b, sta c, sta d, sta e, sta f, sta g, sta h, sta i, sta j, sta k, sta l)
Set the template query parameters.
Definition: qparms.h:207
mysqlpp::SQLQueryParms
This class holds the parameter values for filling template queries.
Definition: qparms.h:48
mysqlpp::SQLTypeAdapter
Converts many different data types to strings suitable for use in SQL queries.
Definition: stadapter.h:73
mysqlpp::Query
A class for building and executing SQL queries.
Definition: query.h:121