From 0d49ea1fe08cf1eab41a00149393a291c65a59d7 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Thu, 25 Jan 2024 20:32:06 +0300 Subject: Turn odb-tests repository into package for muti-package repository --- odb-tests/sqlite/attach/driver.cxx | 109 +++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 odb-tests/sqlite/attach/driver.cxx (limited to 'odb-tests/sqlite/attach/driver.cxx') diff --git a/odb-tests/sqlite/attach/driver.cxx b/odb-tests/sqlite/attach/driver.cxx new file mode 100644 index 0000000..25d279f --- /dev/null +++ b/odb-tests/sqlite/attach/driver.cxx @@ -0,0 +1,109 @@ +// file : sqlite/attach/driver.cxx +// license : GNU GPL v2; see accompanying LICENSE file + +// Test attached database support. +// + +#include // std::unique_ptr +#include + +#include + +#include +#include +#include + +#include + +#include "test.hxx" +#include "test-odb.hxx" + +#undef NDEBUG +#include + +using namespace std; +namespace sqlite = odb::sqlite; +using namespace sqlite; + +int +main (int argc, char* argv[]) +{ + try + { + unique_ptr mdb (create_specific_database (argc, argv)); + + { + object o ("one"); + + connection_ptr c (mdb->connection ()); + + database adb (c, ":memory:", "adb"); + + // Create schema similar to create_database(). + // + { + c->execute ("PRAGMA foreign_keys=OFF"); + + transaction t (c->begin ()); + odb::schema_catalog::create_schema (adb); + t.commit (); + + c->execute ("PRAGMA foreign_keys=ON"); + } + + { + transaction t (c->begin ()); + mdb->persist (o); + adb.persist (o); + t.commit (); + } + + { + transaction t (c->begin ()); + unique_ptr p (adb.load (o.id)); + t.commit (); + + assert (p->str == o.str); + } + + { + o.str = "two"; + + transaction t (c->begin ()); + adb.update (o); + t.commit (); + } + + { + typedef sqlite::query query; + + transaction t (c->begin ()); + unique_ptr p (adb.query_one (query::str == "two")); + t.commit (); + + assert (p->str == o.str); + } + + { + transaction t (c->begin ()); + adb.erase (o); + t.commit (); + } + + { + transaction t (c->begin ()); + unique_ptr p (mdb->load (o.id)); + t.commit (); + + assert (p.get () != 0); + } + + adb.detach (); + } + } + catch (const odb::exception& e) + { + cerr << e.what () << endl; + return 1; + } +} -- cgit v1.1