From c7d1b5f11a45319d71b6fe0929fc616a1640579f Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 10 Feb 2012 15:06:17 +0200 Subject: Use correct truncation vector in container loading code --- mysql/truncation/driver.cxx | 33 +++++++++++++++++++++++++++++++-- mysql/truncation/test.hxx | 34 ++++++++++++++++++---------------- 2 files changed, 49 insertions(+), 18 deletions(-) (limited to 'mysql/truncation') diff --git a/mysql/truncation/driver.cxx b/mysql/truncation/driver.cxx index 292d08f..43f18b3 100644 --- a/mysql/truncation/driver.cxx +++ b/mysql/truncation/driver.cxx @@ -10,6 +10,7 @@ #include #include +#include #include #include @@ -23,9 +24,9 @@ using namespace odb::core; int main (int argc, char* argv[]) { - // The default pre-allocated buffer is 512 bytes long. + // The default pre-allocated buffer is 256 bytes long. // - string long_str (640, 'c'); // This will get the buffer to 1024 + string long_str (300, 'c'); // This will get the buffer to 512 string longer_str (1025, 'b'); try @@ -152,6 +153,34 @@ main (int argc, char* argv[]) t.commit (); } } + + // Test containers. + // + { + auto_ptr db (create_database (argc, argv)); + + // Use different connections to persist and load the object. + // + connection_ptr c1 (db->connection ()); + connection_ptr c2 (db->connection ()); + + container o (1); + o.vec_.push_back (string (513, 'x')); + + { + transaction t (c1->begin ()); + db->persist (o); + t.commit (); + } + + { + transaction t (c2->begin ()); + auto_ptr p (db->load (1)); + t.commit (); + + assert (p->vec_ == o.vec_); + } + } } catch (const odb::exception& e) { diff --git a/mysql/truncation/test.hxx b/mysql/truncation/test.hxx index b3128c0..b1aae1a 100644 --- a/mysql/truncation/test.hxx +++ b/mysql/truncation/test.hxx @@ -6,19 +6,15 @@ #define TEST_HXX #include +#include + #include #pragma db object table ("test") struct object1 { - object1 (unsigned long id) - : id_ (id) - { - } - - object1 () - { - } + object1 () {} + object1 (unsigned long id): id_ (id) {} #pragma db id unsigned long id_; @@ -29,14 +25,8 @@ struct object1 #pragma db object table ("test") struct object2 { - object2 (unsigned long id) - : id_ (id) - { - } - - object2 () - { - } + object2 () {} + object2 (unsigned long id): id_ (id) {} #pragma db id unsigned long id_; @@ -44,4 +34,16 @@ struct object2 std::string str_; }; +#pragma db object +struct container +{ + container () {} + container (unsigned long id) : id_ (id) {} + + #pragma db id + unsigned long id_; + + std::vector vec_; +}; + #endif // TEST_HXX -- cgit v1.1