From 42a45c8f42888ab6138c45e3b2cbfec50edf6d03 Mon Sep 17 00:00:00 2001 From: Constantin Michael Date: Fri, 25 Mar 2011 17:48:23 +0200 Subject: Add Qt example boilerplate code --- qt/README | 10 +++++----- qt/driver.cxx | 21 ++++++++++----------- qt/employee.hxx | 15 --------------- qt/makefile | 4 ++-- qt/person.hxx | 41 +++++++++++++++++++++++++++++++++++++++++ qt/qt-vc10.vcxproj | 8 ++++---- qt/qt-vc9.vcproj | 8 ++++---- 7 files changed, 66 insertions(+), 41 deletions(-) delete mode 100644 qt/employee.hxx create mode 100644 qt/person.hxx (limited to 'qt') diff --git a/qt/README b/qt/README index 4e94255..94663e1 100644 --- a/qt/README +++ b/qt/README @@ -4,13 +4,13 @@ containers, and value types with the help of the Qt profile library The example consists of the following files: -employee.hxx +person.hxx Describe contents. -employee-odb.hxx -employee-odb.ixx -employee-odb.cxx -employee.sql +person-odb.hxx +person-odb.ixx +person-odb.cxx +person.sql The first three files contain the database support code and the last file contains the database schema for the employee.hxx header. diff --git a/qt/driver.cxx b/qt/driver.cxx index 14f0c0e..1d4e2b3 100644 --- a/qt/driver.cxx +++ b/qt/driver.cxx @@ -11,8 +11,8 @@ #include "database.hxx" // create_database -#include "employee.hxx" -#include "employee-odb.hxx" +#include "person.hxx" +#include "person-odb.hxx" using namespace std; using namespace odb::core; @@ -24,18 +24,17 @@ main (int argc, char* argv[]) { auto_ptr db (create_database (argc, argv)); - employee e; - e.name = "John Doe"; + person p1; + p1.name = "Constantin Michael"; + p1.date_of_birth.setDate (1979, 03, 07); - QChar* c = e.name.data (); - - while (!c->isNull ()) + // Persist. + // { - cout << c->toAscii (); - ++c; + transaction t (db->begin ()); + db->persist (p1); + t.commit (); } - - cout << endl; } catch (const odb::exception& e) { diff --git a/qt/employee.hxx b/qt/employee.hxx deleted file mode 100644 index 2fc124d..0000000 --- a/qt/employee.hxx +++ /dev/null @@ -1,15 +0,0 @@ -// file : qt/employee.hxx -// author : Constantin Michael -// copyright : not copyrighted - public domain - -#ifndef EMPLOYEE_HXX -#define EMPLOYEE_HXX - -#include - -struct employee -{ - QString name; -}; - -#endif // EMPLOYEE_HXX diff --git a/qt/makefile b/qt/makefile index 17e9290..a47858d 100644 --- a/qt/makefile +++ b/qt/makefile @@ -6,7 +6,7 @@ include $(dir $(lastword $(MAKEFILE_LIST)))../build/bootstrap.make cxx_tun := driver.cxx -odb_hdr := employee.hxx +odb_hdr := person.hxx cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o) $(odb_hdr:.hxx=-odb.o)) cxx_od := $(cxx_obj:.o=.o.d) @@ -59,7 +59,7 @@ gen := $(addprefix $(out_base)/,$(genf)) $(gen): $(odb) $(gen): odb := $(odb) -$(gen) $(dist): export odb_options += --database $(db_id) \ +$(gen) $(dist): export odb_options += --database $(db_id) --profile qt \ --generate-query --generate-schema $(gen): cpp_options := -I$(out_base) $(gen): $(odb.l.cpp-options) $(odb_qt.l.cpp-options) $(qt.l.cpp-options) diff --git a/qt/person.hxx b/qt/person.hxx new file mode 100644 index 0000000..28460c4 --- /dev/null +++ b/qt/person.hxx @@ -0,0 +1,41 @@ +// file : qt/person.hxx +// author : Constantin Michael +// copyright : not copyrighted - public domain + +#ifndef EMPLOYEE_HXX +#define EMPLOYEE_HXX + +#include +#include +#include +#include + +#pragma db object +struct time_punchcard +{ + #pragma db id auto + unsigned long id; + + QDateTime date_time; +}; + +#pragma db object +struct person +{ + bool + operator== (const person& x) const + { + return name == x.name && + date_of_birth == x.date_of_birth && + time_of_birth == x.time_of_birth; + } + + #pragma db id + QString name; + + #pragma db type("DATE NOT NULL") + QDate date_of_birth; + QTime time_of_birth; +}; + +#endif // EMPLOYEE_HXX diff --git a/qt/qt-vc10.vcxproj b/qt/qt-vc10.vcxproj index d252a8a..da70445 100644 --- a/qt/qt-vc10.vcxproj +++ b/qt/qt-vc10.vcxproj @@ -92,7 +92,7 @@ 4068;4355;4800;4290;%(DisableSpecificWarnings) - odb-__value__(database)-d.lib;odb-qt-d.lib;qt-core-d.lib;odb-d.lib;%(AdditionalDependencies) + odb-__value__(database)-d.lib;QtCored4.lib;odb-qt-d.lib;odb-d.lib;%(AdditionalDependencies) Console true @@ -107,7 +107,7 @@ 4068;4355;4800;4290;%(DisableSpecificWarnings) - odb-__value__(database)-d.lib;odb-qt-d.lib;qt-core-d.lib;odb-d.lib;%(AdditionalDependencies) + odb-__value__(database)-d.lib;QtCored4.lib;odb-qt-d.lib;odb-d.lib;%(AdditionalDependencies) Console true @@ -124,7 +124,7 @@ 4068;4355;4800;4290;%(DisableSpecificWarnings) - odb-__value__(database).lib;odb-qt.lib;qt-core.lib;odb.lib;%(AdditionalDependencies) + odb-__value__(database).lib;QtCore4.lib;odb-qt.lib;odb.lib;%(AdditionalDependencies) Console true true @@ -143,7 +143,7 @@ 4068;4355;4800;4290;%(DisableSpecificWarnings) - odb-__value__(database).lib;odb-qt.lib;qt-core.lib;odb.lib;%(AdditionalDependencies) + odb-__value__(database).lib;QtCore4.lib;odb-qt.lib;odb.lib;%(AdditionalDependencies) Console true true diff --git a/qt/qt-vc9.vcproj b/qt/qt-vc9.vcproj index 0e7ed9c..81e3fd6 100644 --- a/qt/qt-vc9.vcproj +++ b/qt/qt-vc9.vcproj @@ -64,7 +64,7 @@ />