From 87991ad75cf0a33b2503dbb8725c3c6609254961 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 14 Sep 2010 15:44:06 +0200 Subject: Add hello example --- hello/driver.cxx | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 hello/driver.cxx (limited to 'hello/driver.cxx') diff --git a/hello/driver.cxx b/hello/driver.cxx new file mode 100644 index 0000000..2c3edff --- /dev/null +++ b/hello/driver.cxx @@ -0,0 +1,65 @@ +// file : hello/driver.cxx +// author : Boris Kolpackov +// copyright : not copyrighted - public domain + +#include // std::auto_ptr +#include + +#include +#include + +#include "database.hxx" // create_database + +#include "person.hxx" +#include "person-odb.hxx" + +using namespace std; +using namespace odb; + +int +main (int argc, char* argv[]) +{ + try + { + auto_ptr db (create_database (argc, argv)); + + // Create a few persistent person objects. + // + { + person john_doe ("John", "Doe", 29); + person jane_doe ("Jane", "Doe", 28); + person joe_dirt ("Joe", "Dirt", 31); + + transaction t (db->begin_transaction ()); + + db->persist (john_doe); + db->persist (jane_doe); + db->persist (joe_dirt); + + t.commit (); + } + + // Say hello to those under 30. + // + { + typedef odb::query query; + typedef odb::result result; + + transaction t (db->begin_transaction ()); + + result r (db->query (query::age < 30)); + + for (result::iterator i (r.begin ()); i != r.end (); ++i) + { + cout << "Hello, " << i->first () << " " << i->last () << "!" << endl; + } + + t.commit (); + } + } + catch (const odb::exception& e) + { + cerr << e.what () << endl; + return 1; + } +} -- cgit v1.1