MySQL++ Reference Manual

- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Hierarchy
- Class Members

Public Types | Public Member Functions | List of all members
mysqlpp::Row Class Reference

Manages rows from a result set. More...

`#include <row.h>`

Inheritance diagram for mysqlpp::Row:
[legend]
Collaboration diagram for mysqlpp::Row:
[legend]

## Public Types
typedef std::vector< String > | list_type
| type of our internal data list More...
typedef list_type::const_iterator | const_iterator
| constant iterator type
typedef list_type::const_reference | const_reference
| constant reference type
typedef list_type::const_reverse_iterator | const_reverse_iterator
| const reverse iterator type
typedef list_type::difference_type | difference_type
| type for index differences
typedef const_iterator | iterator
| iterator type More...
typedef const_reference | reference
| reference type More...
typedef const_reverse_iterator | reverse_iterator
| mutable reverse iterator type More...
typedef list_type::size_type | size_type
| type of returned sizes
typedef list_type::value_type | value_type
| type of data in container

## Public Member Functions
| Row ()
| Default constructor.
| Row (const Row &r)
| Copy constructor.
| Row (MYSQL_ROW row, const ResultBase *res, const unsigned long *lengths, bool te=true)
| Create a row object. More...
| ~Row ()
| Destroy object.
const_reference | at (size_type i) const
| Get a const reference to the field given its index. More...
const_reference | back () const
| Get a reference to the last element of the vector.
const_iterator | begin () const
| Return a const iterator pointing to first element in the container.
bool | empty () const
| Returns true if container is empty.
const_iterator | end () const
| Return a const iterator pointing to one past the last element in the container.
equal_list_ba< FieldNames, Row, quote_type0 > | equal_list (const char *d=",", const char *e=" = ") const
| Get an "equal list" of the fields and values in this row. More...
template<class Manip >
equal_list_ba< FieldNames, Row, Manip > | equal_list (const char *d, const char *e, Manip m) const
| Get an "equal list" of the fields and values in this row. More...
value_list_ba< FieldNames, do_nothing_type0 > | field_list (const char *d=",") const
| Get a list of the field names in this row. More...
template<class Manip >
value_list_ba< FieldNames, Manip > | field_list (const char *d, Manip m) const
| Get a list of the field names in this row. More...
template<class Manip >
value_list_b< FieldNames, Manip > | field_list (const char *d, Manip m, const std::vector< bool > &vb) const
| Get a list of the field names in this row. More...
value_list_b< FieldNames, quote_type0 > | field_list (const char *d, const std::vector< bool > &vb) const
| Get a list of the field names in this row. More...
value_list_b< FieldNames, quote_type0 > | field_list (const std::vector< bool > &vb) const
| Get a list of the field names in this row. More...
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
| Get a list of the field names in this row. More...
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
| Get a list of the field names in this row. More...
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
| Get a list of the field names in this row. More...
size_type | field_num (const char *name) const
| Returns a field's index given its name.
const_reference | front () const
| Get a reference to the first element of the vector.
size_type | max_size () const
| Return maximum number of elements that can be stored in container without resizing.
Row & | operator= (const Row &rhs)
| Assignment operator.
const_reference | operator[] (const char *field) const
| Get the value of a field given its name. More...
const_reference | operator[] (int i) const
| Get the value of a field given its index. More...
| operator private_bool_type () const
| Returns true if row object was fully initialized and has data. More...
const_reverse_iterator | rbegin () const
| Return reverse iterator pointing to first element in the container.
const_reverse_iterator | rend () const
| Return reverse iterator pointing to one past the last element in the container.
size_type | size () const
| Get the number of fields in the row.
template<class Manip >
value_list_ba< Row, Manip > | value_list (const char *d=",", Manip m=quote) const
| Get a list of the values in this row. More...
template<class Manip >
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. More...
value_list_b< Row, quote_type0 > | value_list (const std::vector< bool > &vb) const
| Get a list of the values in this row. More...
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
| Get a list of the values in this row. More...
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. More...
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. More...
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
| Get a list of the values in this row. More...
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. More...
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. More...
Public Member Functions inherited from mysqlpp::OptionalExceptions
| OptionalExceptions (bool e=true)
| Default constructor. More...
virtual | ~OptionalExceptions ()
| Destroy object.
void | enable_exceptions () const
| Enable exceptions from the object.
void | disable_exceptions () const
| Disable exceptions from the object.
bool | throw_exceptions () const
| Returns true if exceptions are enabled.

## Additional Inherited Members
Protected Member Functions inherited from mysqlpp::OptionalExceptions
void | set_exceptions (bool e) const
| Sets the exception state to a particular value. More...

## Detailed Description

Manages rows from a result set.

This class is like an extended version of a `const` `std::vector` of mysqlpp::String. It adds stuff for populating the vector. As for why it's `const`, what would it mean to modify a Row? If we ever did support such semantics, it should probably actually modify the database. We can't do that if we just derive from std::vector.

