qparms.h
Go to the documentation of this file.
/***********************************************************************
Copyright (c) 1998 by Kevin Atkinson, (c) 1999-2001 by MySQL AB, and
(c) 2004-2007 by Educational Technology Resources, Inc. Others may
also hold copyrights on code in this file. See the CREDITS.txt file
in the top directory of the distribution for details.
This file is part of MySQL++.
MySQL++ is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
MySQL++ is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public
License along with MySQL++; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
USA
***********************************************************************/
#ifndef MYSQLPP_QPARMS_H
#define MYSQLPP_QPARMS_H
#include "stadapter.h"
#include <vector>
namespace mysqlpp {
#if !defined(DOXYGEN_IGNORE)
// Make Doxygen ignore this
class MYSQLPP_EXPORT Query;
#endif
class MYSQLPP_EXPORT SQLQueryParms : public std::vector<SQLTypeAdapter>
{
public:
typedef const SQLTypeAdapter& sta;
SQLQueryParms() :
parent_(0),
processing_(false)
{
}
SQLQueryParms(Query* p) :
parent_(p),
processing_(false)
{
}
bool bound() { return parent_ != 0; }
void clear() { erase(begin(), end()); }
size_t escape_string(std::string* ps, const char* original = 0,
size_t length = 0) const;
size_t escape_string(char* escaped, const char* original,
size_t length) const;
SQLTypeAdapter& operator [](size_type n)
{
if (n >= size()) {
insert(end(), (n + 1) - size(), "");
}
return std::vector<SQLTypeAdapter>::operator [](n);
}
const SQLTypeAdapter& operator [](size_type n) const
{ return std::vector<SQLTypeAdapter>::operator [](n); }
SQLTypeAdapter& operator [](const char *str);
const SQLTypeAdapter& operator [](const char *str) const;
SQLQueryParms& operator <<(const SQLTypeAdapter& str)
{
push_back(str);
return *this;
}
SQLQueryParms& operator +=(const SQLTypeAdapter& str)
{
push_back(str);
return *this;
}
SQLQueryParms operator +(
const SQLQueryParms& other) const;
#if !defined(DOXYGEN_IGNORE)
// Doxygen will not generate documentation for this section.
void set(sta a)
{
clear();
*this << a;
}
void set(sta a, sta b)
{
clear();
*this << a << b;
}
void set(sta a, sta b, sta c)
{
clear();
*this << a << b << c;
}
void set(sta a, sta b, sta c, sta d)
{
clear();
*this << a << b << c << d;
}
void set(sta a, sta b, sta c, sta d, sta e)
{
clear();
*this << a << b << c << d << e;
}
void set(sta a, sta b, sta c, sta d, sta e, sta f)
{
clear();
*this << a << b << c << d << e << f;
}
void set(sta a, sta b, sta c, sta d, sta e, sta f, sta g)
{
clear();
*this << a << b << c << d << e << f << g;
}
void set(sta a, sta b, sta c, sta d, sta e, sta f, sta g, sta h)
{
clear();
*this << a << b << c << d << e << f << g << h;
}
void set(sta a, sta b, sta c, sta d, sta e, sta f, sta g, sta h, sta i)
{
clear();
*this << a << b << c << d << e << f << g << h << i;
}
void set(sta a, sta b, sta c, sta d, sta e, sta f, sta g, sta h, sta i, sta j)
{
clear();
*this << a << b << c << d << e << f << g << h << i << j;
}
void set(sta a, sta b, sta c, sta d, sta e, sta f, sta g, sta h, sta i, sta j, sta k)
{
clear();
*this << a << b << c << d << e << f << g << h << i << j << k;
}
#endif // !defined(DOXYGEN_IGNORE)
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)
{
clear();
*this << a << b << c << d << e << f << g << h << i << j << k << l;
}
private:
friend class Query;
Query* parent_;
bool processing_;
};
struct SQLParseElement
{
SQLParseElement(std::string b, char o, signed char n) :
before(b),
option(o),
num(n)
{
}
std::string before;
char option;
signed char num;
};
} // end namespace mysqlpp
#endif // !defined(MYSQLPP_QPARMS_H)
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