# 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 "common.h"
    00046
    00047 #include "datetime.h"
    00048 #include "myset.h"
    00049 #include "sql_string.h"
    00050
    00051 #include <iostream>
    00052
    00056 namespace mysqlpp {
    00057
    00058 class Query;
    00059
    00060 extern bool dont_quote_auto;
    00061
    00062
    00071
    00072
    00073 enum quote_type0
    00074 {
    00075         quote
    00076 };
    00077
    00078
    00079 #if !defined(DOXYGEN_IGNORE)
    00080 // Doxygen will not generate documentation for this section.
    00081
    00082 struct quote_type1
    00083 {
    00084         std::ostream * ostr;
    00085         quote_type1(std::ostream * o) :
    00086         ostr(o)
    00087         {
    00088         }
    00089 };
    00090
    00091
    00092 inline quote_type1 operator <<(std::ostream& o,
    00093                 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 MYSQLPP_EXPORT SQLQueryParms& operator <<(quote_type2 p,
    00118                 SQLString& in);
    00119
    00120
    00121 template <class T>
    00122 inline std::ostream& operator <<(quote_type1 o, const T & in)
    00123 {
    00124         return *o.ostr << in;
    00125 }
    00126
    00127
    00128 MYSQLPP_EXPORT std::ostream& operator <<(std::ostream& o,
    00129                 const ColData_Tmpl<std::string>& in);
    00130
    00131
    00132 MYSQLPP_EXPORT std::ostream& operator <<(std::ostream& o,
    00133                 const ColData_Tmpl<const_string>& in);
    00134
    00135
    00136 MYSQLPP_EXPORT Query& operator <<(Query& o,
    00137                 const ColData_Tmpl<std::string>& in);
    00138
    00139
    00140 MYSQLPP_EXPORT Query& operator <<(Query& o,
    00141                 const ColData_Tmpl<const_string>& in);
    00142
    00143
    00144 template <>
    00145 MYSQLPP_EXPORT std::ostream& operator <<(quote_type1 o,
    00146                 const std::string& in);
    00147
    00148
    00149 template <>
    00150 MYSQLPP_EXPORT std::ostream& operator <<(quote_type1 o,
    00151                 const char* const& in);
    00152
    00153
    00154 template <>
    00155 MYSQLPP_EXPORT std::ostream& operator <<(quote_type1 o,
    00156                 const ColData_Tmpl<std::string>& in);
    00157
    00158
    00159 template <>
    00160 MYSQLPP_EXPORT std::ostream& operator <<(quote_type1 o,
    00161                 const ColData_Tmpl<const_string>& in);
    00162
    00163
    00164 template <>
    00165 inline std::ostream& operator <<(quote_type1 o,
    00166                 char* const& in)
    00167 {
    00168         return operator <<(o, const_cast<const char* const&>(in));
    00169 }
    00170
    00171 inline std::ostream& operator <<(quote_type1 o,
    00172                 char in[])
    00173 {
    00174         return operator <<(o, static_cast<const char* const&>(in));
    00175 }
    00176
    00177 inline std::ostream& operator <<(quote_type1 o,
    00178                 const char in[])
    00179 {
    00180         return operator <<(o, const_cast<char* const&>(in));
    00181 }
    00182
    00183
    00184 template <>
    00185 inline std::ostream& operator <<(quote_type1 o,
    00186                 const Date& in)
    00187 {
    00188         return *o.ostr << '\'' << in << '\'';
    00189 }
    00190
    00191
    00192 template <>
    00193 inline std::ostream& operator <<(quote_type1 o,
    00194                 const Time& in)
    00195 {
    00196         return *o.ostr << '\'' << in << '\'';
    00197 }
    00198
    00199
    00200 template <>
    00201 inline std::ostream& operator <<(quote_type1 o,
    00202                 const DateTime& in)
    00203 {
    00204         return *o.ostr << '\'' << in << '\'';
    00205 }
    00206
    00207
    00208 template <class ST>
    00209 inline std::ostream& operator <<(quote_type1 o, const Set<ST>& in)
    00210 {
    00211         return *o.ostr << '\'' << in << '\'';
    00212 }
    00213
    00214 #endif // !defined(DOXYGEN_IGNORE)
    00215
    00216
    00224
    00225 enum quote_only_type0
    00226 {
    00227         quote_only
    00228 };
    00229
    00230
    00231 #if !defined(DOXYGEN_IGNORE)
    00232 // Doxygen will not generate documentation for this section.
    00233
    00234 struct quote_only_type1
    00235 {
    00236         std::ostream* ostr;
    00237         quote_only_type1(std::ostream* o) :
    00238         ostr(o)
    00239         {
    00240         }
    00241 };
    00242
    00243
    00244 inline quote_only_type1 operator <<(std::ostream& o,
    00245                 quote_only_type0 /* esc */)
    00246 {
    00247         return quote_only_type1(&o);
    00248 }
    00249
    00250
    00251 struct quote_only_type2
    00252 {
    00253         SQLQueryParms* qparms;
    00254         quote_only_type2(SQLQueryParms* p) :
    00255         qparms(p)
    00256         {
    00257         }
    00258 };
    00259
    00260
    00261 inline quote_only_type2 operator <<(SQLQueryParms& p,
    00262                 quote_only_type0 /* esc */)
    00263 {
    00264         return quote_only_type2(&p);
    00265 }
    00266
    00267 MYSQLPP_EXPORT SQLQueryParms& operator <<(quote_only_type2 p,
    00268                 SQLString& in);
    00269
    00270
    00271 template <class T>
    00272 inline std::ostream& operator <<(quote_only_type1 o, const T& in)
    00273 {
    00274         return *o.ostr << in;
    00275 }
    00276
    00277
    00278 template <>
    00279 inline std::ostream& operator <<(quote_only_type1 o,
    00280                 const std::string& in)
    00281 {
    00282         return *o.ostr << '\'' << in << '\'';
    00283 }
    00284
    00285
    00286 template <>
    00287 MYSQLPP_EXPORT std::ostream& operator <<(quote_only_type1 o,
    00288                 const ColData_Tmpl<std::string>& in);
    00289
    00290
    00291 template <>
    00292 MYSQLPP_EXPORT std::ostream& operator <<(quote_only_type1 o,
    00293                 const ColData_Tmpl<const_string>& in);
    00294
    00295
    00296 template <>
    00297 inline std::ostream& operator <<(quote_only_type1 o,
    00298                 const Date& in)
    00299 {
    00300         return *o.ostr << '\'' << in << '\'';
    00301 }
    00302
    00303
    00304 template <>
    00305 inline std::ostream& operator <<(quote_only_type1 o,
    00306                 const Time& in)
    00307 {
    00308         return *o.ostr << '\'' << in << '\'';
    00309 }
    00310
    00311
    00312 template <>
    00313 inline std::ostream& operator <<(quote_only_type1 o,
    00314                 const DateTime& in)
    00315 {
    00316         return *o.ostr << '\'' << in << '\'';
    00317 }
    00318
    00319
    00320 template <class ST>
    00321 inline std::ostream& operator <<(quote_only_type1 o, const Set<ST>& in)
    00322 {
    00323         return *o.ostr << '\'' << in << '\'';
    00324 }
    00325
    00326 #endif // !defined(DOXYGEN_IGNORE)
    00327
    00328
    00336
    00337 enum quote_double_only_type0
    00338 {
    00339         quote_double_only
    00340 };
    00341
    00342
    00343 #if !defined(DOXYGEN_IGNORE)
    00344 // Doxygen will not generate documentation for this section.
    00345
    00346 struct quote_double_only_type1
    00347 {
    00348         std::ostream* ostr;
    00349         quote_double_only_type1(std::ostream* o) :
    00350         ostr(o)
    00351         {
    00352         }
    00353 };
    00354
    00355
    00356 inline quote_double_only_type1 operator <<(
    00357                 std::ostream& o, quote_double_only_type0 /* esc */)
    00358 {
    00359         return quote_double_only_type1(&o);
    00360 }
    00361
    00362
    00363 struct quote_double_only_type2
    00364 {
    00365         SQLQueryParms *qparms;
    00366         quote_double_only_type2(SQLQueryParms* p) :
    00367         qparms(p)
    00368         {
    00369         }
    00370 };
    00371
    00372
    00373 inline quote_double_only_type2 operator <<(
    00374                 SQLQueryParms& p, quote_double_only_type0 /* esc */)
    00375 {
    00376         return quote_double_only_type2(&p);
    00377 }
    00378
    00379
    00380 MYSQLPP_EXPORT SQLQueryParms& operator <<(quote_double_only_type2 p,
    00381                 SQLString& in);
    00382
    00383
    00384 template <class T>
    00385 inline std::ostream& operator <<(quote_double_only_type1 o, const T& in)
    00386 {
    00387         return *o.ostr << in;
    00388 }
    00389
    00390
    00391 template <>
    00392 inline std::ostream& operator <<(
    00393                 quote_double_only_type1 o, const std::string& in)
    00394 {
    00395         return *o.ostr << '"' << in << '"';
    00396 }
    00397
    00398
    00399 template <>
    00400 MYSQLPP_EXPORT std::ostream& operator <<(quote_double_only_type1 o,
    00401                 const ColData_Tmpl<std::string>& in);
    00402
    00403
    00404 template <>
    00405 MYSQLPP_EXPORT std::ostream & operator <<(quote_double_only_type1 o,
    00406                 const ColData_Tmpl<const_string>& in);
    00407
    00408
    00409 template <>
    00410 inline std::ostream& operator <<(
    00411                 quote_double_only_type1 o, const Date& in)
    00412 {
    00413         return *o.ostr << '"' << in << '"';
    00414 }
    00415
    00416
    00417 template <>
    00418 inline std::ostream& operator <<(
    00419                 quote_double_only_type1 o, const Time& in)
    00420 {
    00421         return *o.ostr << '"' << in << '"';
    00422 }
    00423
    00424
    00425 template <>
    00426 inline std::ostream& operator <<(
    00427                 quote_double_only_type1 o, const DateTime& in)
    00428 {
    00429         return *o.ostr << '"' << in << '"';
    00430 }
    00431
    00432
    00433 template <class ST>
    00434 inline std::ostream& operator <<(quote_double_only_type1 o,
    00435                 const Set<ST>& in)
    00436 {
    00437         return *o.ostr << '"' << in << '"';
    00438 }
    00439
    00440 #endif // !defined(DOXYGEN_IGNORE)
    00441
    00442
    00449
    00450 enum escape_type0 { escape };
    00451
    00452
    00453 #if !defined(DOXYGEN_IGNORE)
    00454 // Doxygen will not generate documentation for this section.
    00455
    00456 struct escape_type1
    00457 {
    00458         std::ostream* ostr;
    00459         escape_type1(std::ostream* o) :
    00460         ostr(o)
    00461         {
    00462         }
    00463 };
    00464
    00465
    00466 inline escape_type1 operator <<(std::ostream& o,
    00467                 escape_type0 /*esc */)
    00468 {
    00469         return escape_type1(&o);
    00470 }
    00471
    00472
    00473 struct escape_type2
    00474 {
    00475         SQLQueryParms *qparms;
    00476         escape_type2(SQLQueryParms* p) :
    00477         qparms(p)
    00478         {
    00479         }
    00480 };
    00481
    00482
    00483 inline escape_type2 operator <<(SQLQueryParms& p,
    00484                 escape_type0 /*esc */)
    00485 {
    00486         return escape_type2(&p);
    00487 }
    00488
    00489 #endif // !defined(DOXYGEN_IGNORE)
    00490
    00491
    00498
    00499 MYSQLPP_EXPORT SQLQueryParms& operator <<(escape_type2 p,
    00500                 SQLString& in);
    00501
    00502
    00511
    00512 template <class T>
    00513 inline std::ostream& operator <<(escape_type1 o, const T& in)
    00514 {
    00515         return *o.ostr << in;
    00516 }
    00517
    00518
    00519 template <>
    00520 MYSQLPP_EXPORT std::ostream& operator <<(escape_type1 o,
    00521                 const std::string& in);
    00522
    00523
    00524 template <>
    00525 MYSQLPP_EXPORT std::ostream& operator <<(escape_type1 o,
    00526                 const char* const& in);
    00527
    00528
    00529 template <>
    00530 MYSQLPP_EXPORT std::ostream& operator <<(escape_type1 o,
    00531                 const ColData_Tmpl<std::string>& in);
    00532
    00533
    00534 template <>
    00535 MYSQLPP_EXPORT std::ostream& operator <<(escape_type1 o,
    00536                 const ColData_Tmpl<const_string>& in);
    00537
    00538
    00545
    00546 template <>
    00547 inline std::ostream& operator <<(escape_type1 o,
    00548                 char* const& in)
    00549 {
    00550         return operator <<(o, const_cast<const char* const&>(in));
    00551 }
    00552
    00553
    00556
    00557 inline std::ostream& operator <<(escape_type1 o,
    00558                 char in[])
    00559 {
    00560         return operator <<(o, static_cast<const char* const&>(in));
    00561 }
    00562
    00563 inline std::ostream& operator <<(escape_type1 o,
    00564                 const char in[])
    00565 {
    00566         return operator <<(o, const_cast<char* const&>(in));
    00567 }
    00568
    00569
    00580
    00581 enum do_nothing_type0
    00582 {
    00583         do_nothing
    00584 };
    00585
    00586
    00587 #if !defined(DOXYGEN_IGNORE)
    00588 // Doxygen will not generate documentation for this section.
    00589
    00590 struct do_nothing_type1
    00591 {
    00592         std::ostream* ostr;
    00593         do_nothing_type1(std::ostream* o) :
    00594         ostr(o)
    00595         {
    00596         }
    00597 };
    00598
    00599
    00600 inline do_nothing_type1 operator <<(std::ostream& o,
    00601                 do_nothing_type0 /*esc */)
    00602 {
    00603         return do_nothing_type1(&o);
    00604 }
    00605
    00606
    00607 template <class T>
    00608 inline std::ostream& operator <<(do_nothing_type1 o, const T& in)
    00609 {
    00610         return *o.ostr << in;
    00611 }
    00612
    00613
    00614 struct do_nothing_type2
    00615 {
    00616         SQLQueryParms *qparms;
    00617         do_nothing_type2(SQLQueryParms* p) :
    00618         qparms(p)
    00619         {
    00620         }
    00621 };
    00622
    00623
    00624 inline do_nothing_type2 operator <<(SQLQueryParms& p,
    00625                 do_nothing_type0 /* esc */)
    00626 {
    00627         return do_nothing_type2(&p);
    00628 }
    00629
    00630
    00631 MYSQLPP_EXPORT SQLQueryParms& operator <<(do_nothing_type2 p,
    00632                 SQLString& in);
    00633
    00634 #endif // !defined(DOXYGEN_IGNORE)
    00635
    00636
    00646
    00647 enum ignore_type0
    00648 {
    00649         ignore
    00650 };
    00651
    00652
    00653 #if !defined(DOXYGEN_IGNORE)
    00654 // Doxygen will not generate documentation for this section.
    00655
    00656 struct ignore_type2
    00657 {
    00658         SQLQueryParms* qparms;
    00659         ignore_type2(SQLQueryParms* p) :
    00660         qparms(p)
    00661         {
    00662         }
    00663 };
    00664
    00665
    00666 inline ignore_type2 operator <<(SQLQueryParms& p,
    00667                 ignore_type0 /* esc*/)
    00668 {
    00669         return ignore_type2(&p);
    00670 }
    00671
    00672
    00673 MYSQLPP_EXPORT SQLQueryParms& operator <<(ignore_type2 p,
    00674                 SQLString& in);
    00675
    00676 #endif // !defined(DOXYGEN_IGNORE)
    00677
    00678 } // end namespace mysqlpp
    00679
    00680 #endif