Skip to content

Instantly share code, notes, and snippets.

@shaina7837
Created August 9, 2013 14:21
Show Gist options
  • Save shaina7837/6193975 to your computer and use it in GitHub Desktop.
Save shaina7837/6193975 to your computer and use it in GitHub Desktop.
#include "showpost.h"
Showpost::Showpost(WContainerWidget *parent) : WContainerWidget(parent),sqlite3("datadb")
{
session_.setConnection(sqlite3);
session_.mapClass<Post> ("post");
session_.mapClass<Category> ("category");
sqlite3.setProperty("show-queries","true");
try{
session_.createTables(); }
catch(exception& e){
cerr<<e.what();}
dbo::ptr<Category> cat_ptr;
{
dbo::Transaction T(session_);
Post *post = new Post();
post->postname = "pooja";
post->postcontent = "where`` u?";
dbo::ptr<Post> post_ptr = session_.add(post);
cat_ptr = session_.add(new Category());
cat_ptr.modify()->categoryname = "billi";
post_ptr.modify()->categories.insert(cat_ptr);
std::cerr << "......"<<cat_ptr->posts.size()<<"......."<<endl;
T.commit();
}
{
dbo::Transaction T(session_);
std::cerr << ">>>>>>" << cat_ptr->posts.size() << "<<<<<<" <<endl;
Posts posts = session_.find<Post>();
for(Posts::const_iterator i =cat_ptr->posts.begin(); i !=cat_ptr-> posts.end(); ++i)
{
WText *nameout = new WText((*i)->postname,this);
this->addWidget(new WBreak());
WText *contentout = new WText((*i)->postcontent,this);
this->addWidget(new WBreak());
// dbo::ptr<Category> findcategory = session_.find<Category>().where("category_id = ?").bind("billi");
// WText *catout = new WText("posted under" + findcategory->categoryname + "category",this);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment