diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2024-01-25 20:35:31 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2024-01-25 20:35:31 +0300 |
commit | 3fe9378674c484750e36f01a353ec17977a6f1a3 (patch) | |
tree | f83e61172c9b0877295284f6fd9e67cddb954ee6 /odb-tests/sqlite/native/driver.cxx | |
parent | 451173da3c76fcb9b3aea5c6d97f48b492558392 (diff) | |
parent | 0d49ea1fe08cf1eab41a00149393a291c65a59d7 (diff) |
Merge branch 'odb-tests' into multi-package
Diffstat (limited to 'odb-tests/sqlite/native/driver.cxx')
-rw-r--r-- | odb-tests/sqlite/native/driver.cxx | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/odb-tests/sqlite/native/driver.cxx b/odb-tests/sqlite/native/driver.cxx new file mode 100644 index 0000000..c87aa5d --- /dev/null +++ b/odb-tests/sqlite/native/driver.cxx @@ -0,0 +1,74 @@ +// file : sqlite/native/driver.cxx +// license : GNU GPL v2; see accompanying LICENSE file + +// Test native SQL execution. +// + +#include <memory> // std::unique_ptr +#include <iostream> + +#include <odb/sqlite/database.hxx> +#include <odb/sqlite/transaction.hxx> + +#include <libcommon/common.hxx> + +#undef NDEBUG +#include <cassert> + +using namespace std; +namespace sqlite = odb::sqlite; +using namespace sqlite; + +int +main (int argc, char* argv[]) +{ + try + { + unique_ptr<database> db ( + create_specific_database<database> (argc, argv, false)); + + // Create the database schema. + // + { + transaction t (db->begin ()); + + db->execute ("DROP TABLE IF EXISTS sqlitex_native_test"); + db->execute ("CREATE TABLE sqlitex_native_test (n INTEGER PRIMARY KEY)"); + + t.commit (); + } + + // Insert a few rows. + // + { + transaction t (db->begin ()); + + assert ( + db->execute ("INSERT INTO sqlitex_native_test (n) VALUES (1)") == 1); + + assert ( + db->execute ("INSERT INTO sqlitex_native_test (n) VALUES (2)") == 1); + + t.commit (); + } + + // Select a few rows. + // + { + transaction t (db->begin ()); + + assert ( + db->execute ("SELECT n FROM sqlitex_native_test WHERE n < 3") == 2); + + assert ( + db->execute ("SELECT n FROM sqlitex_native_test WHERE n > 3") == 0); + + t.commit (); + } + } + catch (const odb::exception& e) + { + cerr << e.what () << endl; + return 1; + } +} |