Project

General

Profile

Bug #4294 » source.txt

lm at, 07/07/2015 02:53 PM

 
#define BOOST_SIGNALS_NO_DEPRECATION_WARNING
#include <Wt/Dbo/Dbo>
#include <Wt/Dbo/backend/Sqlite3>
#include <string>

Wt::Dbo::Session * sesion;

struct meal : public Wt::Dbo::Dbo<meal>
{
long long ptr_id;
std::string name;
template<class A> void persist(A&a)
{
Wt::Dbo::field(a, name, "name");
}
};

std::vector<meal> get_meals(void)
{
Wt::Dbo::Transaction t {*sesion};
std::cerr << "getting meals...\n";
auto query = sesion->find<meal>();
auto meals = query.resultList();
std::vector<meal> ret;
for (auto const & m : meals)
{
std::cerr << "meal\n";
ret.push_back(*m);
ret.back().ptr_id = m.id();
}
return ret;
}

int main()
{
Wt::Dbo::backend::Sqlite3 db("meals.db");
db.setProperty("show-queries", "true");
Wt::Dbo::Session s;
s.setConnection(db);
s.mapClass<meal>("meal");
sesion = &s;

auto const & meals = get_meals();
for (auto const & m : meals)
{
std::cerr << "meal " << m.name << " has id " << m.id() << " and ptr_id = " << m.ptr_id << '\n';
}
}

(4-4/5)