aboutsummaryrefslogtreecommitdiff
path: root/mapping
diff options
context:
space:
mode:
authorConstantin Michael <constantin@codesynthesis.com>2011-11-17 11:44:45 +0200
committerConstantin Michael <constantin@codesynthesis.com>2011-11-17 11:44:45 +0200
commit9616e3e84946c23f64448978d9459d2a25202833 (patch)
tree209fe102c7d73b57ff3d2a4cdf68ad2df705704f /mapping
parent508512b8db199c5bcc1affc237d6eac4e0a4818d (diff)
Add examples for Oracle
Diffstat (limited to 'mapping')
-rw-r--r--mapping/database.hxx7
-rw-r--r--mapping/traits-oracle.hxx95
-rw-r--r--mapping/traits.hxx2
3 files changed, 104 insertions, 0 deletions
diff --git a/mapping/database.hxx b/mapping/database.hxx
index 4f3bb9a..4badc4e 100644
--- a/mapping/database.hxx
+++ b/mapping/database.hxx
@@ -25,6 +25,8 @@
# include <odb/sqlite/database.hxx>
#elif defined(DATABASE_PGSQL)
# include <odb/pgsql/database.hxx>
+#elif defined(DATABASE_ORACLE)
+# include <odb/oracle/database.hxx>
#endif
inline std::auto_ptr<odb::database>
@@ -44,6 +46,8 @@ create_database (int& argc, char* argv[])
odb::sqlite::database::print_usage (cerr);
#elif defined(DATABASE_PGSQL)
odb::pgsql::database::print_usage (cerr);
+#elif defined(DATABASE_ORACLE)
+ odb::oracle::database::print_usage (cerr);
#endif
exit (0);
@@ -73,6 +77,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, false, 873, 873));
#endif
return db;
diff --git a/mapping/traits-oracle.hxx b/mapping/traits-oracle.hxx
new file mode 100644
index 0000000..f1dcfe9
--- /dev/null
+++ b/mapping/traits-oracle.hxx
@@ -0,0 +1,95 @@
+// file : mapping/traits-oracle.hxx
+// author : Constantin Michael <constantin@codesynthesis.com>
+// copyright : not copyrighted - public domain
+
+#ifndef TRAITS_ORACLE_HXX
+#define TRAITS_ORACLE_HXX
+
+//
+// Oracle implementation.
+//
+
+#include <cstddef> // std::size_t
+#include <cstring> // std::strncmp, std::memcpy
+
+#include <odb/oracle/traits.hxx>
+#include <odb/oracle/details/date.hxx>
+
+#include "person.hxx" // date
+
+namespace odb
+{
+ namespace oracle
+ {
+ 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 char* image_type;
+
+ static void
+ set_value (date& v, const char* b, bool is_null)
+ {
+ if (!is_null)
+ {
+ short y;
+ unsigned char m, d, h, min, s;
+ details::get_date (b, y, m, d, h, min, s);
+
+ v = date (y, m, d);
+ }
+ else
+ v = date (0, 0, 0);
+ }
+
+ static void
+ set_image (char* b, bool& is_null, const date& v)
+ {
+ is_null = false;
+
+ short y (static_cast<short> (v.year ()));
+ unsigned char m (static_cast<unsigned char> (v.month ()));
+ unsigned char d (static_cast<unsigned char> (v.day ()));
+
+ details::set_date (b, y, m, d, 0, 0, 0);
+ }
+ };
+ }
+}
+
+#endif // TRAITS_ORACLE_HXX
diff --git a/mapping/traits.hxx b/mapping/traits.hxx
index 1d2412b..1ef2858 100644
--- a/mapping/traits.hxx
+++ b/mapping/traits.hxx
@@ -13,6 +13,8 @@
# include "traits-sqlite.hxx"
#elif defined(DATABASE_PGSQL)
# include "traits-pgsql.hxx"
+#elif defined(DATABASE_ORACLE)
+# include "traits-oracle.hxx"
#endif
#endif // TRAITS_HXX