MySQL++  3.3.0
row.h
Go to the documentation of this file.
1 
4 /***********************************************************************
5  Copyright (c) 1998 by Kevin Atkinson, (c) 1999-2001 by MySQL AB, and
6  (c) 2004-2008 by Educational Technology Resources, Inc. Others may
7  also hold copyrights on code in this file. See the CREDITS.txt file
8  in the top directory of the distribution for details.
9 
10  This file is part of MySQL++.
11 
12  MySQL++ is free software; you can redistribute it and/or modify it
13  under the terms of the GNU Lesser General Public License as published
14  by the Free Software Foundation; either version 2.1 of the License, or
15  (at your option) any later version.
16 
17  MySQL++ is distributed in the hope that it will be useful, but WITHOUT
18  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
20  License for more details.
21 
22  You should have received a copy of the GNU Lesser General Public
23  License along with MySQL++; if not, write to the Free Software
24  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
25  USA
26 ***********************************************************************/
27 
28 #if !defined(MYSQLPP_ROW_H)
29 #define MYSQLPP_ROW_H
30 
31 #include "common.h"
32 
33 #include "mystring.h"
34 #include "noexceptions.h"
35 #include "refcounted.h"
36 #include "vallist.h"
37 
38 #include <vector>
39 #include <string>
40 
41 namespace mysqlpp {
42 
43 #if !defined(DOXYGEN_IGNORE)
44 // Make Doxygen ignore this
45 class FieldNames;
46 class MYSQLPP_EXPORT ResultBase;
47 #endif
48 
62 
63 class MYSQLPP_EXPORT Row : public OptionalExceptions
64 {
65 private:
70  typedef bool Row::*private_bool_type;
71 
72 public:
77  typedef std::vector<String> list_type;
78 
80  typedef list_type::const_iterator const_iterator;
81 
83  typedef list_type::const_reference const_reference;
84 
86  typedef list_type::const_reverse_iterator const_reverse_iterator;
87 
89  typedef list_type::difference_type difference_type;
90 
98 
103 
109 
111  typedef list_type::size_type size_type;
112 
114  typedef list_type::value_type value_type;
115 
117  Row() :
118  initialized_(false)
119  {
120  }
121 
123  Row(const Row& r) :
125  data_(r.data_.begin(), r.data_.end()),
126  field_names_(r.field_names_),
127  initialized_(r.initialized_)
128  {
129  }
130 
137  Row(MYSQL_ROW row, const ResultBase* res,
138  const unsigned long* lengths, bool te = true);
139 
141  ~Row() { }
142 
147  const_reference at(size_type i) const;
148 
150  const_reference back() const { return data_.back(); }
151 
154  const_iterator begin() const { return data_.begin(); }
155 
157  bool empty() const { return data_.empty(); }
158 
161  const_iterator end() const { return data_.end(); }
162 
169  equal_list(const char* d = ",", const char* e = " = ") const;
170 
191  template <class Manip>
193  const char* e, Manip m) const;
194 
200  field_list(const char* d = ",") const;
201 
208  template <class Manip>
209  value_list_ba<FieldNames, Manip> field_list(const char* d,
210  Manip m) const;
211 
220  template <class Manip>
221  value_list_b<FieldNames, Manip> field_list(const char* d, Manip m,
222  const std::vector<bool>& vb) const;
223 
234  const char* d, const std::vector<bool>& vb) const;
235 
244  const std::vector<bool>& vb) const;
245 
253  template <class Manip>
254  value_list_b<FieldNames, Manip> field_list(const char *d, Manip m,
255  bool t0,
256  bool t1 = false, bool t2 = false, bool t3 = false,
257  bool t4 = false, bool t5 = false, bool t6 = false,
258  bool t7 = false, bool t8 = false, bool t9 = false,
259  bool ta = false, bool tb = false, bool tc = false) const;
260 
269  const char *d, bool t0,
270  bool t1 = false, bool t2 = false, bool t3 = false,
271  bool t4 = false, bool t5 = false, bool t6 = false,
272  bool t7 = false, bool t8 = false, bool t9 = false,
273  bool ta = false, bool tb = false, bool tc = false) const;
274 
282  bool t0,
283  bool t1 = false, bool t2 = false, bool t3 = false,
284  bool t4 = false, bool t5 = false, bool t6 = false,
285  bool t7 = false, bool t8 = false, bool t9 = false,
286  bool ta = false, bool tb = false, bool tc = false) const;
287 
289  size_type field_num(const char* name) const;
290 
292  const_reference front() const { return data_.front(); }
293 
296  size_type max_size() const { return data_.max_size(); }
297 
299  Row& operator =(const Row& rhs)
300  {
301  data_.assign(rhs.data_.begin(), rhs.data_.end());
302  field_names_.assign(rhs.field_names_);
303  initialized_ = rhs.initialized_;
304  return *this;
305  }
306 
314  const_reference operator [](const char* field) const;
315 
327  const_reference operator [](int i) const
328  { return at(static_cast<size_type>(i)); }
329 
347  operator private_bool_type() const
348  {
349  return data_.size() && initialized_ ? &Row::initialized_ : 0;
350  }
351 
354  const_reverse_iterator rbegin() const { return data_.rbegin(); }
355 
358  const_reverse_iterator rend() const { return data_.rend(); }
359 
361  size_type size() const { return data_.size(); }
362 
371  template <class Manip>
373  Manip m = quote) const
374  {
375  return value_list_ba<Row, Manip>(*this, d, m);
376  }
377 
384  template <class Manip>
386  const std::vector<bool>& vb, Manip m = quote) const
387  {
388  return value_list_b<Row, Manip>(*this, vb, d, m);
389  }
390 
399  const std::vector<bool> &vb) const
400  {
401  return value_list_b<Row, quote_type0>(*this, vb, ",", quote);
402  }
403 
410  template <class Manip>
411  value_list_b<Row, Manip> value_list(const char *d, Manip m,
412  bool t0, bool t1 = false, bool t2 = false, bool t3 = false,
413  bool t4 = false, bool t5 = false, bool t6 = false,
414  bool t7 = false, bool t8 = false, bool t9 = false,
415  bool ta = false, bool tb = false, bool tc = false) const
416  {
417  std::vector<bool> vb;
418  create_vector(size(), vb, t0, t1, t2, t3, t4, t5, t6,
419  t7, t8, t9, ta, tb, tc);
420  return value_list_b<Row, Manip>(*this, vb, d, m);
421  }
422 
430  value_list(const char *d, bool t0, bool t1 = false, bool t2 = false,
431  bool t3 = false, bool t4 = false, bool t5 = false,
432  bool t6 = false, bool t7 = false, bool t8 = false,
433  bool t9 = false, bool ta = false, bool tb = false,
434  bool tc = false) const
435  {
436  std::vector<bool> vb;
437  create_vector(size(), vb, t0, t1, t2, t3, t4, t5, t6,
438  t7, t8, t9, ta, tb, tc);
439  return value_list_b<Row, quote_type0>(*this, vb, d, quote);
440  }
441 
449  bool t1 = false, bool t2 = false, bool t3 = false,
450  bool t4 = false, bool t5 = false, bool t6 = false,
451  bool t7 = false, bool t8 = false, bool t9 = false,
452  bool ta = false, bool tb = false, bool tc = false) const
453  {
454  std::vector<bool> vb;
455  create_vector(size(), vb, t0, t1, t2, t3, t4, t5, t6,
456  t7, t8, t9, ta, tb, tc);
457  return value_list_b<Row, quote_type0>(*this, vb, ",", quote);
458  }
459 
466  template <class Manip>
467  value_list_b<Row, Manip> value_list(const char *d, Manip m,
468  std::string s0, std::string s1 = "", std::string s2 = "",
469  std::string s3 = "", std::string s4 = "",
470  std::string s5 = "", std::string s6 = "",
471  std::string s7 = "", std::string s8 = "",
472  std::string s9 = "", std::string sa = "",
473  std::string sb = "", std::string sc = "") const
474  {
475  std::vector<bool> vb;
476  create_vector(*this, vb, s0, s1, s2, s3, s4, s5, s6, s7, s8,
477  s9, sa, sb, sc);
478  return value_list_b<Row, Manip>(*this, vb, d, m);
479  }
480 
488  const char *d,
489  std::string s0, std::string s1 = "", std::string s2 = "",
490  std::string s3 = "", std::string s4 = "",
491  std::string s5 = "", std::string s6 = "",
492  std::string s7 = "", std::string s8 = "",
493  std::string s9 = "", std::string sa = "",
494  std::string sb = "", std::string sc = "") const
495  {
496  std::vector<bool> vb;
497  create_vector(*this, vb, s0, s1, s2, s3, s4, s5, s6, s7, s8,
498  s9, sa, sb, sc);
499  return value_list_b<Row, quote_type0>(*this, vb, d, quote);
500  }
501 
509  std::string s0,
510  std::string s1 = "", std::string s2 = "",
511  std::string s3 = "", std::string s4 = "",
512  std::string s5 = "", std::string s6 = "",
513  std::string s7 = "", std::string s8 = "",
514  std::string s9 = "", std::string sa = "",
515  std::string sb = "", std::string sc = "") const
516  {
517  std::vector<bool> vb;
518  create_vector(*this, vb, s0, s1, s2, s3, s4, s5, s6, s7, s8,
519  s9, sa, sb, sc);
520  return value_list_b<Row, quote_type0>(*this, vb, ",", quote);
521  }
522 
523 private:
524  list_type data_;
525  RefCountedPointer<FieldNames> field_names_;
526  bool initialized_;
527 };
528 
529 } // end namespace mysqlpp
530 
531 #endif // !defined(MYSQLPP_ROW_H)
Interface allowing a class to have optional exceptions.
Definition: noexceptions.h:72
Creates an object that acts as a reference-counted pointer to another object.
Definition: refcounted.h:83
Base class for StoreQueryResult and UseQueryResult.
Definition: result.h:111
Manages rows from a result set.
Definition: row.h:64
~Row()
Destroy object.
Definition: row.h:141
const_reverse_iterator reverse_iterator
mutable reverse iterator type
Definition: row.h:108
std::vector< String > list_type
type of our internal data list
Definition: row.h:77
const_reverse_iterator rbegin() const
Return reverse iterator pointing to first element in the container.
Definition: row.h:354
const_iterator iterator
iterator type
Definition: row.h:97
list_type::const_reverse_iterator const_reverse_iterator
const reverse iterator type
Definition: row.h:86
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
list_type::size_type size_type
type of returned sizes
Definition: row.h:111
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
const_iterator begin() const
Return a const iterator pointing to first element in the container.
Definition: row.h:154
list_type::value_type value_type
type of data in container
Definition: row.h:114
Row(const Row &r)
Copy constructor.
Definition: row.h:123
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
list_type::difference_type difference_type
type for index differences
Definition: row.h:89
list_type::const_reference const_reference
constant reference type
Definition: row.h:83
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
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
const_iterator end() const
Return a const iterator pointing to one past the last element in the container.
Definition: row.h:161
Row()
Default constructor.
Definition: row.h:117
size_type size() const
Get the number of fields in the row.
Definition: row.h:361
list_type::const_iterator const_iterator
constant iterator type
Definition: row.h:80
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
const_reference back() const
Get a reference to the last element of the vector.
Definition: row.h:150
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
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
const_reference front() const
Get a reference to the first element of the vector.
Definition: row.h:292
size_type max_size() const
Return maximum number of elements that can be stored in container without resizing.
Definition: row.h:296
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
const_reference reference
reference type
Definition: row.h:102
const_reverse_iterator rend() const
Return reverse iterator pointing to one past the last element in the container.
Definition: row.h:358
bool empty() const
Returns true if container is empty.
Definition: row.h:157
This file includes top-level definitions for use both internal to the library, and outside it....
@ quote
insert into a Query stream to single-quote and escape next item
Definition: manip.h:72
Declares String class, MySQL++'s generic std::string-like class, used for holding data received from ...
Declares interface that allows exceptions to be optional.
Declares the RefCountedPointer template.
Holds two lists of items, typically used to construct a SQL "equals clause".
Definition: vallist.h:61
Same as value_list_ba, plus the option to have some elements of the list suppressed.
Definition: vallist.h:227
Holds a list of items, typically used to construct a SQL "value list".
Definition: vallist.h:187
Declares templates for holding lists of values.
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