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

# manip.h

Go to the documentation of this file.

    00001
    00002
    00003
    00004
    00005
    00006
    00007
    00008
    00009
    00010
    00011
    00012
    00013
    00014
    00015
    00016
    00017
    00018 /***********************************************************************
    00019  Copyright (c) 1998 by Kevin Atkinson, (c) 1999, 2000 and 2001 by
    00020  MySQL AB, and (c) 2004, 2005 by Educational Technology Resources, Inc.
    00021  Others may also hold copyrights on code in this file.  See the CREDITS
    00022  file in the top directory of the distribution for details.
    00023
    00024  This file is part of MySQL++.
    00025
    00026  MySQL++ is free software; you can redistribute it and/or modify it
    00027  under the terms of the GNU Lesser General Public License as published
    00028  by the Free Software Foundation; either version 2.1 of the License, or
    00029  (at your option) any later version.
    00030
    00031  MySQL++ is distributed in the hope that it will be useful, but WITHOUT
    00032  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    00033  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
    00034  License for more details.
    00035
    00036  You should have received a copy of the GNU Lesser General Public
    00037  License along with MySQL++; if not, write to the Free Software
    00038  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
    00039  USA
    00040 ***********************************************************************/
    00041
    00042 #ifndef MYSQLPP_MANIP_H
    00043 #define MYSQLPP_MANIP_H
    00044
    00045 #include "defs.h"
    00046
    00047 #include "datetime.h"
    00048 #include "myset.h"
    00049 #include "sql_string.h"
    00050 #include "sql_query.h"
    00051
    00052 #include <mysql.h>
    00053
    00054 #include <iostream>
    00055
    00059 namespace mysqlpp {
    00060
    00061 extern bool dont_quote_auto;
    00062
    00063
    00072
    00073
    00074 enum quote_type0
    00075 {
    00076         quote
    00077 };
    00078
    00079
    00080 #if !defined(DOXYGEN_IGNORE)
    00081 // Doxygen will not generate documentation for this section.
    00082
    00083 struct quote_type1
    00084 {
    00085         std::ostream * ostr;
    00086         quote_type1(std::ostream * o) :
    00087         ostr(o)
    00088         {
    00089         }
    00090 };
    00091
    00092
    00093 inline quote_type1 operator <<(std::ostream& o, quote_type0 /*esc */)
    00094 {
    00095         return quote_type1(&o);
    00096 }
    00097
    00098
    00099 class SQLQueryParms;
    00100 struct quote_type2
    00101 {
    00102         SQLQueryParms *qparms;
    00103         quote_type2(SQLQueryParms* p) :
    00104         qparms(p)
    00105         {
    00106         }
    00107 };
    00108
    00109
    00110 inline quote_type2 operator <<(SQLQueryParms& p,
    00111                 quote_type0 /*esc */)
    00112 {
    00113         return quote_type2(&p);
    00114 }
    00115
    00116
    00117 SQLQueryParms& operator <<(quote_type2 p, SQLString& in);
    00118
    00119
    00120 template <class T>
    00121         inline std::ostream& operator <<(quote_type1 o, const T & in)
    00122 {
    00123         return *o.ostr << in;
    00124 }
    00125
    00126
    00127 std::ostream& operator <<(std::ostream& o,
    00128                 const ColData_Tmpl<std::string>& in);
    00129
    00130
    00131 std::ostream& operator <<(std::ostream& o,
    00132                 const ColData_Tmpl<const_string>& in);
    00133
    00134
    00135 SQLQuery& operator <<(SQLQuery& o,
    00136                 const ColData_Tmpl<std::string>& in);
    00137
    00138
    00139 SQLQuery& operator <<(SQLQuery& o,
    00140                 const ColData_Tmpl<const_string>& in);
    00141
    00142
    00143 template <>
    00144 std::ostream& operator <<(quote_type1 o, const std::string& in);
    00145
    00146
    00147 template <>
    00148 std::ostream& operator <<(quote_type1 o, const char* const& in);
    00149
    00150
    00151 template <>
    00152 std::ostream& operator <<(quote_type1 o,
    00153                 const ColData_Tmpl<std::string>& in);
    00154
    00155
    00156 template <>
    00157 std::ostream& operator <<(quote_type1 o,
    00158                 const ColData_Tmpl<const_string>& in);
    00159
    00160
    00161 template <>
    00162 inline std::ostream& operator <<(quote_type1 o, char* const& in)
    00163 {
    00164         return operator <<(o, const_cast<const char* const&>(in));
    00165 }
    00166
    00167
    00168 template <>
    00169 inline std::ostream& operator <<(quote_type1 o, const Date& in)
    00170 {
    00171         return *o.ostr << '\'' << in << '\'';
    00172 }
    00173
    00174
    00175 template <>
    00176 inline std::ostream& operator <<(quote_type1 o, const Time& in)
    00177 {
    00178         return *o.ostr << '\'' << in << '\'';
    00179 }
    00180
    00181
    00182 template <>
    00183 inline std::ostream& operator <<(quote_type1 o,
    00184                 const DateTime& in)
    00185 {
    00186         return *o.ostr << '\'' << in << '\'';
    00187 }
    00188
    00189
    00190 template <class ST>
    00191 inline std::ostream& operator <<(quote_type1 o, const Set<ST>& in)
    00192 {
    00193         return *o.ostr << '\'' << in << '\'';
    00194 }
    00195
    00196 #endif // !defined(DOXYGEN_IGNORE)
    00197
    00198
    00206
    00207 enum quote_only_type0
    00208 {
    00209         quote_only
    00210 };
    00211
    00212
    00213 #if !defined(DOXYGEN_IGNORE)
    00214 // Doxygen will not generate documentation for this section.
    00215
    00216 struct quote_only_type1
    00217 {
    00218         std::ostream* ostr;
    00219         quote_only_type1(std::ostream* o) :
    00220         ostr(o)
    00221         {
    00222         }
    00223 };
    00224
    00225
    00226 inline quote_only_type1 operator <<(std::ostream& o,
    00227                 quote_only_type0 /*esc */)
    00228 {
    00229         return quote_only_type1(&o);
    00230 }
    00231
    00232
    00233 struct quote_only_type2
    00234 {
    00235         SQLQueryParms* qparms;
    00236         quote_only_type2(SQLQueryParms* p) :
    00237         qparms(p)
    00238         {
    00239         }
    00240 };
    00241
    00242
    00243 inline quote_only_type2 operator <<(SQLQueryParms& p,
    00244                 quote_only_type0 /*esc */)
    00245 {
    00246         return quote_only_type2(&p);
    00247 }
    00248
    00249 SQLQueryParms& operator <<(quote_only_type2 p, SQLString& in);
    00250
    00251
    00252 template <class T>
    00253 inline std::ostream& operator <<(quote_only_type1 o, const T& in)
    00254 {
    00255         return *o.ostr << in;
    00256 }
    00257
    00258
    00259 template <>
    00260 inline std::ostream& operator <<(quote_only_type1 o,
    00261                 const std::string& in)
    00262 {
    00263         return *o.ostr << '\'' << in << '\'';
    00264 }
    00265
    00266
    00267 template <>
    00268 std::ostream& operator <<(quote_only_type1 o,
    00269                 const ColData_Tmpl<std::string>& in);
    00270
    00271
    00272 template <>
    00273 std::ostream& operator <<(quote_only_type1 o,
    00274                 const ColData_Tmpl<const_string>& in);
    00275
    00276
    00277 template <>
    00278 inline std::ostream& operator <<(quote_only_type1 o, const Date& in)
    00279 {
    00280         return *o.ostr << '\'' << in << '\'';
    00281 }
    00282
    00283
    00284 template <>
    00285 inline std::ostream& operator <<(quote_only_type1 o, const Time& in)
    00286 {
    00287         return *o.ostr << '\'' << in << '\'';
    00288 }
    00289
    00290
    00291 template <>
    00292 inline std::ostream& operator <<(quote_only_type1 o, const DateTime& in)
    00293 {
    00294         return *o.ostr << '\'' << in << '\'';
    00295 }
    00296
    00297
    00298 template <class ST>
    00299 inline std::ostream& operator <<(quote_only_type1 o, const Set<ST>& in)
    00300 {
    00301         return *o.ostr << '\'' << in << '\'';
    00302 }
    00303
    00304 #endif // !defined(DOXYGEN_IGNORE)
    00305
    00306
    00314
    00315 enum quote_double_only_type0
    00316 {
    00317         quote_double_only
    00318 };
    00319
    00320
    00321 #if !defined(DOXYGEN_IGNORE)
    00322 // Doxygen will not generate documentation for this section.
    00323
    00324 struct quote_double_only_type1
    00325 {
    00326         std::ostream* ostr;
    00327         quote_double_only_type1(std::ostream* o) :
    00328         ostr(o)
    00329         {
    00330         }
    00331 };
    00332
    00333
    00334 inline quote_double_only_type1 operator <<(std::ostream& o,
    00335                 quote_double_only_type0 /*esc */)
    00336 {
    00337         return quote_double_only_type1(&o);
    00338 }
    00339
    00340
    00341 struct quote_double_only_type2
    00342 {
    00343         SQLQueryParms *qparms;
    00344         quote_double_only_type2(SQLQueryParms* p) :
    00345         qparms(p)
    00346         {
    00347         }
    00348 };
    00349
    00350
    00351 inline quote_double_only_type2 operator <<(SQLQueryParms& p,
    00352                 quote_double_only_type0 /*esc */)
    00353 {
    00354         return quote_double_only_type2(&p);
    00355 }
    00356
    00357
    00358 SQLQueryParms& operator <<(quote_double_only_type2 p, SQLString& in);
    00359
    00360
    00361 template <class T>
    00362 inline std::ostream& operator <<(quote_double_only_type1 o, const T& in)
    00363 {
    00364         return *o.ostr << in;
    00365 }
    00366
    00367
    00368 template <>
    00369 inline std::ostream& operator <<(quote_double_only_type1 o,
    00370                 const std::string& in)
    00371 {
    00372         return *o.ostr << '"' << in << '"';
    00373 }
    00374
    00375
    00376 template <>
    00377 std::ostream& operator <<(quote_double_only_type1 o,
    00378                 const ColData_Tmpl<std::string>& in);
    00379
    00380
    00381 template <>
    00382 std::ostream & operator <<(quote_double_only_type1 o,
    00383                 const ColData_Tmpl<const_string>& in);
    00384
    00385
    00386 template <>
    00387 inline std::ostream& operator <<(quote_double_only_type1 o,
    00388                 const Date& in)
    00389 {
    00390         return *o.ostr << '"' << in << '"';
    00391 }
    00392
    00393
    00394 template <>
    00395 inline std::ostream& operator <<(quote_double_only_type1 o, const Time& in)
    00396 {
    00397         return *o.ostr << '"' << in << '"';
    00398 }
    00399
    00400
    00401 template <>
    00402 inline std::ostream& operator <<(quote_double_only_type1 o,
    00403                 const DateTime& in)
    00404 {
    00405         return *o.ostr << '"' << in << '"';
    00406 }
    00407
    00408
    00409 template <class ST>
    00410 inline std::ostream& operator <<(quote_double_only_type1 o,
    00411                 const Set<ST>& in)
    00412 {
    00413         return *o.ostr << '"' << in << '"';
    00414 }
    00415
    00416 #endif // !defined(DOXYGEN_IGNORE)
    00417
    00418
    00425
    00426 enum escape_type0 { escape };
    00427
    00428
    00429 #if !defined(DOXYGEN_IGNORE)
    00430 // Doxygen will not generate documentation for this section.
    00431
    00432 struct escape_type1
    00433 {
    00434         std::ostream* ostr;
    00435         escape_type1(std::ostream* o) :
    00436         ostr(o)
    00437         {
    00438         }
    00439 };
    00440
    00441
    00442 inline escape_type1 operator <<(std::ostream& o, escape_type0 /*esc */)
    00443 {
    00444         return escape_type1(&o);
    00445 }
    00446
    00447
    00448 struct escape_type2
    00449 {
    00450         SQLQueryParms *qparms;
    00451         escape_type2(SQLQueryParms* p) :
    00452         qparms(p)
    00453         {
    00454         }
    00455 };
    00456
    00457
    00458 inline escape_type2 operator <<(SQLQueryParms& p, escape_type0 /*esc */)
    00459 {
    00460         return escape_type2(&p);
    00461 }
    00462
    00463 #endif // !defined(DOXYGEN_IGNORE)
    00464
    00465
    00472
    00473 SQLQueryParms& operator <<(escape_type2 p, SQLString& in);
    00474
    00475
    00484
    00485 template <class T>
    00486 inline std::ostream& operator <<(escape_type1 o, const T& in)
    00487 {
    00488         return *o.ostr << in;
    00489 }
    00490
    00491
    00492 template <>
    00493 std::ostream& operator <<(escape_type1 o, const std::string& in);
    00494
    00495
    00496 template <>
    00497 std::ostream& operator <<(escape_type1 o, const char* const& in);
    00498
    00499
    00500 template <>
    00501 std::ostream& operator <<(escape_type1 o,
    00502                 const ColData_Tmpl<std::string>& in);
    00503
    00504
    00505 template <>
    00506 std::ostream& operator <<(escape_type1 o,
    00507                 const ColData_Tmpl<const_string>& in);
    00508
    00509
    00516
    00517 template <>
    00518 inline std::ostream& operator <<(escape_type1 o, char* const& in)
    00519 {
    00520         return operator <<(o, const_cast<const char* const&>(in));
    00521 }
    00522
    00523
    00534
    00535 enum do_nothing_type0
    00536 {
    00537         do_nothing
    00538 };
    00539
    00540
    00541 #if !defined(DOXYGEN_IGNORE)
    00542 // Doxygen will not generate documentation for this section.
    00543
    00544 struct do_nothing_type1
    00545 {
    00546         std::ostream* ostr;
    00547         do_nothing_type1(std::ostream* o) :
    00548         ostr(o)
    00549         {
    00550         }
    00551 };
    00552
    00553
    00554 inline do_nothing_type1 operator <<(std::ostream& o,
    00555                 do_nothing_type0 /*esc */)
    00556 {
    00557         return do_nothing_type1(&o);
    00558 }
    00559
    00560
    00561 template < class T >
    00562         inline std::ostream & operator <<(do_nothing_type1 o, const T & in)
    00563 {
    00564         return *o.ostr << in;
    00565 }
    00566
    00567
    00568 struct do_nothing_type2
    00569 {
    00570         SQLQueryParms *qparms;
    00571         do_nothing_type2(SQLQueryParms* p) :
    00572         qparms(p)
    00573         {
    00574         }
    00575 };
    00576
    00577
    00578 inline do_nothing_type2 operator <<(SQLQueryParms& p,
    00579                 do_nothing_type0 /*esc */)
    00580 {
    00581         return do_nothing_type2(&p);
    00582 }
    00583
    00584
    00585 inline SQLQueryParms& operator <<(do_nothing_type2 p, SQLString& in)
    00586 {
    00587         in.processed = true;
    00588         return *p.qparms << in;
    00589 }
    00590
    00591 #endif // !defined(DOXYGEN_IGNORE)
    00592
    00593
    00603
    00604 enum ignore_type0
    00605 {
    00606         ignore
    00607 };
    00608
    00609
    00610 #if !defined(DOXYGEN_IGNORE)
    00611 // Doxygen will not generate documentation for this section.
    00612
    00613 struct ignore_type2
    00614 {
    00615         SQLQueryParms* qparms;
    00616         ignore_type2(SQLQueryParms* p) :
    00617         qparms(p)
    00618         {
    00619         }
    00620 };
    00621
    00622
    00623 inline ignore_type2 operator <<(SQLQueryParms& p, ignore_type0 /*esc*/)
    00624 {
    00625         return ignore_type2(&p);
    00626 }
    00627
    00628
    00629 inline SQLQueryParms& operator <<(ignore_type2 p, SQLString& in)
    00630 {
    00631         return *p.qparms << in;
    00632 }
    00633
    00634 #endif // !defined(DOXYGEN_IGNORE)
    00635
    00636 } // end namespace mysqlpp
    00637
    00638 #endif