From ab994fdada3eebc794d6b1686f55a35420e4d758 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 25 Apr 2012 10:45:32 +0200 Subject: New example, inheritance/polymorphism Also move the inheritance example to inheritance/reuse. --- inheritance/driver.cxx | 81 -------------------------------------------------- 1 file changed, 81 deletions(-) delete mode 100644 inheritance/driver.cxx (limited to 'inheritance/driver.cxx') diff --git a/inheritance/driver.cxx b/inheritance/driver.cxx deleted file mode 100644 index 38964af..0000000 --- a/inheritance/driver.cxx +++ /dev/null @@ -1,81 +0,0 @@ -// file : inheritance/driver.cxx -// copyright : not copyrighted - public domain - -#include // std::auto_ptr -#include - -#include -#include - -#include "database.hxx" // create_database - -#include "employee.hxx" -#include "employee-odb.hxx" - -using namespace std; -using namespace odb::core; - -int -main (int argc, char* argv[]) -{ - try - { - auto_ptr db (create_database (argc, argv)); - - // Add a few employees and contractors to the database. - // - { - permanent_employee p1 ("John", "Doe"); - permanent_employee p2 ("Jane", "Doe"); - - temporary_employee t1 ("John", "Smith", 6); - temporary_employee t2 ("Jane", "Smith", 12); - - contractor c1 ("Joe", "Doe", "j.doe@example.com"); - contractor c2 ("Joe", "Smith", "j.smith@example.com"); - - transaction t (db->begin ()); - db->persist (p1); - db->persist (p2); - db->persist (t1); - db->persist (t2); - db->persist (c1); - db->persist (c2); - t.commit (); - } - - // Lookup a contractor based on the email address. - // - { - transaction t (db->begin ()); - auto_ptr c (db->load ("j.smith@example.com")); - t.commit (); - - cout << c->first () << " " << c->last () << " " << c->email () << endl; - } - - // Query for temporary employees that have John as first name. - // - { - typedef odb::query query; - typedef odb::result result; - - transaction t (db->begin ()); - - result r (db->query (query::first == "John")); - - for (result::iterator i (r.begin ()); i != r.end (); ++i) - { - cout << i->first () << " " << i->last () << " " - << i->duration () << " months" << endl; - } - - t.commit (); - } - } - catch (const odb::exception& e) - { - cerr << e.what () << endl; - return 1; - } -} -- cgit v1.1