aboutsummaryrefslogtreecommitdiff
path: root/mapping
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2012-01-16 09:50:11 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2012-01-16 09:50:11 +0200
commit7d74507aacb63f77b763c940ef6fb6c82cb2445a (patch)
tree9d92e44fd3a5de7a5463b170e5e0a9831d46abeb /mapping
parent24f87489a4d315cc01ca9d49a3f0209522fe6729 (diff)
Add SQL Server support
Diffstat (limited to 'mapping')
-rw-r--r--mapping/database.hxx9
-rw-r--r--mapping/traits-mssql.hxx86
-rw-r--r--mapping/traits.hxx2
3 files changed, 95 insertions, 2 deletions
diff --git a/mapping/database.hxx b/mapping/database.hxx
index 36a9cb7..a3ab8f9 100644
--- a/mapping/database.hxx
+++ b/mapping/database.hxx
@@ -27,6 +27,8 @@
# include <odb/pgsql/database.hxx>
#elif defined(DATABASE_ORACLE)
# include <odb/oracle/database.hxx>
+#elif defined(DATABASE_MSSQL)
+# include <odb/mssql/database.hxx>
#endif
inline std::auto_ptr<odb::database>
@@ -48,6 +50,8 @@ create_database (int& argc, char* argv[])
odb::pgsql::database::print_usage (cerr);
#elif defined(DATABASE_ORACLE)
odb::oracle::database::print_usage (cerr);
+#elif defined(DATABASE_MSSQL)
+ odb::mssql::database::print_usage (cerr);
#endif
exit (0);
@@ -78,8 +82,9 @@ create_database (int& argc, char* argv[])
#elif defined(DATABASE_PGSQL)
auto_ptr<database> db (new odb::pgsql::database (argc, argv));
#elif defined(DATABASE_ORACLE)
- auto_ptr<database> db (
- new odb::oracle::database (argc, argv));
+ auto_ptr<database> db (new odb::oracle::database (argc, argv));
+#elif defined(DATABASE_MSSQL)
+ auto_ptr<database> db (new odb::mssql::database (argc, argv));
#endif
return db;
diff --git a/mapping/traits-mssql.hxx b/mapping/traits-mssql.hxx
new file mode 100644
index 0000000..264a657
--- /dev/null
+++ b/mapping/traits-mssql.hxx
@@ -0,0 +1,86 @@
+// file : mapping/traits-mssql.hxx
+// author : Constantin Michael <constantin@codesynthesis.com>
+// copyright : not copyrighted - public domain
+
+#ifndef TRAITS_MSSQL_HXX
+#define TRAITS_MSSQL_HXX
+
+//
+// SQL Server implementation.
+//
+
+#include <cstddef> // std::size_t
+#include <cstring> // std::strncmp, std::memcpy
+#include <cassert>
+
+#include <odb/mssql/traits.hxx>
+
+#include "person.hxx" // date
+
+namespace odb
+{
+ namespace mssql
+ {
+ template <>
+ class value_traits<bool, id_string>
+ {
+ public:
+ typedef bool value_type;
+ typedef bool query_type;
+ typedef char* image_type;
+
+ static void
+ set_value (bool& v,
+ const char* b,
+ std::size_t n,
+ bool is_null)
+ {
+ v = (!is_null && n == 4 && std::strncmp ("true", b, n) == 0);
+ }
+
+ static void
+ set_image (char* b,
+ std::size_t c,
+ std::size_t& n,
+ bool& is_null,
+ bool v)
+ {
+ is_null = false;
+ n = v ? 4 : 5;
+
+ assert (n <= c);
+
+ std::memcpy (b, (v ? "true" : "false"), n);
+ }
+ };
+
+ template <>
+ class value_traits< ::date, id_date>
+ {
+ public:
+ typedef ::date value_type;
+ typedef ::date query_type;
+ typedef mssql::date image_type;
+
+ static void
+ set_value (value_type& v, const image_type& i, bool is_null)
+ {
+ if (!is_null)
+ v = value_type (static_cast<unsigned int> (i.year), i.month, i.day);
+ else
+ v = value_type (0, 0, 0);
+ }
+
+ static void
+ set_image (image_type& i, bool& is_null, const value_type& v)
+ {
+ is_null = false;
+ i.year = static_cast<SQLSMALLINT> (v.year ());
+ i.month = static_cast<SQLUSMALLINT> (v.month ());
+ i.day = static_cast<SQLUSMALLINT> (v.day ());
+ }
+ };
+ }
+}
+
+#endif // TRAITS_MSSQL_HXX
diff --git a/mapping/traits.hxx b/mapping/traits.hxx
index 1ef2858..c2bec55 100644
--- a/mapping/traits.hxx
+++ b/mapping/traits.hxx
@@ -15,6 +15,8 @@
# include "traits-pgsql.hxx"
#elif defined(DATABASE_ORACLE)
# include "traits-oracle.hxx"
+#elif defined(DATABASE_MSSQL)
+# include "traits-mssql.hxx"
#endif
#endif // TRAITS_HXX