00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <sstream>
00022
00023 #include <pqxx-object/exceptions.h>
00024
00025 #include "places.h"
00026
00027 using std::ostringstream;
00028 using std::string;
00029 using std::vector;
00030
00031 using namespace pqxxobject;
00032
00033 Place::Place():
00034 m_id(0),
00035 m_name(""),
00036 m_gridref("")
00037 {
00038 }
00039
00040 Place::Place(const std::string& name,
00041 const std::string& gridref):
00042 m_id(0),
00043 m_name(name),
00044 m_gridref(gridref)
00045 {
00046 }
00047
00048 Place::~Place()
00049 {
00050 }
00051
00052 int
00053 Place::get_id() const
00054 {
00055 return m_id;
00056 }
00057
00058 const std::string&
00059 Place::get_name() const
00060 {
00061 return m_name;
00062 }
00063
00064 void
00065 Place::set_name(const std::string& name)
00066 {
00067 m_name = name;
00068 }
00069
00070 const std::string&
00071 Place::get_gridref() const
00072 {
00073 return m_gridref;
00074 }
00075
00076 void
00077 Place::set_gridref(const std::string& gridref)
00078 {
00079 m_gridref = gridref;
00080 }
00081
00082 Place::row_ptr
00083 Place::create(pqxx::result::const_iterator row,
00084 pqxxobject::transaction& tran)
00085 {
00086 row_ptr p(new Place);
00087 row->at("id").to(p->m_id.get_value());
00088 row->at("name").to(p->m_name.get_value());
00089 row->at("gridref").to(p->m_gridref.get_value());
00090 return p;
00091 }
00092
00093 void
00094 Place::insert_impl(pqxxobject::transaction& tran)
00095 {
00096 ostringstream query;
00097
00098 query << "INSERT INTO places (name, gridref) "
00099 << "VALUES ('" << get_name()
00100 << "', '" << get_gridref() << "')";
00101
00102 tran.perform(query.str(), 1, 1);
00103 }
00104
00105 void
00106 Place::update_impl(pqxxobject::transaction& tran)
00107 {
00108 ostringstream query;
00109
00110 query << "UPDATE places "
00111 << "SET name = '" << get_name()
00112 << "', gridref = '" << get_gridref() << "' "
00113 << "WHERE (id = " << get_id() << ")";
00114
00115 tran.perform(query.str(), 1, 1);
00116 }
00117
00118 void
00119 Place::erase_impl(pqxxobject::transaction& tran)
00120 {
00121 ostringstream query;
00122
00123 query << "DELETE FROM places "
00124 << "WHERE (id = " << get_id() << ")";
00125
00126 tran.perform(query.str(), 1, 1);
00127 }
00128
00129 void
00130 Place::refresh_impl(pqxxobject::transaction& tran)
00131 {
00132 }
00133
00134
00135 PlaceTable::PlaceTable(pqxxobject::transaction& tran):
00136 table_base(tran)
00137 {
00138 }
00139
00140 PlaceTable::~PlaceTable()
00141 {
00142 }
00143
00144 PlaceTable::row_list_ptr
00145 PlaceTable::get_list(sort_order order)
00146 {
00147 ostringstream query;
00148 query << "SELECT id, name, gridref FROM places "
00149 << "ORDER BY ";
00150
00151 if (order == ORDER_ID)
00152 query << "id";
00153 else if (order == ORDER_NAME)
00154 query << "name";
00155 else if (order == ORDER_GRIDREF)
00156 query << "gridref";
00157 else
00158 query << "name";
00159
00160 return find_many(query.str());
00161 }
00162
00163 PlaceTable::row_ptr
00164 PlaceTable::find(int place_id)
00165 {
00166 ostringstream query;
00167 query << "SELECT id, name, gridref FROM places "
00168 << "WHERE (id = " << place_id << ")";
00169
00170 return find_one(query.str());
00171 }
00172
00173
00174 PlaceTable::row_ptr
00175 PlaceTable::find_name(const std::string& name)
00176 {
00177 ostringstream query;
00178 query << "SELECT id, name, gridref FROM places "
00179 << "WHERE (name = '" << name << "')";
00180
00181 return find_one(query.str());
00182 }
00183
00184 PlaceTable::row_list_ptr
00185 PlaceTable::find_gridref(const std::string& gridref)
00186 {
00187 ostringstream query;
00188 query << "SELECT id, name, gridref FROM places "
00189 << "WHERE (gridref = '" << gridref << "')";
00190
00191 return find_many(query.str());
00192 }