- Main Page
- Classes
- Files

- File List
- File Members

# row.h

Go to the documentation of this file.

    00001
    00002
    00003
    00004 /***********************************************************************
    00005  Copyright (c) 1998 by Kevin Atkinson, (c) 1999-2001 by MySQL AB, and
    00006  (c) 2004-2007 by Educational Technology Resources, Inc.  Others may
    00007  also hold copyrights on code in this file.  See the CREDITS file in
    00008  the top directory of the distribution for details.
    00009
    00010  This file is part of MySQL++.
    00011
    00012  MySQL++ is free software; you can redistribute it and/or modify it
    00013  under the terms of the GNU Lesser General Public License as published
    00014  by the Free Software Foundation; either version 2.1 of the License, or
    00015  (at your option) any later version.
    00016
    00017  MySQL++ is distributed in the hope that it will be useful, but WITHOUT
    00018  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    00019  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
    00020  License for more details.
    00021
    00022  You should have received a copy of the GNU Lesser General Public
    00023  License along with MySQL++; if not, write to the Free Software
    00024  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
    00025  USA
    00026 ***********************************************************************/
    00027
    00028 #if !defined(MYSQLPP_ROW_H)
    00029 #define MYSQLPP_ROW_H
    00030
    00031 #include "common.h"
    00032
    00033 #include "mystring.h"
    00034 #include "noexceptions.h"
    00035 #include "refcounted.h"
    00036 #include "vallist.h"
    00037
    00038 #include <vector>
    00039 #include <string>
    00040
    00041 namespace mysqlpp {
    00042
    00043 #if !defined(DOXYGEN_IGNORE)
    00044 // Make Doxygen ignore this
    00045 class FieldNames;
    00046 class MYSQLPP_EXPORT ResultBase;
    00047 #endif
    00048
    00062
    00063 class MYSQLPP_EXPORT Row : public OptionalExceptions
    00064 {
    00065 private:
    00070     typedef bool Row::*private_bool_type;
    00071
    00072 public:
    00077         typedef std::vector<String> list_type;
    00078
    00080         typedef list_type::const_iterator const_iterator;
    00081
    00083         typedef list_type::const_reference const_reference;
    00084
    00086         typedef list_type::const_reverse_iterator const_reverse_iterator;
    00087
    00089         typedef list_type::difference_type difference_type;
    00090
    00097         typedef const_iterator iterator;
    00098
    00102         typedef const_reference reference;
    00103
    00108         typedef const_reverse_iterator reverse_iterator;
    00109
    00111         typedef list_type::size_type size_type;
    00112
    00114         typedef list_type::value_type value_type;
    00115
    00117         Row() :
    00118         initialized_(false)
    00119         {
    00120         }
    00121
    00123         Row(const Row& r) :
    00124         OptionalExceptions(),
    00125         data_(r.data_.begin(), r.data_.end()),
    00126         field_names_(r.field_names_),
    00127         initialized_(r.initialized_)
    00128         {
    00129         }
    00130
    00137         Row(MYSQL_ROW row, const ResultBase* res,
    00138                         const unsigned long* lengths, bool te = true);
    00139
    00141         ~Row() { }
    00142
    00147         const_reference at(size_type i) const { return data_.at(i); }
    00148
    00150         const_reference back() const { return data_.back(); }
    00151
    00154         const_iterator begin() const { return data_.begin(); }
    00155
    00157         bool empty() const { return data_.empty(); }
    00158
    00161         const_iterator end() const { return data_.end(); }
    00162
    00168         equal_list_ba<FieldNames, Row, quote_type0>
    00169                         equal_list(const char* d = ",", const char* e = " = ") const;
    00170
    00191         template <class Manip>
    00192         equal_list_ba<FieldNames, Row, Manip> equal_list(const char* d,
    00193                         const char* e, Manip m) const;
    00194
    00199         value_list_ba<FieldNames, do_nothing_type0>
    00200                         field_list(const char* d = ",") const;
    00201
    00208         template <class Manip>
    00209         value_list_ba<FieldNames, Manip> field_list(const char* d,
    00210                         Manip m) const;
    00211
    00220         template <class Manip>
    00221         value_list_b<FieldNames, Manip> field_list(const char* d, Manip m,
    00222                         const std::vector<bool>& vb) const;
    00223
    00233         value_list_b<FieldNames, quote_type0> field_list(
    00234                         const char* d, const std::vector<bool>& vb) const;
    00235
    00243         value_list_b<FieldNames, quote_type0> field_list(
    00244                         const std::vector<bool>& vb) const;
    00245
    00253         template <class Manip>
    00254         value_list_b<FieldNames, Manip> field_list(const char *d, Manip m,
    00255                         bool t0,
    00256                         bool t1 = false, bool t2 = false, bool t3 = false,
    00257                         bool t4 = false, bool t5 = false, bool t6 = false,
    00258                         bool t7 = false, bool t8 = false, bool t9 = false,
    00259                         bool ta = false, bool tb = false, bool tc = false) const;
    00260
    00268         value_list_b<FieldNames, quote_type0> field_list(
    00269                         const char *d, bool t0,
    00270                         bool t1 = false, bool t2 = false, bool t3 = false,
    00271                         bool t4 = false, bool t5 = false, bool t6 = false,
    00272                         bool t7 = false, bool t8 = false, bool t9 = false,
    00273                         bool ta = false, bool tb = false, bool tc = false) const;
    00274
    00281         value_list_b<FieldNames, quote_type0> field_list(
    00282                         bool t0,
    00283                         bool t1 = false, bool t2 = false, bool t3 = false,
    00284                         bool t4 = false, bool t5 = false, bool t6 = false,
    00285                         bool t7 = false, bool t8 = false, bool t9 = false,
    00286                         bool ta = false, bool tb = false, bool tc = false) const;
    00287
    00289         size_type field_num(const char* name) const;
    00290
    00292         const_reference front() const { return data_.front(); }
    00293
    00296         size_type max_size() const { return data_.max_size(); }
    00297
    00299         Row& operator =(const Row& rhs)
    00300         {
    00301                 data_.assign(rhs.data_.begin(), rhs.data_.end());
    00302                 field_names_.assign(rhs.field_names_);
    00303                 initialized_ = rhs.initialized_;
    00304                 return *this;
    00305         }
    00306
    00313         const_reference operator [](const char* field) const;
    00314
    00323         const_reference operator [](int i) const
    00324                         { return at(static_cast<size_type>(i)); }
    00325
    00343         operator private_bool_type() const
    00344         {
    00345                 return data_.size() && initialized_ ? &Row::initialized_ : 0;
    00346         }
    00347
    00350         const_reverse_iterator rbegin() const { return data_.rbegin(); }
    00351
    00354         const_reverse_iterator rend() const { return data_.rend(); }
    00355
    00357         size_type size() const { return data_.size(); }
    00358
    00367         template <class Manip>
    00368         value_list_ba<Row, Manip> value_list(const char* d = ",",
    00369                         Manip m = quote) const
    00370         {
    00371                 return value_list_ba<Row, Manip>(*this, d, m);
    00372         }
    00373
    00380         template <class Manip>
    00381         value_list_b<Row, Manip> value_list(const char *d,
    00382                         const std::vector<bool>& vb, Manip m = quote) const
    00383         {
    00384                 return value_list_b<Row, Manip>(*this, vb, d, m);
    00385         }
    00386
    00394         value_list_b<Row, quote_type0> value_list(
    00395                         const std::vector<bool> &vb) const
    00396         {
    00397                 return value_list_b<Row, quote_type0>(*this, vb, ",", quote);
    00398         }
    00399
    00406         template <class Manip>
    00407         value_list_b<Row, Manip> value_list(const char *d, Manip m,
    00408                         bool t0, bool t1 = false, bool t2 = false, bool t3 = false,
    00409                         bool t4 = false, bool t5 = false, bool t6 = false,
    00410                         bool t7 = false, bool t8 = false, bool t9 = false,
    00411                         bool ta = false, bool tb = false, bool tc = false) const
    00412         {
    00413                 std::vector<bool> vb;
    00414                 create_vector(size(), vb, t0, t1, t2, t3, t4, t5, t6,
    00415                                 t7, t8, t9, ta, tb, tc);
    00416                 return value_list_b<Row, Manip>(*this, vb, d, m);
    00417         }
    00418
    00425         value_list_b <Row, quote_type0>
    00426         value_list(const char *d, bool t0, bool t1 = false, bool t2 = false,
    00427                         bool t3 = false, bool t4 = false, bool t5 = false,
    00428                         bool t6 = false, bool t7 = false, bool t8 = false,
    00429                         bool t9 = false, bool ta = false, bool tb = false,
    00430                         bool tc = false) const
    00431         {
    00432                 std::vector<bool> vb;
    00433                 create_vector(size(), vb, t0, t1, t2, t3, t4, t5, t6,
    00434                                 t7, t8, t9, ta, tb, tc);
    00435                 return value_list_b<Row, quote_type0>(*this, vb, d, quote);
    00436         }
    00437
    00444         value_list_b<Row, quote_type0> value_list(bool t0,
    00445                         bool t1 = false, bool t2 = false, bool t3 = false,
    00446                         bool t4 = false, bool t5 = false, bool t6 = false,
    00447                         bool t7 = false, bool t8 = false, bool t9 = false,
    00448                         bool ta = false, bool tb = false, bool tc = false) const
    00449         {
    00450                 std::vector<bool> vb;
    00451                 create_vector(size(), vb, t0, t1, t2, t3, t4, t5, t6,
    00452                                 t7, t8, t9, ta, tb, tc);
    00453                 return value_list_b<Row, quote_type0>(*this, vb, ",", quote);
    00454         }
    00455
    00462         template <class Manip>
    00463         value_list_b<Row, Manip> value_list(const char *d, Manip m,
    00464                         std::string s0, std::string s1 = "", std::string s2 = "",
    00465                         std::string s3 = "", std::string s4 = "",
    00466                         std::string s5 = "", std::string s6 = "",
    00467                         std::string s7 = "", std::string s8 = "",
    00468                         std::string s9 = "", std::string sa = "",
    00469                         std::string sb = "", std::string sc = "") const
    00470         {
    00471                 std::vector<bool> vb;
    00472                 create_vector(*this, vb, s0, s1, s2, s3, s4, s5, s6, s7, s8,
    00473                                 s9, sa, sb, sc);
    00474                 return value_list_b<Row, Manip>(*this, vb, d, m);
    00475         }
    00476
    00483         value_list_b<Row, quote_type0> value_list(
    00484                         const char *d,
    00485                         std::string s0, std::string s1 = "", std::string s2 = "",
    00486                         std::string s3 = "", std::string s4 = "",
    00487                         std::string s5 = "", std::string s6 = "",
    00488                         std::string s7 = "", std::string s8 = "",
    00489                         std::string s9 = "", std::string sa = "",
    00490                         std::string sb = "", std::string sc = "") const
    00491         {
    00492                 std::vector<bool> vb;
    00493                 create_vector(*this, vb, s0, s1, s2, s3, s4, s5, s6, s7, s8,
    00494                                 s9, sa, sb, sc);
    00495                 return value_list_b<Row, quote_type0>(*this, vb, d, quote);
    00496         }
    00497
    00504         value_list_b<Row, quote_type0> value_list(
    00505                         std::string s0,
    00506                         std::string s1 = "", std::string s2 = "",
    00507                         std::string s3 = "", std::string s4 = "",
    00508                         std::string s5 = "", std::string s6 = "",
    00509                         std::string s7 = "", std::string s8 = "",
    00510                         std::string s9 = "", std::string sa = "",
    00511                         std::string sb = "", std::string sc = "") const
    00512         {
    00513                 std::vector<bool> vb;
    00514                 create_vector(*this, vb, s0, s1, s2, s3, s4, s5, s6, s7, s8,
    00515                                 s9, sa, sb, sc);
    00516                 return value_list_b<Row, quote_type0>(*this, vb, ",", quote);
    00517         }
    00518
    00519 private:
    00520         list_type data_;
    00521         RefCountedPointer<FieldNames> field_names_;
    00522         bool initialized_;
    00523 };
    00524
    00525 } // end namespace mysqlpp
    00526
    00527 #endif // !defined(MYSQLPP_ROW_H)