summaryrefslogtreecommitdiff
path: root/odb-tests/qt/mssql
diff options
context:
space:
mode:
Diffstat (limited to 'odb-tests/qt/mssql')
-rw-r--r--odb-tests/qt/mssql/basic/buildfile39
-rw-r--r--odb-tests/qt/mssql/basic/driver.cxx67
-rw-r--r--odb-tests/qt/mssql/basic/test.hxx46
-rw-r--r--odb-tests/qt/mssql/basic/testscript11
-rw-r--r--odb-tests/qt/mssql/date-time/buildfile39
-rw-r--r--odb-tests/qt/mssql/date-time/driver.cxx96
-rw-r--r--odb-tests/qt/mssql/date-time/test.hxx68
-rw-r--r--odb-tests/qt/mssql/date-time/testscript11
8 files changed, 377 insertions, 0 deletions
diff --git a/odb-tests/qt/mssql/basic/buildfile b/odb-tests/qt/mssql/basic/buildfile
new file mode 100644
index 0000000..f86b2f8
--- /dev/null
+++ b/odb-tests/qt/mssql/basic/buildfile
@@ -0,0 +1,39 @@
+# file : qt/mssql/basic/buildfile
+# license : GNU GPL v2; see accompanying LICENSE file
+
+if ($build.meta_operation != 'dist')
+{
+ assert ($qt) \
+ "Qt version should be configured for this test via config.odb_tests.qt variable"
+
+ assert ($mssql) "mssql should be configured for this test"
+ assert (!$multi) "multi-database mode is not supported by this test"
+}
+
+import meta_libs = libodb%lib{odb}
+import meta_libs += libodb-qt%lib{odb-qt}
+import meta_libs += "libQt$(qt_ver)Core"%lib{"Qt$(qt_ver)Core"}
+
+import libs = libodb-mssql%lib{odb-mssql}
+import libs += lib{common}
+
+exe{driver}: {hxx cxx}{* -test-odb} {hxx ixx cxx}{test-odb} testscript
+
+# Introduce the metadata library target to make sure the libodb library is
+# resolved for the odb_compile ad hoc rule (see build/root.build for details).
+#
+libue{test-meta}: $meta_libs
+
+<{hxx ixx cxx}{test-odb}>: hxx{test} libue{test-meta}
+
+exe{driver}: libue{test-meta} $libs
+
+# Specify the ODB custom options to be used by the odb_compile ad hoc rule
+# (see build/root.build for details).
+#
+odb_options = --std ($qt_ver == 5 ? c++11 : c++17) \
+ --table-prefix qt_mssql_basic_ \
+ --profile qt/basic \
+ --generate-schema
+
+cxx.poptions =+ "-I$out_base" "-I$src_base"
diff --git a/odb-tests/qt/mssql/basic/driver.cxx b/odb-tests/qt/mssql/basic/driver.cxx
new file mode 100644
index 0000000..24526b2
--- /dev/null
+++ b/odb-tests/qt/mssql/basic/driver.cxx
@@ -0,0 +1,67 @@
+// file : qt/mssql/basic/driver.cxx
+// license : GNU GPL v2; see accompanying LICENSE file
+
+// Test Qt basic type persistence. SQL Server version.
+//
+
+#include <memory> // std::unique_ptr
+#include <iostream>
+
+#include <QtCore/QCoreApplication>
+
+#include <odb/mssql/database.hxx>
+#include <odb/mssql/transaction.hxx>
+
+#include <libcommon/common.hxx>
+
+#include "test.hxx"
+#include "test-odb.hxx"
+
+#undef NDEBUG
+#include <cassert>
+
+using namespace std;
+using namespace odb::core;
+
+int
+main (int argc, char* argv[])
+{
+ QCoreApplication app (argc, argv);
+
+ try
+ {
+ unique_ptr<database> db (create_database (argc, argv));
+
+ object o;
+ o.id_ = "object 1";
+ o.sstr_ = QString (512, 's');
+ o.lstr_ = QString (65000, 'l'); // Test temp buffer boundary.
+ o.snstr_ = QString (512, QChar (0x1234));
+ o.lnstr_ = QString (65536, QChar (0x2345));
+ o.sbuf_ = QByteArray (512, 0x01);
+ o.lbuf_ = QByteArray (65536, 0x02);
+
+ // Persist.
+ //
+ {
+ transaction t (db->begin ());
+ db->persist (o);
+ t.commit ();
+ }
+
+ // Load.
+ //
+ {
+ transaction t (db->begin ());
+ unique_ptr<object> p (db->load<object> (o.id_));
+ t.commit ();
+
+ assert (*p == o);
+ }
+ }
+ catch (const odb::exception& e)
+ {
+ cerr << e.what () << endl;
+ return 1;
+ }
+}
diff --git a/odb-tests/qt/mssql/basic/test.hxx b/odb-tests/qt/mssql/basic/test.hxx
new file mode 100644
index 0000000..bce87b6
--- /dev/null
+++ b/odb-tests/qt/mssql/basic/test.hxx
@@ -0,0 +1,46 @@
+// file : qt/mssql/basic/test.hxx
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef TEST_HXX
+#define TEST_HXX
+
+#include <QtCore/QString>
+#include <QtCore/QByteArray>
+
+#pragma db object
+struct object
+{
+ bool
+ operator== (const object& x) const
+ {
+ return
+ id_ == x.id_ &&
+ sstr_ == x.sstr_ &&
+ lstr_ == x.lstr_ &&
+ snstr_ == x.snstr_ &&
+ lnstr_ == x.lnstr_ &&
+ sbuf_ == x.sbuf_ &&
+ lbuf_ == x.lbuf_;
+ }
+
+ #pragma db id
+ QString id_;
+
+ QString sstr_;
+
+ #pragma db type ("VARCHAR(max)")
+ QString lstr_;
+
+ #pragma db type ("NVARCHAR(512)")
+ QString snstr_;
+
+ #pragma db type ("NVARCHAR(max)")
+ QString lnstr_;
+
+ #pragma db type ("VARBINARY(512)")
+ QByteArray sbuf_;
+
+ QByteArray lbuf_;
+};
+
+#endif // TEST_HXX
diff --git a/odb-tests/qt/mssql/basic/testscript b/odb-tests/qt/mssql/basic/testscript
new file mode 100644
index 0000000..16e5453
--- /dev/null
+++ b/odb-tests/qt/mssql/basic/testscript
@@ -0,0 +1,11 @@
+# file : qt/mssql/basic/testscript
+# license : GNU GPL v2; see accompanying LICENSE file
+
+.include ../../../database-options.testscript
+.include ../../../mssql.testscript
+
++$create_schema
+
+: basics
+:
+$*
diff --git a/odb-tests/qt/mssql/date-time/buildfile b/odb-tests/qt/mssql/date-time/buildfile
new file mode 100644
index 0000000..7dc5549
--- /dev/null
+++ b/odb-tests/qt/mssql/date-time/buildfile
@@ -0,0 +1,39 @@
+# file : qt/mssql/date-time/buildfile
+# license : GNU GPL v2; see accompanying LICENSE file
+
+if ($build.meta_operation != 'dist')
+{
+ assert ($qt) \
+ "Qt version should be configured for this test via config.odb_tests.qt variable"
+
+ assert ($mssql) "mssql should be configured for this test"
+ assert (!$multi) "multi-database mode is not supported by this test"
+}
+
+import meta_libs = libodb%lib{odb}
+import meta_libs += libodb-qt%lib{odb-qt}
+import meta_libs += "libQt$(qt_ver)Core"%lib{"Qt$(qt_ver)Core"}
+
+import libs = libodb-mssql%lib{odb-mssql}
+import libs += lib{common}
+
+exe{driver}: {hxx cxx}{* -test-odb} {hxx ixx cxx}{test-odb} testscript
+
+# Introduce the metadata library target to make sure the libodb library is
+# resolved for the odb_compile ad hoc rule (see build/root.build for details).
+#
+libue{test-meta}: $meta_libs
+
+<{hxx ixx cxx}{test-odb}>: hxx{test} libue{test-meta}
+
+exe{driver}: libue{test-meta} $libs
+
+# Specify the ODB custom options to be used by the odb_compile ad hoc rule
+# (see build/root.build for details).
+#
+odb_options = --std ($qt_ver == 5 ? c++11 : c++17) \
+ --table-prefix qt_mssql_dt_ \
+ --profile qt/date-time \
+ --generate-schema
+
+cxx.poptions =+ "-I$out_base" "-I$src_base"
diff --git a/odb-tests/qt/mssql/date-time/driver.cxx b/odb-tests/qt/mssql/date-time/driver.cxx
new file mode 100644
index 0000000..a555c10
--- /dev/null
+++ b/odb-tests/qt/mssql/date-time/driver.cxx
@@ -0,0 +1,96 @@
+// file : qt/mssql/date-time/driver.cxx
+// license : GNU GPL v2; see accompanying LICENSE file
+
+// Test Qt date/time type persistence. SQL Server version.
+//
+
+#include <memory> // std::unique_ptr
+#include <iostream>
+
+#include <QtCore/QDateTime>
+#include <QtCore/QCoreApplication>
+
+#include <odb/mssql/database.hxx>
+#include <odb/mssql/transaction.hxx>
+
+#include <libcommon/common.hxx>
+
+#include "test.hxx"
+#include "test-odb.hxx"
+
+#undef NDEBUG
+#include <cassert>
+
+using namespace std;
+using namespace odb::core;
+
+int
+main (int argc, char* argv[])
+{
+ QCoreApplication app (argc, argv);
+
+ try
+ {
+ unique_ptr<database> db (create_database (argc, argv));
+
+ object o;
+
+ // Check persistence of null values.
+ //
+ {
+ transaction t (db->begin ());
+ db->persist (o);
+ t.commit ();
+ }
+
+ {
+ transaction t (db->begin ());
+ unique_ptr<object> ol (db->load<object> (o.id));
+ t.commit ();
+
+ assert (ol->is_null ());
+ }
+
+ // Check persistence of valid dates and times.
+ //
+#if !defined(MSSQL_SERVER_VERSION) || MSSQL_SERVER_VERSION >= 1000
+ QDateTime t (QDateTime::currentDateTime ());
+
+ o.date = t.date ();
+ o.date_time = t;
+#endif
+
+ // In DATETIME fractional seconds are rounded to .000, .003, or .007.
+ //
+ o.date_time_dt = QDateTime (QDate (2012, 1, 14),
+ QTime (11, 57, 13, 3));
+
+ // SMALLDATETIME doesn't have seconds (always 0).
+ //
+ o.date_time_sdt = QDateTime (QDate (2012, 1, 14),
+ QTime (11, 57, 0, 0));
+
+#if !defined(MSSQL_SERVER_VERSION) || MSSQL_SERVER_VERSION >= 1000
+ o.time = t.time ();
+#endif
+
+ {
+ transaction t (db->begin ());
+ db->persist (o);
+ t.commit ();
+ }
+
+ {
+ transaction t (db->begin ());
+ unique_ptr<object> ol (db->load<object> (o.id));
+ t.commit ();
+
+ assert (*ol == o);
+ }
+ }
+ catch (const odb::exception& e)
+ {
+ cerr << e.what () << endl;
+ return 1;
+ }
+}
diff --git a/odb-tests/qt/mssql/date-time/test.hxx b/odb-tests/qt/mssql/date-time/test.hxx
new file mode 100644
index 0000000..71769b9
--- /dev/null
+++ b/odb-tests/qt/mssql/date-time/test.hxx
@@ -0,0 +1,68 @@
+// file : qt/mssql/date-time/test.hxx
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef TEST_HXX
+#define TEST_HXX
+
+#include <QtCore/QDateTime>
+
+#include <odb/core.hxx>
+
+#pragma db object
+struct object
+{
+ #pragma db id auto
+ unsigned long id;
+
+#if !defined(MSSQL_SERVER_VERSION) || MSSQL_SERVER_VERSION >= 1000
+ QDate date;
+
+ QDateTime date_time;
+#endif
+
+ #pragma db type ("DATETIME")
+ QDateTime date_time_dt;
+
+ #pragma db type ("SMALLDATETIME")
+ QDateTime date_time_sdt;
+
+#if !defined(MSSQL_SERVER_VERSION) || MSSQL_SERVER_VERSION >= 1000
+ QTime time;
+#endif
+
+ bool
+ operator== (const object& x) const
+ {
+ return
+ id == x.id
+#if !defined(MSSQL_SERVER_VERSION) || MSSQL_SERVER_VERSION >= 1000
+ && date == x.date
+ && date_time == x.date_time
+#endif
+ && date_time_dt == x.date_time_dt
+ && date_time_sdt == x.date_time_sdt
+#if !defined(MSSQL_SERVER_VERSION) || MSSQL_SERVER_VERSION >= 1000
+ && time == x.time
+#endif
+ ;
+ }
+
+ bool
+ is_null () const
+ {
+ return
+ true
+#if !defined(MSSQL_SERVER_VERSION) || MSSQL_SERVER_VERSION >= 1000
+ && date.isNull ()
+ && date_time.isNull ()
+#endif
+ && date_time_dt.isNull ()
+ && date_time_sdt.isNull ()
+#if !defined(MSSQL_SERVER_VERSION) || MSSQL_SERVER_VERSION >= 1000
+ && time.isNull ()
+#endif
+ ;
+ }
+};
+
+#endif // TEST_HXX
diff --git a/odb-tests/qt/mssql/date-time/testscript b/odb-tests/qt/mssql/date-time/testscript
new file mode 100644
index 0000000..16e5453
--- /dev/null
+++ b/odb-tests/qt/mssql/date-time/testscript
@@ -0,0 +1,11 @@
+# file : qt/mssql/basic/testscript
+# license : GNU GPL v2; see accompanying LICENSE file
+
+.include ../../../database-options.testscript
+.include ../../../mssql.testscript
+
++$create_schema
+
+: basics
+:
+$*