// file : common/object/driver.cxx // copyright : Copyright (c) 2009-2019 Code Synthesis Tools CC // license : GNU GPL v2; see accompanying LICENSE file // Test persistent classes. // #include // std::auto_ptr #include #include #include #include #include #include "test.hxx" #include "test-odb.hxx" using namespace std; using namespace odb::core; int main (int argc, char* argv[]) { try { auto_ptr db (create_database (argc, argv)); // Test persistent class template instantiation. // { using namespace test1; pair_object po; po.second = "abc"; derived d; d.x = "abc"; d.n = 123; // persist // { transaction t (db->begin ()); db->persist (po); db->persist (d); t.commit (); } // load & check // { transaction t (db->begin ()); auto_ptr po1 (db->load (po.first)); auto_ptr d1 (db->load (d.id)); t.commit (); assert (po == *po1); assert (d.x == d1->x); assert (d.n == d1->n); } // Test the API confusion. // { transaction t (db->begin ()); db->update (po); db->reload (po); db->erase (po); db->query (); t.commit (); } } } catch (const odb::exception& e) { cerr << e.what () << endl; return 1; } }