Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

pqxx-object/update_query.h

Go to the documentation of this file.
00001 // database update query class                                   -*- C++ -*-
00002 // $Id: update_query.h,v 1.1 2004/04/01 10:13:09 roger Exp $
00003 //
00004 // Copyright (C) 2003  Roger Leigh <rleigh@debian.org>
00005 //
00006 //
00007 //  All rights reserved.
00008 //
00009 //  Redistribution and use in source and binary forms, with or without
00010 //  modification, are permitted provided that the following conditions
00011 //  are met:
00012 //
00013 //  * Redistributions of source code must retain the above copyright
00014 //    notice, this list of conditions and the following disclaimer.
00015 //  * Redistributions in binary form must reproduce the above
00016 //    copyright notice, this list of conditions and the following
00017 //    disclaimer in the documentation and/or other materials provided
00018 //    with the distribution.
00019 //  * Neither the name of the author, nor the names of other
00020 //    contributors may be used to endorse or promote products derived
00021 //    from this software without specific prior written permission.
00022 //
00023 //  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
00024 //  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
00025 //  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00026 //  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00027 //  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
00028 //  BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00029 //  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
00030 //  TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00031 //  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
00032 //  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
00033 //  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
00034 //  THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00035 //  SUCH DAMAGE.
00036 //
00038 
00039 #ifndef PQXX_OBJECT_UPDATE_QUERY_H
00040 #define PQXX_OBJECT_UPDATE_QUERY_H
00041 
00042 #include <list>
00043 #include <string>
00044 #include <sstream>
00045 #include <utility>
00046 
00047 #include <pqxx/util>
00048 
00049 #include <pqxx-object/field_base.h>
00050 #include <pqxx-object/query.h>
00051 #include <pqxx-object/query_helpers.h>
00052 
00053 namespace pqxxobject
00054 {
00059   class update_query : public query
00060   {
00061   public:
00063     update_query();
00064 
00069     explicit update_query(const std::string& table);
00070 
00072     update_query(const update_query& rhs);
00073 
00075     virtual ~update_query();
00076 
00077     typedef std::pair<std::string, std::string> field_value;
00078 
00083     template< typename T, template <typename> class F >
00084     void add(F<T>& field)
00085     {
00086       remove(field);
00087       query_helper<T, F> helper;
00088       m_field_list.push_back(helper.apply(field));
00089     }
00090 
00095     template< typename T, template <typename> class F >
00096     void where(F<T>& field)
00097     {
00098       m_where.clear();
00099       query_helper<T, F> helper;
00100       std::pair<std::string, std::string> values(helper.apply(field));
00101       std::ostringstream tmp;
00102       tmp << values.first << " = " << values.second;
00103       m_where = tmp.str();
00104     }
00105 
00106 
00111     void where(const std::string& where_string)
00112     {
00113       m_where = where_string;
00114     }
00115 
00120     void remove(const field_base& field);
00121 
00126     std::string str();
00127 
00128   private:
00129     std::string m_table_name;
00130     std::list<field_value> m_field_list;
00131     std::string m_where;
00132 
00133   }; // class update_query
00134 
00135   template<typename T>
00136   std::ostream& operator << (std::ostream& os, const update_query& rhs)
00137   {
00138     os << rhs.str();
00139   }
00140 
00141 }; // namespace pqxxobject
00142 
00143 #endif // PQXX_OBJECT_UPDATE_QUERY_H

Generated on Thu Apr 1 12:53:10 2004 for pqxx-object API Reference by doxygen 1.3.5