From 6a3ddb6bd80f3c0c4d7b6957cb7be1f3d8713720 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 26 Apr 2012 17:16:24 +0200 Subject: Add test for readonly object with auto id --- common/readonly/driver.cxx | 24 ++++++++++++++++++++++++ common/readonly/test.hxx | 16 +++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) (limited to 'common') diff --git a/common/readonly/driver.cxx b/common/readonly/driver.cxx index b39ab38..b67ed4f 100644 --- a/common/readonly/driver.cxx +++ b/common/readonly/driver.cxx @@ -287,6 +287,30 @@ main (int argc, char* argv[]) assert (*o.pl == 2 && *o.cpl == 2 && *o.pcl == 2 && *o.cpcl == 1); } + + // Readonly object with auto id. + // + { + ro_auto o1 (1); + ro_auto o2 (2); + + { + transaction t (db->begin ()); + db->persist (o1); + db->persist (o2); + t.commit (); + } + + { + transaction t (db->begin ()); + auto_ptr p1 (db->load (o1.id)); + auto_ptr p2 (db->load (o2.id)); + t.commit (); + + assert (p1->num == o1.num); + assert (p2->num == o2.num); + } + } } catch (const odb::exception& e) { diff --git a/common/readonly/test.hxx b/common/readonly/test.hxx index a29a2bd..0b73d94 100644 --- a/common/readonly/test.hxx +++ b/common/readonly/test.hxx @@ -10,7 +10,7 @@ #include -// Simple readonly value. +// Simple readonly object. // #pragma db object struct simple @@ -209,4 +209,18 @@ struct wrapper const std::auto_ptr cpcl; }; +// Readonly object with auto id. +// +#pragma db object readonly +struct ro_auto +{ + ro_auto (unsigned long n): num (n) {} + ro_auto () {} + + #pragma db id auto + unsigned long id; + + unsigned long num; +}; + #endif // TEST_HXX -- cgit v1.1