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

query.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 
00020 /***********************************************************************
00021  Copyright (c) 1998 by Kevin Atkinson, (c) 1999, 2000 and 2001 by
00022  MySQL AB, and (c) 2004, 2005 by Educational Technology Resources, Inc.
00023  Others may also hold copyrights on code in this file.  See the CREDITS
00024  file in the top directory of the distribution for details.
00025 
00026  This file is part of MySQL++.
00027 
00028  MySQL++ is free software; you can redistribute it and/or modify it
00029  under the terms of the GNU Lesser General Public License as published
00030  by the Free Software Foundation; either version 2.1 of the License, or
00031  (at your option) any later version.
00032 
00033  MySQL++ is distributed in the hope that it will be useful, but WITHOUT
00034  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00035  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
00036  License for more details.
00037 
00038  You should have received a copy of the GNU Lesser General Public
00039  License along with MySQL++; if not, write to the Free Software
00040  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
00041  USA
00042 ***********************************************************************/
00043 
00044 #ifndef MYSQLPP_QUERY_H
00045 #define MYSQLPP_QUERY_H
00046 
00047 #include "defs.h"
00048 
00049 #include "coldata.h"
00050 #include "connection.h"
00051 #include "result.h"
00052 #include "sql_query.h"
00053 
00054 #include <mysql.h>
00055 
00057 #define mysql_query_define1(RETURN, FUNC) \
00058   RETURN FUNC (const char* str); \
00059   RETURN FUNC (parms &p);\
00060   mysql_query_define0(RETURN,FUNC) \
00061 
00062 
00063 #define mysql_query_define2(FUNC) \
00064   template <class T1> void FUNC (T1 &con, const char* str); \
00065   template <class T1> void FUNC (T1 &con, parms &p, query_reset r = RESET_QUERY);\
00066   template <class T1> void FUNC (T1 &con, ss a)\
00067         {FUNC (con, parms() << a);}\
00068   template <class T1> void FUNC (T1 &con, ss a, ss b)\
00069         {FUNC (con, parms() << a << b);}\
00070   template <class T1> void FUNC (T1 &con, ss a, ss b, ss c)\
00071         {FUNC (con, parms() << a << b << c);}\
00072   template <class T1> void FUNC (T1 &con, ss a, ss b, ss c, ss d)\
00073         {FUNC (con, parms() << a << b << c << d);}\
00074   template <class T1> void FUNC (T1 &con, ss a, ss b, ss c, ss d, ss e)\
00075         {FUNC (con, parms() << a << b << c << d << e);} \
00076   template <class T1> void FUNC (T1 &con, ss a, ss b, ss c, ss d, ss e, ss f)\
00077         {FUNC (con, parms() << a << b << c << d << e << f);}\
00078   template <class T1> void FUNC (T1 &con,ss a,ss b,ss c,ss d,ss e,ss f,ss g)\
00079         {FUNC (con, parms() << a << b << c << d << e << f << g);}\
00080   template <class T1> void FUNC (T1 &con,ss a,ss b,ss c,ss d,ss e,ss f,ss g,ss h)\
00081         {FUNC (con, parms() << a << b << c << d << e << f << g << h);}\
00082   template <class T1> void FUNC (T1 &con, ss a, ss b, ss c, ss d, ss e, ss f, ss g, ss h, ss i)\
00083         {FUNC (con, parms() << a << b << c << d << e << f << g << h << i);}\
00084   template <class T1> void FUNC (T1 &con, ss a,ss b,ss c,ss d,ss e,ss f,ss g,ss h,ss i,ss j)\
00085         {FUNC (con, parms() <<a <<b <<c <<d <<e <<f <<g <<h <<i <<j);}\
00086   template <class T1> void FUNC (T1 &con, ss a,ss b,ss c,ss d,ss e,ss f,ss g,ss h,ss i,ss j,ss k)\
00087         {FUNC (con, parms() <<a <<b <<c <<d <<e <<f <<g <<h <<i <<j <<k);}\
00088   template <class T1> void FUNC (T1 &con, ss a,ss b,ss c,ss d,ss e,ss f,ss g,ss h,ss i,ss j,ss k,\
00089                            ss l)\
00090         {FUNC (con, parms() <<a <<b <<c <<d <<e <<f <<g <<h <<i <<j <<k <<l);}\
00091 
00092 namespace mysqlpp {
00093 
00100 
00101 class Query : public SQLQuery
00102 {
00103 private:
00104         Connection* mysql;
00105         bool throw_exceptions;
00106 
00107         my_ulonglong affected_rows() const;
00108         my_ulonglong insert_id();
00109         std::string info();
00110         bool lock();
00111         void unlock();
00112 
00113 public:
00120         Query(Connection * c, bool te = false) :
00121         SQLQuery(),
00122         mysql(c),
00123         throw_exceptions(te)
00124         {
00125                 Success = true;
00126         }
00127 
00129         Query(const Query& q);
00130 
00133         std::string error();
00134 
00136         bool success();
00137 
00139         std::string preview() { return str(def); }
00140 
00142         std::string preview(parms& p) { return str(p); }
00143 
00155         bool exec(const std::string& str);
00156 
00176         ResNSel execute() { return execute(def); }
00177 
00201         ResUse use() { return use(def); }
00202 
00224         Result store() { return store(def); }
00225 
00243         template <class Sequence> void storein_sequence(Sequence& con,
00244                         query_reset r = RESET_QUERY)
00245         {
00246                 storein_sequence_(con, def, r);
00247         }
00248 
00256         template <class Set> void storein_set(Set& con,
00257                         query_reset r = RESET_QUERY)
00258         {
00259                 storein_set(con, def, r);
00260         }
00261 
00280         template<class Container> void storein(Container& con,
00281                         query_reset r = RESET_QUERY) { storein(con, def, r); }
00282 
00293         template<class T> Query& update(const T& o, const T& n)
00294         {
00295                 SQLQuery::update(o, n);
00296                 return *this;
00297         }
00298 
00307         template<class T> Query& insert(const T& v)
00308         {
00309                 SQLQuery::insert(v);
00310                 return *this;
00311         }
00312 
00326         template<class Iter> Query& insert(Iter first, Iter last)
00327         {
00328                 SQLQuery::insert(first, last);
00329                 return *this;
00330         }
00331 
00341         template<class T> Query& replace(const T& v)
00342         {
00343                 SQLQuery::replace(v);
00344                 return *this;
00345         }
00346 
00347 #if !defined(DOXYGEN_IGNORE)
00348         // Declare the remaining overloads.  These are hidden down here partly
00349         // to keep the above code clear, but also so that we may hide them
00350         // from Doxygen, which gets confused by macro instantiations that look
00351         // like method declarations.
00352         mysql_query_define0(std::string, preview)
00353         mysql_query_define1(ResNSel, execute)
00354         mysql_query_define1(ResUse, use)
00355         mysql_query_define1(Result, store)
00356         mysql_query_define2(storein_sequence)
00357         mysql_query_define2(storein_set)
00358         mysql_query_define2(storein)
00359 #endif // !defined(DOXYGEN_IGNORE)
00360 };
00361 
00362 
00363 #if !defined(DOXYGEN_IGNORE)
00364 // Doxygen will not generate documentation for this section.
00365 
00366 template<class Seq>
00367 void Query::storein_sequence(Seq& seq, parms& p, query_reset r)
00368 {
00369         r = parsed.size() ? DONT_RESET : RESET_QUERY;
00370         mysql->storein_sequence(seq, str(p, r));
00371 }
00372 
00373 template<class Set>
00374 void Query::storein_set(Set& sett, parms& p, query_reset r)
00375 {
00376         r = parsed.size() ? DONT_RESET : RESET_QUERY;
00377         mysql->storein_set(sett, str(p, r));
00378 }
00379 
00380 template<class Sequence>
00381 void Query::storein_sequence(Sequence& seq, const char *s)
00382 {
00383         mysql->storein_sequence(seq, s);
00384 }
00385 
00386 template<class Set>
00387 void Query::storein_set(Set& sett, const char *s)
00388 {
00389         mysql->storein_set(sett, s);
00390 }
00391 
00392 template<class T>
00393 void Query::storein(T& con, parms& p, query_reset r)
00394 {
00395         r = parsed.size() ? DONT_RESET : RESET_QUERY;
00396         mysql->storein(con, str(p, r));
00397 }
00398 
00399 template<class T>
00400 void Query::storein(T& con, const char *s)
00401 {
00402         mysql->storein(con, s);
00403 }
00404 
00405 #endif // !defined(DOXYGEN_IGNORE)
00406 
00407 } // end namespace mysqlpp
00408 
00409 #endif
00410 

Generated on Thu May 26 09:39:58 2005 for MySQL++ by doxygen1.2.18