From 2ef165437ce47f50110a9b230f302c5cd5fde1d4 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 25 Feb 2011 12:07:33 +0200 Subject: Add support for examples in subdirectories Move the schema example to schema/custom. --- schema/driver.cxx | 119 ------------------------------------------------------ 1 file changed, 119 deletions(-) delete mode 100644 schema/driver.cxx (limited to 'schema/driver.cxx') diff --git a/schema/driver.cxx b/schema/driver.cxx deleted file mode 100644 index 3f36f03..0000000 --- a/schema/driver.cxx +++ /dev/null @@ -1,119 +0,0 @@ -// file : schema/driver.cxx -// author : Boris Kolpackov -// copyright : not copyrighted - public domain - -#include // std::auto_ptr -#include - -#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)); - - // Create the database schema. - // - { - transaction t (db->begin ()); - - // Try to drop the tables if they exist and ignore the error - // if they don't. - // - try - { - db->execute ("DROP TABLE Employer"); - db->execute ("DROP TABLE Employee"); - db->execute ("DROP TABLE EmployeeDegree"); - } - catch (const odb::exception&) - { - } - - db->execute ( - "CREATE TABLE Employer (" - "name VARCHAR (255) NOT NULL PRIMARY KEY)"); - - db->execute ( - "CREATE TABLE Employee (" - "ssn INTEGER UNSIGNED NOT NULL PRIMARY KEY," - "first_name VARCHAR (255) NOT NULL," - "last_name VARCHAR (255) NOT NULL," - "employer VARCHAR (255) NOT NULL REFERENCES Employer (name))"); - - db->execute ( - "CREATE TABLE EmployeeDegree (" - "ssn INTEGER UNSIGNED NOT NULL REFERENCES Employee (ssn)," - "degree VARCHAR (255) NOT NULL)"); - - t.commit (); - } - - // Create a few persistent objects. - // - { - shared_ptr st (new employer ("Simple Tech Ltd")); - - shared_ptr john (new employee (1, "John", "Doe", st)); - shared_ptr jane (new employee (2, "Jane", "Doe", st)); - - john->degrees ().push_back ("BA"); - john->degrees ().push_back ("MSc"); - jane->degrees ().push_back ("Ph.D."); - - transaction t (db->begin ()); - - db->persist (st); - db->persist (john); - db->persist (jane); - - t.commit (); - } - - // Load employees with "Doe" as the last name and print what we've got. - // - { - typedef odb::query query; - typedef odb::result result; - - session s; - transaction t (db->begin ()); - - result r (db->query (query::name::last == "Doe")); - - for (result::iterator i (r.begin ()); i != r.end (); ++i) - { - cout << i->name ().first () << " " << i->name ().last () << endl - << " employer: " << i->employer ()->name () << endl; - - for (degrees::iterator j (i->degrees ().begin ()); - j != i->degrees ().end (); - ++j) - { - cout << " degree: " << *j << endl; - } - - cout << endl; - } - - t.commit (); - } - } - catch (const odb::exception& e) - { - cerr << e.what () << endl; - return 1; - } -} -- cgit v1.1