diff options
Diffstat (limited to 'odb-tests/sqlite/native')
-rw-r--r-- | odb-tests/sqlite/native/buildfile | 12 | ||||
-rw-r--r-- | odb-tests/sqlite/native/driver.cxx | 74 | ||||
-rw-r--r-- | odb-tests/sqlite/native/testscript | 9 |
3 files changed, 95 insertions, 0 deletions
diff --git a/odb-tests/sqlite/native/buildfile b/odb-tests/sqlite/native/buildfile new file mode 100644 index 0000000..49aa05b --- /dev/null +++ b/odb-tests/sqlite/native/buildfile @@ -0,0 +1,12 @@ +# file : sqlite/native/buildfile +# license : GNU GPL v2; see accompanying LICENSE file + +assert ($sqlite && !$multi || $build.meta_operation == 'dist') \ +"sqlite should be configured via config.odb_tests.database variable as a single database" + +import libs = libodb-sqlite%lib{odb-sqlite} +import libs += lib{common} + +exe{driver}: {hxx cxx}{*} $libs testscript + +cxx.poptions =+ "-I$out_base" "-I$src_base" 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; + } +} diff --git a/odb-tests/sqlite/native/testscript b/odb-tests/sqlite/native/testscript new file mode 100644 index 0000000..16f05e0 --- /dev/null +++ b/odb-tests/sqlite/native/testscript @@ -0,0 +1,9 @@ +# file : sqlite/native/testscript +# license : GNU GPL v2; see accompanying LICENSE file + +.include ../../database-options.testscript +.include ../../sqlite.testscript + +: basics +: +$* |