diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2011-07-22 14:49:29 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2011-07-22 17:57:00 +0200 |
commit | b8fe0a2a11f3d51e969128c7f02a83cf9b9d65df (patch) | |
tree | 57246395b150229c267b2c10d3c11ab4b89b6184 /common/default/driver.cxx | |
parent | aa82673655e7aecd7cf2e7e9b5fd407eee2b01f2 (diff) |
Add pragma for setting type's or member's default value
New pragma: default. New test: default.
Diffstat (limited to 'common/default/driver.cxx')
-rw-r--r-- | common/default/driver.cxx | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/common/default/driver.cxx b/common/default/driver.cxx new file mode 100644 index 0000000..32c1923 --- /dev/null +++ b/common/default/driver.cxx @@ -0,0 +1,76 @@ +// file : common/default/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +// Test default values. +// + +#include <memory> // std::auto_ptr +#include <cassert> +#include <iostream> + +#include <odb/database.hxx> +#include <odb/transaction.hxx> + +#include <common/common.hxx> + +#include "test.hxx" +#include "test-odb.hxx" + +using namespace std; +using namespace odb::core; + +int +main (int argc, char* argv[]) +{ + try + { + auto_ptr<database> db (create_database (argc, argv)); + + // Insert an object using an ad-hoc SQL statement. This way + // we get all the default values. + // + { + transaction t (db->begin ()); + db->execute ("INSERT INTO object (obj_id) VALUES (1)"); + t.commit (); + } + + // Now load the object and check all the values. + // + { + transaction t (db->begin ()); + auto_ptr<object> o (db->load<object> (1)); + t.commit (); + + assert (o->b); + assert (o->pi == 1234); + assert (o->ni == -1234); + assert (o->zi == 0); + assert (o->pf == 1.234); + assert (o->nf == -1.234); + assert (o->zf == 0.0); + assert (o->sf == 1.123e+10); + assert (o->str == "Someone's string"); + assert (o->e == green); + } + + // Check the NULL default value using a query. + // + { + typedef odb::query<object> query; + typedef odb::result<object> result; + + transaction t (db->begin ()); + result r (db->query<object> (query::null.is_null ())); + assert (!r.empty ()); + t.commit (); + } + } + catch (const odb::exception& e) + { + cerr << e.what () << endl; + return 1; + } +} |