Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

row.h

Go to the documentation of this file.
00001 #ifndef MYSQLPP_ROW_H
00002 #define MYSQLPP_ROW_H
00003 
00006 
00007 #include "coldata.h"
00008 #include "exceptions.h"
00009 #include "resiter.h"
00010 #include "vallist.h"
00011 
00012 #include <vector>
00013 #include <string>
00014 
00015 #include <string.h>
00016 
00017 namespace mysqlpp {
00018 
00019 class FieldNames;
00020 class ResUse;
00021 
00023 
00024 template <class ThisType, class Res>
00025 class RowTemplate {
00026 protected:
00027   virtual ThisType& self() = 0;
00028   virtual const ThisType& self() const = 0;
00029 public:
00030   virtual const Res & parent() const = 0;
00031   
00032   // 
00033   // value_list
00034   //
00035   value_list_ba<ThisType,quote_type0> 
00036   value_list(const char *d = ",") const {
00037     return value_list_ba<ThisType,quote_type0> 
00038       (self(), d, quote);
00039   }
00040 
00041   template <class Manip>  
00042   value_list_ba<ThisType,Manip> 
00043   value_list(const char *d, Manip m) const {
00044     return value_list_ba<ThisType,Manip> (self(), d, m);
00045   }
00046 
00047   template <class Manip>  
00048   value_list_b<ThisType,Manip> 
00049   value_list(const char *d, Manip m, const std::vector<bool> &vb) const {
00050     return value_list_b<ThisType,Manip> (self(), vb, d, m);
00051   }
00052 
00053   value_list_b<ThisType,quote_type0> 
00054   value_list(const char *d, const std::vector<bool> &vb) const {
00055     return value_list_b<ThisType,quote_type0> (self(), vb, d, quote);
00056   }
00057 
00058   value_list_b<ThisType,quote_type0> 
00059   value_list(const std::vector<bool> &vb) const {
00060     return value_list_b<ThisType,quote_type0> (self(), vb, ",", quote);
00061   }
00062 
00063   template <class Manip>  
00064   value_list_b<ThisType,Manip> 
00065   value_list(const char *d, Manip m, bool t0,
00066              bool t1=false, bool t2=false, bool t3=false, bool t4=false,
00067              bool t5=false, bool t6=false, bool t7=false, bool t8=false,
00068              bool t9=false, bool ta=false, bool tb=false, bool tc=false) const {
00069     std::vector<bool> vb;
00070     create_vector(self().size(), vb, t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,ta,tb,tc);
00071     return value_list_b<ThisType, Manip>(self(), vb, d, m);
00072   }
00073 
00074   value_list_b<ThisType,quote_type0> 
00075   value_list(const char *d, bool t0,
00076              bool t1=false, bool t2=false, bool t3=false, bool t4=false,
00077              bool t5=false, bool t6=false, bool t7=false, bool t8=false,
00078              bool t9=false, bool ta=false, bool tb=false, bool tc=false) const {
00079     std::vector<bool> vb;
00080     create_vector(self().size(), vb, t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,ta,tb,tc);
00081     return value_list_b<ThisType, quote_type0>(self(), vb, d, quote);
00082   }
00083 
00084   value_list_b<ThisType,quote_type0> 
00085   value_list(bool t0,
00086              bool t1=false, bool t2=false, bool t3=false, bool t4=false,
00087              bool t5=false, bool t6=false, bool t7=false, bool t8=false,
00088              bool t9=false, bool ta=false, bool tb=false, bool tc=false) const {
00089     std::vector<bool> vb;
00090     create_vector(self().size(), vb, t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,ta,tb,tc);
00091     return value_list_b<ThisType, quote_type0>(self(), vb, ",", quote);
00092   }
00093 
00094   template <class Manip>
00095   value_list_b<ThisType,Manip> 
00096   value_list(const char *d, Manip m, std::string s0,
00097              std::string s1="", std::string s2="", std::string s3="", std::string s4="",
00098              std::string s5="", std::string s6="", std::string s7="", std::string s8="",
00099              std::string s9="", std::string sa="", std::string sb="", std::string sc="") const {
00100     std::vector<bool> vb;
00101     create_vector(self(), vb, s0,s1,s2,s3,s4,s5,s6,s7,s8,s9,sa,sb,sc);
00102     return value_list_b<ThisType, Manip>(self(), vb, d, m);
00103   }
00104 
00105   value_list_b<ThisType,quote_type0> 
00106   value_list(const char *d, std::string s0,
00107              std::string s1="", std::string s2="", std::string s3="", std::string s4="",
00108              std::string s5="", std::string s6="", std::string s7="", std::string s8="",
00109              std::string s9="", std::string sa="", std::string sb="", std::string sc="") const {
00110     std::vector<bool> vb;
00111     create_vector(self(), vb, s0,s1,s2,s3,s4,s5,s6,s7,s8,s9,sa,sb,sc);
00112     return value_list_b<ThisType, quote_type0>(self(), vb, d, quote);
00113   }
00114 
00115   value_list_b<ThisType,quote_type0> 
00116   value_list(std::string s0,
00117              std::string s1="", std::string s2="", std::string s3="", std::string s4="",
00118              std::string s5="", std::string s6="", std::string s7="", std::string s8="",
00119              std::string s9="", std::string sa="", std::string sb="", std::string sc="") const {
00120     std::vector<bool> vb;
00121     create_vector(self(), vb, s0,s1,s2,s3,s4,s5,s6,s7,s8,s9,sa,sb,sc);
00122     return value_list_b<ThisType, quote_type0>(self(), vb, ",", quote);
00123   }
00124 
00125   //
00126   // field_list
00127   //
00128   value_list_ba<FieldNames, do_nothing_type0> 
00129   field_list(const char *d = ",") const {
00130     return value_list_ba<FieldNames, do_nothing_type0> 
00131       (parent().names(), d, do_nothing);
00132   }
00133 
00134   template <class Manip>  
00135   value_list_ba<FieldNames,Manip> 
00136   field_list(const char *d, Manip m) const {
00137     return value_list_ba<FieldNames, Manip>
00138       (parent().names(), d, m);
00139   }
00140 
00141   template <class Manip>  
00142   value_list_b<FieldNames,Manip> 
00143   field_list(const char *d, Manip m, const std::vector<bool> &vb) const {
00144     return value_list_b<FieldNames,Manip> (parent().names(), vb, d, m);
00145   }
00146 
00147   value_list_b<FieldNames,quote_type0> 
00148   field_list(const char *d, const std::vector<bool> &vb) const {
00149     return value_list_b<FieldNames,quote_type0> (parent().names(), vb, d, quote);
00150   }
00151 
00152   value_list_b<FieldNames,quote_type0> 
00153   field_list(const std::vector<bool> &vb) const {
00154     return value_list_b<FieldNames,quote_type0> (parent().names(), vb, ",", quote);
00155   }
00156 
00157   template <class Manip>  
00158   value_list_b<FieldNames,Manip> 
00159   field_list(const char *d, Manip m, bool t0,
00160              bool t1=false, bool t2=false, bool t3=false, bool t4=false,
00161              bool t5=false, bool t6=false, bool t7=false, bool t8=false,
00162              bool t9=false, bool ta=false, bool tb=false, bool tc=false) const {
00163     std::vector<bool> vb;
00164     create_vector(parent().names().size(), vb, t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,ta,tb,tc);
00165     return value_list_b<FieldNames, Manip>(parent().names(), vb, d, m);
00166   }
00167 
00168   value_list_b<FieldNames,quote_type0> 
00169   field_list(const char *d, bool t0,
00170              bool t1=false, bool t2=false, bool t3=false, bool t4=false,
00171              bool t5=false, bool t6=false, bool t7=false, bool t8=false,
00172              bool t9=false, bool ta=false, bool tb=false, bool tc=false) const {
00173     std::vector<bool> vb;
00174     create_vector(parent().names().size(), vb, t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,ta,tb,tc);
00175     return value_list_b<FieldNames, quote_type0>(parent().names(), vb, d, quote);
00176   }
00177 
00178   value_list_b<FieldNames,quote_type0> 
00179   field_list(bool t0,
00180              bool t1=false, bool t2=false, bool t3=false, bool t4=false,
00181              bool t5=false, bool t6=false, bool t7=false, bool t8=false,
00182              bool t9=false, bool ta=false, bool tb=false, bool tc=false) const {
00183     std::vector<bool> vb;
00184     create_vector(parent().names().size(), vb, t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,ta,tb,tc);
00185     return value_list_b<FieldNames, quote_type0>(parent().names(), vb, ",", quote);
00186   }
00187 
00188   template <class Manip>
00189   value_list_b<FieldNames,Manip> 
00190   field_list(const char *d, Manip m, std::string s0,
00191              std::string s1="", std::string s2="", std::string s3="", std::string s4="",
00192              std::string s5="", std::string s6="", std::string s7="", std::string s8="",
00193              std::string s9="", std::string sa="", std::string sb="", std::string sc="") const {
00194     std::vector<bool> vb;
00195     create_vector(parent().names(), vb, s0,s1,s2,s3,s4,s5,s6,s7,s8,s9,sa,sb,sc);
00196     return value_list_b<FieldNames, Manip>(parent().names(), vb, d, m);
00197   }
00198 
00199   value_list_b<FieldNames,quote_type0> 
00200   field_list(const char *d, std::string s0,
00201              std::string s1="", std::string s2="", std::string s3="", std::string s4="",
00202              std::string s5="", std::string s6="", std::string s7="", std::string s8="",
00203              std::string s9="", std::string sa="", std::string sb="", std::string sc="") const {
00204     std::vector<bool> vb;
00205     create_vector(parent().names(), vb, s0,s1,s2,s3,s4,s5,s6,s7,s8,s9,sa,sb,sc);
00206     return value_list_b<FieldNames, quote_type0>(parent().names(), vb, d, quote);
00207   }
00208 
00209   value_list_b<FieldNames,quote_type0> 
00210   field_list(std::string s0,
00211              std::string s1="", std::string s2="", std::string s3="", std::string s4="",
00212              std::string s5="", std::string s6="", std::string s7="", std::string s8="",
00213              std::string s9="", std::string sa="", std::string sb="", std::string sc="") const {
00214     std::vector<bool> vb;
00215     create_vector(parent().names(), vb, s0,s1,s2,s3,s4,s5,s6,s7,s8,s9,sa,sb,sc);
00216     return value_list_b<FieldNames, quote_type0>(parent().names(), vb, ",", quote);
00217   }
00218 
00219   //
00220   // equal_list
00221   //
00222   equal_list_ba<FieldNames,ThisType,quote_type0> 
00223   equal_list(const char *d = ",", const char *e = " = ") const {
00224     return equal_list_ba<FieldNames,ThisType,quote_type0> 
00225       (parent().names(), self(), d, e, quote);
00226   }
00227 
00228   template <class Manip>
00229   equal_list_ba<FieldNames,ThisType,Manip> 
00230   equal_list(const char *d, const char *e, Manip m) const {
00231     return equal_list_ba<FieldNames,ThisType,Manip> 
00232       (parent().names(), self(), d, e, m);
00233   }
00234 
00235   virtual ~RowTemplate() {}
00236 };
00237 
00238 
00240 class Row : public const_subscript_container<Row,ColData,const ColData>,
00241             public RowTemplate<Row, ResUse>
00242 {
00243 private:
00244   std::vector <std::string> data;
00245         std::vector <bool> is_nulls;
00246   const ResUse *res;
00247   bool         throw_exceptions, initialized;
00248 
00249 public:
00250   Row() {}
00251   Row(MYSQL_ROW d, const ResUse *r, unsigned long *jj, bool te = false) 
00252     : res(r), throw_exceptions(te), initialized(false)
00253                 {
00254                   if (!d || !r) {
00255                                 if (throw_exceptions) throw BadQuery("ROW or RES is NULL");
00256                                 else return;
00257                         }
00258                   data.clear(); is_nulls.clear(); initialized=true;
00259                   for (unsigned int i=0;i<size();i++) 
00260                         {
00261                           data.insert(data.end(), (d[i] ?
00262                                         std::string(d[i], jj[i]) :
00263                                         std::string("NULL")));
00264                           is_nulls.insert(is_nulls.end(),d[i] ? false : true);
00265                         }
00266                 }
00267   ~Row() {data.clear(); is_nulls.clear(); initialized = false;} 
00268 
00270   const Row& self() const {return *this;}
00271 
00273   Row& self() {return *this;}
00274 
00276   const ResUse&  parent() const {return *res;}
00277 
00279   size_type     size() const;
00280 
00282   const ColData   operator [] (size_type i) const;
00283 
00284   const ColData lookup_by_name(const char*) const;
00285 
00286   const char *raw_data(int i) const {return data[i].data();}
00287 
00289   operator bool() const {return (data.size()) ? true : false;}
00290 }; 
00291 
00292 } // end namespace mysqlpp
00293 
00294 #endif
00295 

Generated on Thu May 5 05:30:43 2005 for MySQL++ by doxygen1.2.18