00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef MYSQLPP_ROW_H
00029 #define MYSQLPP_ROW_H
00030
00031 #include "coldata.h"
00032 #include "exceptions.h"
00033 #include "resiter.h"
00034 #include "vallist.h"
00035
00036 #include <vector>
00037 #include <string>
00038
00039 #include <string.h>
00040
00041 namespace mysqlpp {
00042
00043 class FieldNames;
00044 class ResUse;
00045
00047
00048 template <class ThisType, class Res>
00049 class RowTemplate
00050 {
00051 protected:
00055 virtual ThisType& self() = 0;
00056
00059 virtual const ThisType& self() const = 0;
00060
00061 public:
00063 virtual ~RowTemplate() { }
00064
00069 virtual const Res& parent() const = 0;
00070
00075 value_list_ba<ThisType, quote_type0> value_list(
00076 const char* d = ",") const
00077 {
00078 return value_list_ba<ThisType, quote_type0>(self(), d, quote);
00079 }
00080
00085 template <class Manip>
00086 value_list_ba<ThisType, Manip> value_list(const char *d,
00087 Manip m) const {
00088 return value_list_ba<ThisType, Manip>(self(), d, m);
00089 }
00090
00097 template <class Manip>
00098 value_list_b<ThisType, Manip> value_list(const char *d, Manip m,
00099 const std::vector<bool>& vb) const
00100 {
00101 return value_list_b<ThisType, Manip>(self(), vb, d, m);
00102 }
00103
00112 value_list_b<ThisType, quote_type0>
00113 value_list(const char* d, const std::vector<bool>& vb) const
00114 {
00115 return value_list_b<ThisType, quote_type0>(self(), vb, d, quote);
00116 }
00117
00125 value_list_b<ThisType, quote_type0> value_list(
00126 const std::vector<bool> &vb) const
00127 {
00128 return value_list_b<ThisType, quote_type0>(self(), vb, ",", quote);
00129 }
00130
00137 template <class Manip>
00138 value_list_b<ThisType, Manip> value_list(const char *d, Manip m,
00139 bool t0, bool t1 = false, bool t2 = false, bool t3 = false,
00140 bool t4 = false, bool t5 = false, bool t6 = false,
00141 bool t7 = false, bool t8 = false, bool t9 = false,
00142 bool ta = false, bool tb = false, bool tc = false) const
00143 {
00144 std::vector<bool> vb;
00145 create_vector(self().size(), vb, t0, t1, t2, t3, t4, t5, t6,
00146 t7, t8, t9, ta, tb, tc);
00147 return value_list_b<ThisType, Manip>(self(), vb, d, m);
00148 }
00149
00156 value_list_b <ThisType, quote_type0>
00157 value_list(const char *d, bool t0, bool t1 = false, bool t2 = false,
00158 bool t3 = false, bool t4 = false, bool t5 = false,
00159 bool t6 = false, bool t7 = false, bool t8 = false,
00160 bool t9 = false, bool ta = false, bool tb = false,
00161 bool tc = false) const
00162 {
00163 std::vector<bool> vb;
00164 create_vector(self().size(), vb, t0, t1, t2, t3, t4, t5, t6,
00165 t7, t8, t9, ta, tb, tc);
00166 return value_list_b<ThisType, quote_type0>(self(), vb, d, quote);
00167 }
00168
00175 value_list_b<ThisType, quote_type0> value_list(bool t0,
00176 bool t1 = false, bool t2 = false, bool t3 = false,
00177 bool t4 = false, bool t5 = false, bool t6 = false,
00178 bool t7 = false, bool t8 = false, bool t9 = false,
00179 bool ta = false, bool tb = false, bool tc = false) const
00180 {
00181 std::vector<bool> vb;
00182 create_vector(self().size(), vb, t0, t1, t2, t3, t4, t5, t6,
00183 t7, t8, t9, ta, tb, tc);
00184 return value_list_b<ThisType, quote_type0>(self(), vb, ",", quote);
00185 }
00186
00193 template <class Manip>
00194 value_list_b<ThisType, Manip> value_list(const char *d, Manip m,
00195 std::string s0, std::string s1 = "", std::string s2 = "",
00196 std::string s3 = "", std::string s4 = "",
00197 std::string s5 = "", std::string s6 = "",
00198 std::string s7 = "", std::string s8 = "",
00199 std::string s9 = "", std::string sa = "",
00200 std::string sb = "", std::string sc = "") const
00201 {
00202 std::vector<bool> vb;
00203 create_vector(self(), vb, s0, s1, s2, s3, s4, s5, s6, s7, s8,
00204 s9, sa, sb, sc);
00205 return value_list_b<ThisType, Manip>(self(), vb, d, m);
00206 }
00207
00214 value_list_b<ThisType, quote_type0> value_list(const char *d,
00215 std::string s0, std::string s1 = "", std::string s2 = "",
00216 std::string s3 = "", std::string s4 = "",
00217 std::string s5 = "", std::string s6 = "",
00218 std::string s7 = "", std::string s8 = "",
00219 std::string s9 = "", std::string sa = "",
00220 std::string sb = "", std::string sc = "") const
00221 {
00222 std::vector<bool> vb;
00223 create_vector(self(), vb, s0, s1, s2, s3, s4, s5, s6, s7, s8,
00224 s9, sa, sb, sc);
00225 return value_list_b<ThisType, quote_type0>(self(), vb, d, quote);
00226 }
00227
00234 value_list_b<ThisType, quote_type0> value_list(std::string s0,
00235 std::string s1 = "", std::string s2 = "",
00236 std::string s3 = "", std::string s4 = "",
00237 std::string s5 = "", std::string s6 = "",
00238 std::string s7 = "", std::string s8 = "",
00239 std::string s9 = "", std::string sa = "",
00240 std::string sb = "", std::string sc = "") const
00241 {
00242 std::vector<bool> vb;
00243 create_vector(self(), vb, s0, s1, s2, s3, s4, s5, s6, s7, s8,
00244 s9, sa, sb, sc);
00245 return value_list_b<ThisType, quote_type0>(self(), vb, ",", quote);
00246 }
00247
00252 value_list_ba<FieldNames, do_nothing_type0> field_list(
00253 const char* d = ",") const
00254 {
00255 return value_list_ba<FieldNames, do_nothing_type0>
00256 (parent().names(), d, do_nothing);
00257 }
00258
00265 template <class Manip>
00266 value_list_ba<FieldNames, Manip> field_list(const char *d,
00267 Manip m) const
00268 {
00269 return value_list_ba<FieldNames, Manip>(parent().names(), d, m);
00270 }
00271
00280 template <class Manip>
00281 value_list_b<FieldNames, Manip> field_list(const char *d, Manip m,
00282 const std::vector<bool>& vb) const
00283 {
00284 return value_list_b<FieldNames, Manip>(parent().names(), vb, d, m);
00285 }
00286
00296 value_list_b<FieldNames, quote_type0> field_list(const char *d,
00297 const std::vector<bool> &vb) const
00298 {
00299 return value_list_b<FieldNames, quote_type0>(parent().names(),
00300 vb, d, quote);
00301 }
00302
00310 value_list_b<FieldNames, quote_type0> field_list(
00311 const std::vector<bool> &vb) const
00312 {
00313 return value_list_b<FieldNames, quote_type0>(parent().names(),
00314 vb, ",", quote);
00315 }
00316
00324 template <class Manip> value_list_b<FieldNames, Manip> field_list(
00325 const char *d, Manip m, bool t0, bool t1 = false,
00326 bool t2 = false, bool t3 = false, bool t4 = false,
00327 bool t5 = false, bool t6 = false, bool t7 = false,
00328 bool t8 = false, bool t9 = false, bool ta = false,
00329 bool tb = false, bool tc = false) const
00330 {
00331 std::vector<bool> vb;
00332 create_vector(parent().names().size(), vb, t0, t1, t2, t3, t4,
00333 t5, t6, t7, t8, t9, ta, tb, tc);
00334 return value_list_b<FieldNames, Manip>(parent().names(), vb, d, m);
00335 }
00336
00344 value_list_b<FieldNames, quote_type0> field_list(const char *d,
00345 bool t0, bool t1 = false, bool t2 = false, bool t3 = false,
00346 bool t4 = false, bool t5 = false, bool t6 = false,
00347 bool t7 = false, bool t8 = false, bool t9 = false,
00348 bool ta = false, bool tb = false, bool tc = false) const
00349 {
00350 std::vector<bool> vb;
00351 create_vector(parent().names().size(), vb, t0, t1, t2, t3, t4,
00352 t5, t6, t7, t8, t9, ta, tb, tc);
00353 return value_list_b<FieldNames, quote_type0>(parent().names(),
00354 vb, d, quote);
00355 }
00356
00363 value_list_b<FieldNames, quote_type0> field_list(bool t0,
00364 bool t1 = false, bool t2 = false, bool t3 = false,
00365 bool t4 = false, bool t5 = false, bool t6 = false,
00366 bool t7 = false, bool t8 = false, bool t9 = false,
00367 bool ta = false, bool tb = false, bool tc = false) const
00368 {
00369 std::vector<bool> vb;
00370 create_vector(parent().names().size(), vb, t0, t1, t2, t3, t4,
00371 t5, t6, t7, t8, t9, ta, tb, tc);
00372 return value_list_b<FieldNames, quote_type0>(parent().names(),
00373 vb, ",", quote);
00374 }
00375
00382 template <class Manip> value_list_b<FieldNames, Manip> field_list(
00383 const char *d, Manip m, std::string s0, std::string s1 = "",
00384 std::string s2 = "", std::string s3 = "",
00385 std::string s4 = "", std::string s5 = "",
00386 std::string s6 = "", std::string s7 = "",
00387 std::string s8 = "", std::string s9 = "",
00388 std::string sa = "", std::string sb = "",
00389 std::string sc = "") const
00390 {
00391 std::vector<bool> vb;
00392 create_vector(parent().names(), vb, s0, s1, s2, s3, s4, s5, s6,
00393 s7, s8, s9, sa, sb, sc);
00394 return value_list_b<FieldNames, Manip>(parent().names(), vb, d, m);
00395 }
00396
00403 value_list_b<FieldNames, quote_type0> field_list(const char *d,
00404 std::string s0, std::string s1 = "", std::string s2 = "",
00405 std::string s3 = "", std::string s4 = "",
00406 std::string s5 = "", std::string s6 = "",
00407 std::string s7 = "", std::string s8 = "",
00408 std::string s9 = "", std::string sa = "",
00409 std::string sb = "", std::string sc = "") const
00410 {
00411 std::vector<bool> vb;
00412 create_vector(parent().names(), vb, s0, s1, s2, s3, s4, s5, s6,
00413 s7, s8, s9, sa, sb, sc);
00414 return value_list_b<FieldNames, quote_type0>(parent().names(),
00415 vb, d, quote);
00416 }
00417
00424 value_list_b<FieldNames, quote_type0> field_list(std::string s0,
00425 std::string s1 = "", std::string s2 = "",
00426 std::string s3 = "", std::string s4 = "",
00427 std::string s5 = "", std::string s6 = "",
00428 std::string s7 = "", std::string s8 = "",
00429 std::string s9 = "", std::string sa = "",
00430 std::string sb = "", std::string sc = "") const
00431 {
00432 std::vector<bool> vb;
00433 create_vector(parent().names(), vb, s0, s1, s2, s3, s4, s5, s6,
00434 s7, s8, s9, sa, sb, sc);
00435 return value_list_b<FieldNames, quote_type0>(parent().names(),
00436 vb, ",", quote);
00437 }
00438
00444 equal_list_ba<FieldNames, ThisType, quote_type0> equal_list(
00445 const char* d = ",", const char* e = " = ") const
00446 {
00447 return equal_list_ba<FieldNames, ThisType, quote_type0>(
00448 parent().names(), self(), d, e, quote);
00449 }
00450
00471 template <class Manip>
00472 equal_list_ba<FieldNames, ThisType, Manip> equal_list(const char* d,
00473 const char* e, Manip m) const
00474 {
00475 return equal_list_ba<FieldNames, ThisType, Manip>(
00476 parent().names(), self(), d, e, m);
00477 }
00478 };
00479
00480
00482 class Row : public const_subscript_container<Row, ColData,
00483 const ColData>, public RowTemplate<Row, ResUse>
00484 {
00485 private:
00486 std::vector<std::string> data;
00487 std::vector<bool> is_nulls;
00488 const ResUse* res;
00489 bool throw_exceptions;
00490 bool initialized;
00491
00492 public:
00494 Row() { }
00495
00502 Row(MYSQL_ROW d, const ResUse* r, unsigned long* jj, bool te = false) :
00503 res(r),
00504 throw_exceptions(te),
00505 initialized(false)
00506 {
00507 if (!d || !r) {
00508 if (throw_exceptions) {
00509 throw BadQuery("ROW or RES is NULL");
00510 }
00511 else {
00512 return;
00513 }
00514 }
00515 data.clear();
00516 is_nulls.clear();
00517 initialized = true;
00518 for (unsigned int i = 0; i < size(); i++) {
00519 data.insert(data.end(),
00520 (d[i] ? std::string(d[i], jj[i]) : std::string("NULL")));
00521 is_nulls.insert(is_nulls.end(), d[i] ? false : true);
00522 }
00523 }
00524
00526 ~Row()
00527 {
00528 data.clear();
00529 is_nulls.clear();
00530 initialized = false;
00531 }
00532
00534 const Row & self() const
00535 {
00536 return *this;
00537 }
00538
00540 Row& self()
00541 {
00542 return *this;
00543 }
00544
00546 const ResUse& parent() const
00547 {
00548 return *res;
00549 }
00550
00552 size_type size() const;
00553
00584 const ColData operator [](size_type i) const;
00585
00591 const ColData lookup_by_name(const char*) const;
00592
00598 const char* raw_data(int i) const
00599 {
00600 return data[i].data();
00601 }
00602
00604 operator bool() const
00605 {
00606 return data.size();
00607 }
00608 };
00609
00610 }
00611
00612 #endif