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
00029
00030
00031
00032
00033
00034
00035
00036
00038
00039 #ifndef PQXXOBJECT_UPDATE_QUERY_H
00040 #define PQXXOBJECT_UPDATE_QUERY_H
00041
00042 #include <list>
00043 #include <string>
00044 #include <sstream>
00045 #include <utility>
00046
00047 #include <pqxx/util>
00048
00049 #include <pqxxobject/field_base.h>
00050 #include <pqxxobject/query.h>
00051 #include <pqxxobject/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 m_field_list.push_back(query_helper<T, F>::apply(field));
00088 }
00089
00094 template< typename T, template <typename> class F >
00095 void where(F<T>& field)
00096 {
00097 m_where.clear();
00098 query_helper<T, F> helper;
00099 std::pair<std::string, std::string> values(helper.apply(field));
00100 std::ostringstream tmp;
00101 tmp << values.first << " = " << values.second;
00102 m_where = tmp.str();
00103 }
00104
00105
00110 void where(const std::string& where_string)
00111 {
00112 m_where = where_string;
00113 }
00114
00119 void remove(const field_base& field);
00120
00125 std::string str() const;
00126
00127 private:
00128 std::string m_table_name;
00129 std::list<field_value> m_field_list;
00130 std::string m_where;
00131
00132 };
00133
00134 template<typename T>
00135 std::ostream& operator << (std::ostream& os, const update_query& rhs)
00136 {
00137 os << rhs.str();
00138 }
00139
00140 };
00141
00142 #endif // PQXXOBJECT_UPDATE_QUERY_H