summaryrefslogtreecommitdiff
path: root/odb-tests/sqlite/native
diff options
context:
space:
mode:
Diffstat (limited to 'odb-tests/sqlite/native')
-rw-r--r--odb-tests/sqlite/native/buildfile15
-rw-r--r--odb-tests/sqlite/native/driver.cxx74
-rw-r--r--odb-tests/sqlite/native/testscript9
3 files changed, 98 insertions, 0 deletions
diff --git a/odb-tests/sqlite/native/buildfile b/odb-tests/sqlite/native/buildfile
new file mode 100644
index 0000000..76f6b53
--- /dev/null
+++ b/odb-tests/sqlite/native/buildfile
@@ -0,0 +1,15 @@
+# file : sqlite/native/buildfile
+# license : GNU GPL v2; see accompanying LICENSE file
+
+if ($build.meta_operation != 'dist')
+{
+ assert ($sqlite) "sqlite should be configured for this test"
+ assert (!$multi) "multi-database mode is not supported by this test"
+}
+
+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
+:
+$*