Not that we could derive from std::vector even if we wanted to: `vector::operator[](size_type)` would interfere with our `operator`[](const `char*`). We can avoid this only by maintaining our own public inteface independent of that of `vector`.

## Member Typedef Documentation

typedef const_iterator mysqlpp::Row::iterator

iterator type

Note that this is just an alias for the const iterator. Row is immutable, but people are in the habit of saying 'iterator' even when they don't intend to use the iterator to modify the container, so we provide this as a convenience.

typedef std::vector<String> mysqlpp::Row::list_type

type of our internal data list

This is public because all other typedefs we have for mirroring std::vector's public interface depend on it.

typedef const_reference mysqlpp::Row::reference

reference type

See Also
  iterator for justification for this const_reference alias

typedef const_reverse_iterator mysqlpp::Row::reverse_iterator

mutable reverse iterator type

See Also
  iterator for justification for this const_reverse_iterator alias

## Constructor & Destructor Documentation

mysqlpp::Row::Row | ( | MYSQL_ROW | row,
|  | const ResultBase * | res,
|  | const unsigned long * | lengths,
|  | bool | te = `true`
| ) |  |

Create a row object.

Parameters

  row | MySQL C API row data
  res | result set that the row comes from
  lengths | length of each item in row
  te | if true, throw exceptions on errors

References mysqlpp::ResultBase::field_names(), mysqlpp::ResultBase::field_type(), mysqlpp::ResultBase::num_fields(), and size().

## Member Function Documentation

Row::const_reference mysqlpp::Row::at | ( | size_type | i | ) | const

Get a const reference to the field given its index.

Exceptions

  mysqlpp::BadIndex | if the row is not initialized or there are less than `i` fields in the row.

References size().

Referenced by operator[]().

equal_list_ba< FieldNames, Row, quote_type0 > mysqlpp::Row::equal_list | ( | const char * | d = `","`,
|  | const char * | e = `" = "`
| ) |  | const

Get an "equal list" of the fields and values in this row.

When inserted into a C++ stream, the delimiter 'd' will be used between the items, " = " is the relationship operator, and items will be quoted and escaped.

template<class Manip >

equal_list_ba< FieldNames, Row, Manip > mysqlpp::Row::equal_list | ( | const char * | d,
|  | const char * | e,
|  | Manip | m
| ) |  | const

Get an "equal list" of the fields and values in this row.

This method's parameters govern how the returned list will behave when you insert it into a C++ stream:

Parameters

  d | delimiter to use between items
  e | the operator to use between elements
  m | the manipulator to use for each element

