MySQL++: row.h Source File
row.h
Go to the documentation of this file.
/***********************************************************************
Copyright (c) 1998 by Kevin Atkinson, (c) 1999-2001 by MySQL AB, and
(c) 2004-2008 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
***********************************************************************/
#if !defined(MYSQLPP_ROW_H)
#define MYSQLPP_ROW_H
#include "common.h"
#include "mystring.h"
#include "noexceptions.h"
#include "refcounted.h"
#include "vallist.h"
#include <vector>
#include <string>
namespace mysqlpp {
#if !defined(DOXYGEN_IGNORE)
// Make Doxygen ignore this
class FieldNames;
class MYSQLPP_EXPORT ResultBase;
#endif
class MYSQLPP_EXPORT Row : public OptionalExceptions
{
private:
typedef bool Row::*private_bool_type;
public:
typedef std::vector<String> list_type;
typedef list_type::const_iterator const_iterator;
typedef list_type::const_reference const_reference;
typedef list_type::const_reverse_iterator const_reverse_iterator;
typedef list_type::difference_type difference_type;
typedef const_iterator iterator;
typedef const_reference reference;
typedef const_reverse_iterator reverse_iterator;
typedef list_type::size_type size_type;
typedef list_type::value_type value_type;
Row() :
initialized_(false)
{
}
Row(const Row& r) :
OptionalExceptions(),
data_(r.data_.begin(), r.data_.end()),
field_names_(r.field_names_),
initialized_(r.initialized_)
{
}
Row(MYSQL_ROW row, const ResultBase* res,
const unsigned long* lengths, bool te = true);
~Row() { }
const_reference at(size_type i) const;
const_reference back() const { return data_.back(); }
const_iterator begin() const { return data_.begin(); }
bool empty() const { return data_.empty(); }
const_iterator end() const { return data_.end(); }
equal_list_ba<FieldNames, Row, quote_type0>
equal_list(const char* d = ",", const char* e = " = ") const;
template <class Manip>
equal_list_ba<FieldNames, Row, Manip> equal_list(const char* d,
const char* e, Manip m) const;
value_list_ba<FieldNames, do_nothing_type0>
field_list(const char* d = ",") const;
template <class Manip>
value_list_ba<FieldNames, Manip> field_list(const char* d,
Manip m) const;
template <class Manip>
value_list_b<FieldNames, Manip> field_list(const char* d, Manip m,
const std::vector<bool>& vb) const;
value_list_b<FieldNames, quote_type0> field_list(
const char* d, const std::vector<bool>& vb) const;
value_list_b<FieldNames, quote_type0> field_list(
const std::vector<bool>& vb) const;
template <class Manip>
value_list_b<FieldNames, Manip> field_list(const char *d, Manip m,
bool t0,
bool t1 = false, bool t2 = false, bool t3 = false,
bool t4 = false, bool t5 = false, bool t6 = false,
bool t7 = false, bool t8 = false, bool t9 = false,
bool ta = false, bool tb = false, bool tc = false) const;
value_list_b<FieldNames, quote_type0> field_list(
const char *d, bool t0,
bool t1 = false, bool t2 = false, bool t3 = false,
bool t4 = false, bool t5 = false, bool t6 = false,
bool t7 = false, bool t8 = false, bool t9 = false,
bool ta = false, bool tb = false, bool tc = false) const;
value_list_b<FieldNames, quote_type0> field_list(
bool t0,
bool t1 = false, bool t2 = false, bool t3 = false,
bool t4 = false, bool t5 = false, bool t6 = false,
bool t7 = false, bool t8 = false, bool t9 = false,
bool ta = false, bool tb = false, bool tc = false) const;
size_type field_num(const char* name) const;
const_reference front() const { return data_.front(); }
size_type max_size() const { return data_.max_size(); }
Row& operator =(const Row& rhs)
{
data_.assign(rhs.data_.begin(), rhs.data_.end());
field_names_.assign(rhs.field_names_);
initialized_ = rhs.initialized_;
return *this;
}
const_reference operator [](const char* field) const;
const_reference operator [](int i) const
{ return at(static_cast<size_type>(i)); }
operator private_bool_type() const
{
return data_.size() && initialized_ ? &Row::initialized_ : 0;
}
const_reverse_iterator rbegin() const { return data_.rbegin(); }
const_reverse_iterator rend() const { return data_.rend(); }
size_type size() const { return data_.size(); }
template <class Manip>
value_list_ba<Row, Manip> value_list(const char* d = ",",
Manip m = quote) const
{
return value_list_ba<Row, Manip>(*this, d, m);
}
template <class Manip>
value_list_b<Row, Manip> value_list(const char *d,
const std::vector<bool>& vb, Manip m = quote) const
{
return value_list_b<Row, Manip>(*this, vb, d, m);
}
value_list_b<Row, quote_type0> value_list(
const std::vector<bool> &vb) const
{
return value_list_b<Row, quote_type0>(*this, vb, ",", quote);
}
template <class Manip>
value_list_b<Row, Manip> value_list(const char *d, Manip m,
bool t0, bool t1 = false, bool t2 = false, bool t3 = false,
bool t4 = false, bool t5 = false, bool t6 = false,
bool t7 = false, bool t8 = false, bool t9 = false,
bool ta = false, bool tb = false, bool tc = false) const
{
std::vector<bool> vb;
create_vector(size(), vb, t0, t1, t2, t3, t4, t5, t6,
t7, t8, t9, ta, tb, tc);
return value_list_b<Row, Manip>(*this, vb, d, m);
}
value_list_b <Row, quote_type0>
value_list(const char *d, bool t0, bool t1 = false, bool t2 = false,
bool t3 = false, bool t4 = false, bool t5 = false,
bool t6 = false, bool t7 = false, bool t8 = false,
bool t9 = false, bool ta = false, bool tb = false,
bool tc = false) const
{
std::vector<bool> vb;
create_vector(size(), vb, t0, t1, t2, t3, t4, t5, t6,
t7, t8, t9, ta, tb, tc);
return value_list_b<Row, quote_type0>(*this, vb, d, quote);
}
value_list_b<Row, quote_type0> value_list(bool t0,
bool t1 = false, bool t2 = false, bool t3 = false,
bool t4 = false, bool t5 = false, bool t6 = false,
bool t7 = false, bool t8 = false, bool t9 = false,
bool ta = false, bool tb = false, bool tc = false) const
{
std::vector<bool> vb;
create_vector(size(), vb, t0, t1, t2, t3, t4, t5, t6,
t7, t8, t9, ta, tb, tc);
return value_list_b<Row, quote_type0>(*this, vb, ",", quote);
}
template <class Manip>
value_list_b<Row, Manip> value_list(const char *d, Manip m,
std::string s0, std::string s1 = "", std::string s2 = "",
std::string s3 = "", std::string s4 = "",
std::string s5 = "", std::string s6 = "",
std::string s7 = "", std::string s8 = "",
std::string s9 = "", std::string sa = "",
std::string sb = "", std::string sc = "") const
{
std::vector<bool> vb;
create_vector(*this, vb, s0, s1, s2, s3, s4, s5, s6, s7, s8,
s9, sa, sb, sc);
return value_list_b<Row, Manip>(*this, vb, d, m);
}
value_list_b<Row, quote_type0> value_list(
const char *d,
std::string s0, std::string s1 = "", std::string s2 = "",
std::string s3 = "", std::string s4 = "",
std::string s5 = "", std::string s6 = "",
std::string s7 = "", std::string s8 = "",
std::string s9 = "", std::string sa = "",
std::string sb = "", std::string sc = "") const
{
std::vector<bool> vb;
create_vector(*this, vb, s0, s1, s2, s3, s4, s5, s6, s7, s8,
s9, sa, sb, sc);
return value_list_b<Row, quote_type0>(*this, vb, d, quote);
}
value_list_b<Row, quote_type0> value_list(
std::string s0,
std::string s1 = "", std::string s2 = "",
std::string s3 = "", std::string s4 = "",
std::string s5 = "", std::string s6 = "",
std::string s7 = "", std::string s8 = "",
std::string s9 = "", std::string sa = "",
std::string sb = "", std::string sc = "") const
{
std::vector<bool> vb;
create_vector(*this, vb, s0, s1, s2, s3, s4, s5, s6, s7, s8,
s9, sa, sb, sc);
return value_list_b<Row, quote_type0>(*this, vb, ",", quote);
}
private:
list_type data_;
RefCountedPointer<FieldNames> field_names_;
bool initialized_;
};
} // end namespace mysqlpp
#endif // !defined(MYSQLPP_ROW_H)
mysqlpp::OptionalExceptions
Interface allowing a class to have optional exceptions.
Definition: noexceptions.h:72
mysqlpp::RefCountedPointer
Creates an object that acts as a reference-counted pointer to another object.
Definition: refcounted.h:83
mysqlpp::ResultBase
Base class for StoreQueryResult and UseQueryResult.
Definition: result.h:111
mysqlpp::Row
Manages rows from a result set.
Definition: row.h:64
mysqlpp::Row::~Row
~Row()
Destroy object.
Definition: row.h:141
mysqlpp::Row::reverse_iterator
const_reverse_iterator reverse_iterator
mutable reverse iterator type
Definition: row.h:108
mysqlpp::Row::list_type
std::vector< String > list_type
type of our internal data list
Definition: row.h:77
mysqlpp::Row::rbegin
const_reverse_iterator rbegin() const
Return reverse iterator pointing to first element in the container.
Definition: row.h:354
mysqlpp::Row::iterator
const_iterator iterator
iterator type
Definition: row.h:97
mysqlpp::Row::const_reverse_iterator
list_type::const_reverse_iterator const_reverse_iterator
const reverse iterator type
Definition: row.h:86
mysqlpp::Row::value_list
value_list_b< Row, quote_type0 > value_list(std::string s0, std::string s1="", std::string s2="", std::string s3="", std::string s4="", std::string s5="", std::string s6="", std::string s7="", std::string s8="", std::string s9="", std::string sa="", std::string sb="", std::string sc="") const
Get a list of the values in this row.
Definition: row.h:508
mysqlpp::Row::size_type
list_type::size_type size_type
type of returned sizes
Definition: row.h:111
mysqlpp::Row::value_list
value_list_ba< Row, Manip > value_list(const char *d=",", Manip m=quote) const
Get a list of the values in this row.
Definition: row.h:372
mysqlpp::Row::begin
const_iterator begin() const
Return a const iterator pointing to first element in the container.
Definition: row.h:154
mysqlpp::Row::value_type
list_type::value_type value_type
type of data in container
Definition: row.h:114
mysqlpp::Row::Row
Row(const Row &r)
Copy constructor.
Definition: row.h:123
mysqlpp::Row::value_list
value_list_b< Row, Manip > value_list(const char *d, Manip m, bool t0, bool t1=false, bool t2=false, bool t3=false, bool t4=false, bool t5=false, bool t6=false, bool t7=false, bool t8=false, bool t9=false, bool ta=false, bool tb=false, bool tc=false) const
Get a list of the values in this row.
Definition: row.h:411
mysqlpp::Row::difference_type
list_type::difference_type difference_type
type for index differences
Definition: row.h:89
mysqlpp::Row::const_reference
list_type::const_reference const_reference
constant reference type
Definition: row.h:83
mysqlpp::Row::value_list
value_list_b< Row, quote_type0 > value_list(const std::vector< bool > &vb) const
Get a list of the values in this row.
Definition: row.h:398
mysqlpp::Row::value_list
value_list_b< Row, Manip > value_list(const char *d, Manip m, std::string s0, std::string s1="", std::string s2="", std::string s3="", std::string s4="", std::string s5="", std::string s6="", std::string s7="", std::string s8="", std::string s9="", std::string sa="", std::string sb="", std::string sc="") const
Get a list of the values in this row.
Definition: row.h:467
mysqlpp::Row::end
const_iterator end() const
Return a const iterator pointing to one past the last element in the container.
Definition: row.h:161
mysqlpp::Row::Row
Row()
Default constructor.
Definition: row.h:117
mysqlpp::Row::size
size_type size() const
Get the number of fields in the row.
Definition: row.h:361
mysqlpp::Row::const_iterator
list_type::const_iterator const_iterator
constant iterator type
Definition: row.h:80
mysqlpp::Row::value_list
value_list_b< Row, Manip > value_list(const char *d, const std::vector< bool > &vb, Manip m=quote) const
Get a list of the values in this row.
Definition: row.h:385
mysqlpp::Row::back
const_reference back() const
Get a reference to the last element of the vector.
Definition: row.h:150
mysqlpp::Row::value_list
value_list_b< Row, quote_type0 > value_list(const char *d, std::string s0, std::string s1="", std::string s2="", std::string s3="", std::string s4="", std::string s5="", std::string s6="", std::string s7="", std::string s8="", std::string s9="", std::string sa="", std::string sb="", std::string sc="") const
Get a list of the values in this row.
Definition: row.h:487
mysqlpp::Row::value_list
value_list_b< Row, quote_type0 > value_list(const char *d, bool t0, bool t1=false, bool t2=false, bool t3=false, bool t4=false, bool t5=false, bool t6=false, bool t7=false, bool t8=false, bool t9=false, bool ta=false, bool tb=false, bool tc=false) const
Get a list of the values in this row.
Definition: row.h:430
mysqlpp::Row::front
const_reference front() const
Get a reference to the first element of the vector.
Definition: row.h:292
mysqlpp::Row::max_size
size_type max_size() const
Return maximum number of elements that can be stored in container without resizing.
Definition: row.h:296
mysqlpp::Row::value_list
value_list_b< Row, quote_type0 > value_list(bool t0, bool t1=false, bool t2=false, bool t3=false, bool t4=false, bool t5=false, bool t6=false, bool t7=false, bool t8=false, bool t9=false, bool ta=false, bool tb=false, bool tc=false) const
Get a list of the values in this row.
Definition: row.h:448
mysqlpp::Row::reference
const_reference reference
reference type
Definition: row.h:102
mysqlpp::Row::rend
const_reverse_iterator rend() const
Return reverse iterator pointing to one past the last element in the container.
Definition: row.h:358
mysqlpp::Row::empty
bool empty() const
Returns true if container is empty.
Definition: row.h:157
common.h
This file includes top-level definitions for use both internal to the library, and outside it....
mysqlpp::quote
@ quote
insert into a Query stream to single-quote and escape next item
Definition: manip.h:72
mystring.h
Declares String class, MySQL++'s generic std::string-like class, used for holding data received from ...
noexceptions.h
Declares interface that allows exceptions to be optional.
refcounted.h
Declares the RefCountedPointer template.
mysqlpp::equal_list_ba
Holds two lists of items, typically used to construct a SQL "equals clause".
Definition: vallist.h:61
mysqlpp::value_list_b
Same as value_list_ba, plus the option to have some elements of the list suppressed.
Definition: vallist.h:227
mysqlpp::value_list_ba
Holds a list of items, typically used to construct a SQL "value list".
Definition: vallist.h:187
vallist.h
Declares templates for holding lists of values.
mysqlpp::equal_list
equal_list_ba< Seq1, Seq2, do_nothing_type0 > equal_list(const Seq1 &s1, const Seq2 &s2, const char *d=",", const char *e=" = ")
Constructs an equal_list_ba.
Definition: vallist.h:553