From 7ee76c54fca21bed2b94ebf1e71f723670f135fe Mon Sep 17 00:00:00 2001 From: Constantin Michael Date: Mon, 11 Apr 2011 18:21:12 +0200 Subject: Add SQLite support to Qt example --- qt/README | 2 +- qt/database.hxx | 22 +++++++++++++++++++++- qt/driver.cxx | 5 ++--- qt/employee.hxx | 5 ++++- 4 files changed, 28 insertions(+), 6 deletions(-) (limited to 'qt') diff --git a/qt/README b/qt/README index b67eea4..111a39b 100644 --- a/qt/README +++ b/qt/README @@ -11,7 +11,7 @@ employee.hxx establish a bidirectional employee-employer relationship. We also use the QDateTime type to store the employee's date of birth and QString to store the employee's first and last name. Finally we use QByteArray - to represent the persons genetic fingerprint. + to store the person's public key. employee-odb.hxx employee-odb.ixx diff --git a/qt/database.hxx b/qt/database.hxx index c7c6957..5b96ae9 100644 --- a/qt/database.hxx +++ b/qt/database.hxx @@ -18,6 +18,10 @@ #if defined(DATABASE_MYSQL) # include +#elif defined(DATABASE_SQLITE) +# include +# include +# include #endif inline std::auto_ptr @@ -33,14 +37,30 @@ create_database (int& argc, char* argv[]) #if defined(DATABASE_MYSQL) odb::mysql::database::print_usage (cerr); +#elif defined(DATABASE_SQLITE) + odb::sqlite::database::print_usage (cerr); #endif exit (0); } #if defined(DATABASE_MYSQL) - return auto_ptr (new odb::mysql::database (argc, argv)); + auto_ptr db (new odb::mysql::database (argc, argv)); +#elif defined(DATABASE_SQLITE) + auto_ptr db ( + new odb::sqlite::database ( + argc, argv, false, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE)); + + // Create the database schema. + // + { + transaction t (db->begin ()); + schema_catalog::create_schema (*db); + t.commit (); + } #endif + + return db; } #endif // DATABASE_HXX diff --git a/qt/driver.cxx b/qt/driver.cxx index 5dfe13f..f41e4d6 100644 --- a/qt/driver.cxx +++ b/qt/driver.cxx @@ -18,8 +18,7 @@ using namespace odb::core; ostream& operator << (ostream& os, const QString& s) { - os << s.toStdString (); - return os; + return os << s.toStdString (); } int @@ -66,7 +65,7 @@ main (int argc, char* argv[]) t.commit (); } - // Complex Systems Inc.dob + // Complex Systems Inc. // { shared_ptr er (new employer ("Complex Systems Inc")); diff --git a/qt/employee.hxx b/qt/employee.hxx index 1e39993..60c6980 100644 --- a/qt/employee.hxx +++ b/qt/employee.hxx @@ -86,7 +86,10 @@ public: const QDate& born, const QByteArray& public_key, shared_ptr employer) - : first_ (first), last_ (last), born_(born), public_key_(public_key), + : first_ (first), + last_ (last), + born_ (born), + public_key_ (public_key), employer_ (employer) { } -- cgit v1.1