diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2012-09-05 14:58:55 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2012-09-05 14:58:55 +0200 |
commit | 0e6587f29f40a841f0e393887fea4e5cf385e0e6 (patch) | |
tree | a556749c3ee3ac2714c0bb8914277fd0cb8bfb8d /qt | |
parent | 5a16b0511ae3ac491ac23bba07f7259f6c255472 (diff) |
Support for Qt QUuid persistence
This support was added to the basic sub-profile. New test: qt/common/basic.
Updated the qt example to use QUuid as an object id.
Diffstat (limited to 'qt')
-rw-r--r-- | qt/common/basic/driver.cxx | 67 | ||||
-rw-r--r-- | qt/common/basic/makefile | 124 | ||||
-rw-r--r-- | qt/common/basic/test.hxx | 36 | ||||
-rw-r--r-- | qt/common/basic/test.std | 0 | ||||
-rw-r--r-- | qt/common/makefile | 1 |
5 files changed, 228 insertions, 0 deletions
diff --git a/qt/common/basic/driver.cxx b/qt/common/basic/driver.cxx new file mode 100644 index 0000000..5a31674 --- /dev/null +++ b/qt/common/basic/driver.cxx @@ -0,0 +1,67 @@ +// file : qt/common/basic/driver.cxx +// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +// Test Qt basic type persistence (common part). +// + +#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)); + + object o (1); + o.uuid_ = QUuid::createUuid (); + o.null_ = QUuid (); + o.zero_ = QUuid (); + + { + transaction t (db->begin ()); + db->persist (o); + t.commit (); + } + + { + transaction t (db->begin ()); + auto_ptr<object> p (db->load<object> (o.id_)); + t.commit (); + + assert (*p == o); + } + + { + typedef odb::query<object> query; + typedef odb::result<object> result; + + transaction t (db->begin ()); + result r (db->query<object> (query::uuid == o.uuid_)); + result::iterator i (r.begin ()); + assert (i != r.end () && i->id_ == o.id_); + assert (++i == r.end ()); + t.commit (); + } + + } + catch (const odb::exception& e) + { + cerr << e.what () << endl; + return 1; + } +} diff --git a/qt/common/basic/makefile b/qt/common/basic/makefile new file mode 100644 index 0000000..6ede2c6 --- /dev/null +++ b/qt/common/basic/makefile @@ -0,0 +1,124 @@ +# file : qt/common/basic/makefile +# copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC +# license : GNU GPL v2; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../build/bootstrap.make + +cxx_tun := driver.cxx +odb_hdr := test.hxx +cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o) $(odb_hdr:.hxx=-odb.o)) +cxx_od := $(cxx_obj:.o=.o.d) + +common.l := $(out_root)/libcommon/common/common.l +common.l.cpp-options := $(out_root)/libcommon/common/common.l.cpp-options + +driver := $(out_base)/driver +dist := $(out_base)/.dist +test := $(out_base)/.test +clean := $(out_base)/.clean + +# Import. +# +$(call import,\ + $(scf_root)/import/odb/stub.make,\ + odb: odb,odb-rules: odb_rules) + +$(call import,\ + $(scf_root)/import/libodb-qt/stub.make,\ + l: odb_qt.l,cpp-options: odb_qt.l.cpp-options) + +$(call import,\ + $(scf_root)/import/libqt/core/stub.make,\ + l: qt_core.l,cpp-options: qt_core.l.cpp-options) + +# Build. +# +$(driver): $(cxx_obj) $(odb_qt.l) $(common.l) $(qt_core.l) +$(cxx_obj) $(cxx_od): cpp_options := -I$(out_base) -I$(src_base) +$(cxx_obj) $(cxx_od): $(common.l.cpp-options) $(odb_qt.l.cpp-options) \ +$(qt_core.l.cpp-options) + +genf := $(addprefix $(odb_hdr:.hxx=-odb),.hxx .ixx .cxx) $(odb_hdr:.hxx=.sql) +gen := $(addprefix $(out_base)/,$(genf)) + +$(gen): $(odb) +$(gen): odb := $(odb) +$(gen) $(dist): export odb_options += --database $(db_id) \ +--profile qt/basic --generate-schema --generate-query \ +--table-prefix qt_basic_ +$(gen): cpp_options := -I$(src_base) +$(gen): $(common.l.cpp-options) $(odb_qt.l.cpp-options) \ +$(qt_core.l.cpp-options) + +$(call include-dep,$(cxx_od),$(cxx_obj),$(gen)) + +# Alias for default target. +# +$(out_base)/: $(driver) + +# Dist +# +name := $(subst /,-,$(subst $(src_root)/qt/common/,,$(src_base))) + +$(dist): db_id := @database@ +$(dist): sources := $(cxx_tun) +$(dist): headers := $(odb_hdr) +$(dist): data_dist := test.std +$(dist): export name := $(name) +$(dist): export extra_dist := $(data_dist) $(call vc9projs,$(name)) \ +$(call vc10projs,$(name)) +$(dist): + $(call dist-data,$(sources) $(headers) $(data_dist)) + $(call meta-automake,../template/Makefile.am) + $(call meta-vc9projs,../template/template,$(name)) + $(call meta-vc10projs,../template/template,$(name)) + +# Test. +# +$(test): $(driver) $(src_base)/test.std + $(call schema) + $(call message,test $<,$< --options-file $(dcf_root)/db.options \ +>$(out_base)/test.out) + $(call message,,diff -u $(src_base)/test.std $(out_base)/test.out) + $(call message,,rm -f $(out_base)/test.out) + +# Clean. +# +$(clean): \ + $(driver).o.clean \ + $(addsuffix .cxx.clean,$(cxx_obj)) \ + $(addsuffix .cxx.clean,$(cxx_od)) \ + $(addprefix $(out_base)/,$(odb_hdr:.hxx=-odb.cxx.hxx.clean)) + $(call message,,rm -f $(out_base)/test.out) + +# Generated .gitignore. +# +ifeq ($(out_base),$(src_base)) +$(driver): | $(out_base)/.gitignore + +$(out_base)/.gitignore: files := driver $(genf) +$(clean): $(out_base)/.gitignore.clean + +$(call include,$(bld_root)/git/gitignore.make) +endif + +# How to. +# +$(call include,$(bld_root)/dist.make) +$(call include,$(bld_root)/meta/vc9proj.make) +$(call include,$(bld_root)/meta/vc10proj.make) +$(call include,$(bld_root)/meta/automake.make) + +$(call include,$(bld_root)/cxx/standard.make) # cxx_standard +ifdef cxx_standard +$(gen): odb_options += --std $(cxx_standard) +$(call include,$(odb_rules)) +endif + +$(call include,$(bld_root)/cxx/cxx-d.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/o-e.make) + +# Dependencies. +# +$(call import,$(src_root)/libcommon/makefile) diff --git a/qt/common/basic/test.hxx b/qt/common/basic/test.hxx new file mode 100644 index 0000000..6fee19a --- /dev/null +++ b/qt/common/basic/test.hxx @@ -0,0 +1,36 @@ +// file : qt/common/basic/test.hxx +// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef TEST_HXX +#define TEST_HXX + +#include <QUuid> + +#include <odb/core.hxx> + +#pragma db object +struct object +{ + object () {} + object (unsigned long id): id_ (id) {} + + #pragma db id + unsigned long id_; + + QUuid uuid_; + QUuid null_; + + #pragma db not_null + QUuid zero_; + + bool operator== (const object& x) const + { + return id_ == x.id_ && + uuid_ == x.uuid_ && + null_ == x.null_ && + zero_ == x.zero_; + } +}; + +#endif // TEST_HXX diff --git a/qt/common/basic/test.std b/qt/common/basic/test.std new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/qt/common/basic/test.std diff --git a/qt/common/makefile b/qt/common/makefile index 584267e..1ac4f7e 100644 --- a/qt/common/makefile +++ b/qt/common/makefile @@ -5,6 +5,7 @@ include $(dir $(lastword $(MAKEFILE_LIST)))../../build/bootstrap.make tests := \ +basic \ containers \ smart-ptr \ template |