For example, if d is ",", e is " = ", and m is the quote manipulator, then the field and value lists (a, b) (c, d'e) will yield an equal list that gives the following when inserted into a C++ stream:

* 'a' = 'c', 'b' = 'd''e'
*

Notice how the single quote was 'escaped' in the SQL way to avoid a syntax error.

value_list_ba< FieldNames, do_nothing_type0 > mysqlpp::Row::field_list | ( | const char * | d = `","` | ) | const

Get a list of the field names in this row.

When inserted into a C++ stream, the delimiter 'd' will be used between the items, and no manipulator will be used on the items.

template<class Manip >

value_list_ba< FieldNames, Manip > mysqlpp::Row::field_list | ( | const char * | d,
|  | Manip | m
| ) |  | const

Get a list of the field names in this row.

Parameters

  d | delimiter to place between the items when the list is inserted into a C++ stream
  m | manipulator to use before each item when the list is inserted into a C++ stream

template<class Manip >

value_list_b< FieldNames, Manip > mysqlpp::Row::field_list | ( | const char * | d,
|  | Manip | m,
|  | const std::vector< bool > & | vb
| ) |  | const

Get a list of the field names in this row.

Parameters

  d | delimiter to place between the items when the list is inserted into a C++ stream
  m | manipulator to use before each item when the list is inserted into a C++ stream
  vb | for each true item in this list, add that field name to the returned list; ignore the others

value_list_b< FieldNames, quote_type0 > mysqlpp::Row::field_list | ( | const char * | d,
|  | const std::vector< bool > & | vb
| ) |  | const

Get a list of the field names in this row.

Parameters

  d | delimiter to place between the items when the list is inserted into a C++ stream
  vb | for each true item in this list, add that field name to the returned list; ignore the others

Field names will be quoted and escaped when inserted into a C++ stream.

value_list_b< FieldNames, quote_type0 > mysqlpp::Row::field_list | ( | const std::vector< bool > & | vb | ) | const

Get a list of the field names in this row.

Parameters

  vb | for each true item in this list, add that field name to the returned list; ignore the others

Field names will be quoted and escaped when inserted into a C++ stream, and a comma will be placed between them as a delimiter.

template<class Manip >

value_list_b< FieldNames, Manip > mysqlpp::Row::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

Get a list of the field names in this row.

For each true parameter, the field name in that position within the row is added to the returned list. When the list is inserted into a C++ stream, the delimiter 'd' will be placed between the items as a delimiter, and the manipulator 'm' used before each item.

value_list_b< FieldNames, quote_type0 > mysqlpp::Row::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

Get a list of the field names in this row.

For each true parameter, the field name in that position within the row is added to the returned list. When the list is inserted into a C++ stream, the delimiter 'd' will be placed between the items as a delimiter, and the items will be quoted and escaped.

value_list_b< FieldNames, quote_type0 > mysqlpp::Row::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

Get a list of the field names in this row.

For each true parameter, the field name in that position within the row is added to the returned list. When the list is inserted into a C++ stream, a comma will be placed between the items as a delimiter, and the items will be quoted and escaped.

mysqlpp::Row::operator private_bool_type | ( |  | ) | const
| inline

Returns true if row object was fully initialized and has data.

This operator lets you use Row in bool context, which lets you do things like tell when you've run off the end of a "use" query's result set:

* Query q("....");
* if (UseQueryResult res = q.use()) {
* // Can use 'res', query succeeded
* while (Row row = res.fetch_row()) {
* // Retreived another row in the result set, can use 'row'
* }
* }
*

const Row::value_type & mysqlpp::Row::operator[] | ( | const char * | field | ) | const

Get the value of a field given its name.

If the field does not exist in this row, we throw a BadFieldName exception if exceptions are enabled, or an empty row if not. An empty row tests as false in bool context.

This operator is fairly inefficient. operator[](int) is faster.

References at(), empty(), field_num(), size(), and mysqlpp::OptionalExceptions::throw_exceptions().

const_reference mysqlpp::Row::operator[] | ( | int | i | ) | const
| inline

Get the value of a field given its index.

This function is just syntactic sugar, wrapping the at() method.

It's critical that the parameter type be `int`, not `size_type`, because it will interfere with the `const` `char*` overload otherwise. row[0] is ambiguous when there isn't an int overload.

Exceptions

  mysqlpp::BadIndex | if the row is not initialized or there are less than `i` fields in the row.

template<class Manip >

value_list_ba<Row, Manip> mysqlpp::Row::value_list | ( | const char * | d = `","`,
|  | Manip | m = `quote`
| ) |  | const
| inline

Get a list of the values in this row.

When inserted into a C++ stream, the delimiter 'd' will be used between the items, and the quoting and escaping rules will be set by the manipulator 'm' you choose.

Parameters

  d | delimiter to use between values
  m | manipulator to use when inserting values into a stream

template<class Manip >

value_list_b<Row, Manip> mysqlpp::Row::value_list | ( | const char * | d,
|  | const std::vector< bool > & | vb,
|  | Manip | m = `quote`
| ) |  | const
| inline

Get a list of the values in this row.

Parameters

  d | delimiter to use between values
  vb | for each true item in this list, add that value to the returned list; ignore the others
  m | manipulator to use when inserting values into a stream

value_list_b<Row, quote_type0> mysqlpp::Row::value_list | ( | const std::vector< bool > & | vb | ) | const
| inline

Get a list of the values in this row.

Parameters

  vb | for each true item in this list, add that value to the returned list; ignore the others

Items will be quoted and escaped when inserted into a C++ stream, and a comma will be used as a delimiter between the items.

template<class Manip >

value_list_b<Row, Manip> mysqlpp::Row::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
| inline

Get a list of the values in this row.

For each true parameter, the value in that position within the row is added to the returned list. When the list is inserted into a C++ stream, the delimiter 'd' will be placed between the items, and the manipulator 'm' used before each item.

value_list_b<Row, quote_type0> mysqlpp::Row::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
| inline

Get a list of the values in this row.

For each true parameter, the value in that position within the row is added to the returned list. When the list is inserted into a C++ stream, the delimiter 'd' will be placed between the items, and items will be quoted and escaped.

value_list_b<Row, quote_type0> mysqlpp::Row::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
| inline

Get a list of the values in this row.

For each true parameter, the value in that position within the row is added to the returned list. When the list is inserted into a C++ stream, the a comma will be placed between the items, as a delimiter, and items will be quoted and escaped.

template<class Manip >

value_list_b<Row, Manip> mysqlpp::Row::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
| inline

Get a list of the values in this row.

The 's' parameters name the fields that will be added to the returned list. When inserted into a C++ stream, the delimiter 'd' will be placed between the items, and the manipulator 'm' will be inserted before each item.

value_list_b<Row, quote_type0> mysqlpp::Row::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
| inline

Get a list of the values in this row.

The 's' parameters name the fields that will be added to the returned list. When inserted into a C++ stream, the delimiter 'd' will be placed between the items, and items will be quoted and escaped.

value_list_b<Row, quote_type0> mysqlpp::Row::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
| inline

Get a list of the values in this row.

The 's' parameters name the fields that will be added to the returned list. When inserted into a C++ stream, a comma will be placed between the items as a delimiter, and items will be quoted and escaped.

The documentation for this class was generated from the following files:

- row.h
- row.cpp