aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2012-09-11 13:55:48 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2012-09-11 13:55:48 +0200
commitd87a78e24d5988cfa3556707b7beffd1b0c15901 (patch)
tree32115e06a1bdade66efea1e304ba5863feaa5a21
parent32fcd732e2535090174142dd15b8b74fc444a9c2 (diff)
Add support for mapping std::array to BLOB and char[16] to UUID types
-rw-r--r--common/blob/driver.cxx6
-rw-r--r--common/blob/test.hxx36
-rw-r--r--mssql/types/driver.cxx2
-rw-r--r--mssql/types/test.hxx5
-rw-r--r--pgsql/types/driver.cxx4
-rw-r--r--pgsql/types/test.hxx2
-rw-r--r--pgsql/types/traits.hxx27
7 files changed, 45 insertions, 37 deletions
diff --git a/common/blob/driver.cxx b/common/blob/driver.cxx
index b280771..ec507ce 100644
--- a/common/blob/driver.cxx
+++ b/common/blob/driver.cxx
@@ -5,6 +5,8 @@
// Test BLOB mapping.
//
+#include <common/config.hxx> // HAVE_CXX11
+
#include <memory> // std::auto_ptr
#include <cassert>
#include <iostream>
@@ -47,6 +49,10 @@ main (int argc, char* argv[])
o.vuc.assign (udata, udata + sizeof (data));
memcpy (o.c, data, sizeof (data));
memcpy (o.uc, udata, sizeof (data));
+#ifdef HAVE_CXX11
+ memcpy (o.a.data (), data, sizeof (data));
+ memcpy (o.ua.data (), udata, sizeof (data));
+#endif
o.cont.push_back (1);
o.cont.push_back (2);
o.cont.push_back (3);
diff --git a/common/blob/test.hxx b/common/blob/test.hxx
index 9e6434b..5d88d8b 100644
--- a/common/blob/test.hxx
+++ b/common/blob/test.hxx
@@ -5,17 +5,25 @@
#ifndef TEST_HXX
#define TEST_HXX
+#include <common/config.hxx> // HAVE_CXX11
+
#include <vector>
#include <cstring> // std::memcmp
+#ifdef HAVE_CXX11
+# include <array>
+#endif
+
#include <odb/core.hxx>
#ifdef ODB_COMPILER
# if defined(ODB_DATABASE_PGSQL)
# define BLOB_TYPE "BYTEA"
# elif defined(ODB_DATABASE_MSSQL)
+//# define BLOB_TYPE "VARBINARY(1024)"
# define BLOB_TYPE "VARBINARY(max)"
# else
+//# define BLOB_TYPE "RAW(1024)"
# define BLOB_TYPE "BLOB"
# endif
#endif
@@ -41,7 +49,16 @@ struct object
#pragma db type(BLOB_TYPE)
unsigned char uc[1024];
- // Make sure we can still use std::vector<char> as a container.
+#ifdef HAVE_CXX11
+ #pragma db type(BLOB_TYPE)
+ std::array<char, 1024> a;
+
+ #pragma db type(BLOB_TYPE)
+ std::array<char, 1024> ua;
+#endif
+
+ // Make sure we can still use std::vector<char> and std::array<char>
+ // as containers.
//
std::vector<unsigned char> cont;
};
@@ -49,13 +66,16 @@ struct object
inline bool
operator== (const object& x, const object& y)
{
- return
- x.id_ == y.id_ &&
- x.vc == y.vc &&
- x.vuc == y.vuc &&
- std::memcmp (x.c, y.c, sizeof (x.c)) == 0 &&
- std::memcmp (x.uc, y.uc, sizeof (x.uc)) == 0 &&
- x.cont == y.cont;
+ return x.id_ == y.id_
+ && x.vc == y.vc
+ && x.vuc == y.vuc
+ && std::memcmp (x.c, y.c, sizeof (x.c)) == 0
+ && std::memcmp (x.uc, y.uc, sizeof (x.uc)) == 0
+#ifdef HAVE_CXX11
+ && x.a == y.a
+ && x.ua == y.ua
+#endif
+ && x.cont == y.cont;
}
#endif // TEST_HXX
diff --git a/mssql/types/driver.cxx b/mssql/types/driver.cxx
index 2d32429..3f5577f 100644
--- a/mssql/types/driver.cxx
+++ b/mssql/types/driver.cxx
@@ -97,6 +97,8 @@ main (int argc, char* argv[])
o.guid_.Data3 = 0x4E4D;
memcpy (&o.guid_.Data4, "\xB2\x2F\x56\x44\x3C\xFA\x54\x3F", 8);
#endif
+ memcpy (o.uuid_, "\x6F\x84\x6D\x41\xC8\x9A\x4E\x4D\xB2\x2F"
+ "\x56\x44\x3C\xFA\x54\x3F", 16);
// Persist.
//
diff --git a/mssql/types/test.hxx b/mssql/types/test.hxx
index b89a621..d735acf 100644
--- a/mssql/types/test.hxx
+++ b/mssql/types/test.hxx
@@ -241,6 +241,9 @@ struct object
GUID guid_;
#endif
+ #pragma db type ("UNIQUEIDENTIFIER")
+ char uuid_[16];
+
bool
operator== (const object& y) const
{
@@ -301,7 +304,7 @@ struct object
#ifdef _WIN32
&& std::memcmp (&guid_, &y.guid_, sizeof (guid_)) == 0
#endif
- ;
+ && std::memcmp (uuid_, y.uuid_, sizeof (uuid_)) == 0;
}
};
diff --git a/pgsql/types/driver.cxx b/pgsql/types/driver.cxx
index 724a068..8b51cc5 100644
--- a/pgsql/types/driver.cxx
+++ b/pgsql/types/driver.cxx
@@ -61,6 +61,10 @@ main (int argc, char* argv[])
o.bit_.c = 0;
o.bit_.d = 1;
+ // 6F846D41-C89A-4E4D-B22F-56443CFA543F
+ memcpy (o.uuid_, "\x6F\x84\x6D\x41\xC8\x9A\x4E\x4D\xB2\x2F"
+ "\x56\x44\x3C\xFA\x54\x3F", 16);
+
o.enum_ = green;
// Persist.
diff --git a/pgsql/types/test.hxx b/pgsql/types/test.hxx
index 856e981..34f913f 100644
--- a/pgsql/types/test.hxx
+++ b/pgsql/types/test.hxx
@@ -150,7 +150,7 @@ struct object
// Other types.
//
#pragma db type ("UUID")
- unsigned char uuid_[16];
+ char uuid_[16];
// Test ENUM representation.
//
diff --git a/pgsql/types/traits.hxx b/pgsql/types/traits.hxx
index 0ec4079..10dcb24 100644
--- a/pgsql/types/traits.hxx
+++ b/pgsql/types/traits.hxx
@@ -130,33 +130,6 @@ namespace odb
};
template <>
- class value_traits<unsigned char[16], id_uuid>
- {
- public:
- typedef unsigned char* value_type;
- typedef details::ubuffer query_type;
- typedef unsigned char* image_type;
-
- static void
- set_value (unsigned char v[16],
- const unsigned char* i,
- bool is_null)
- {
- if (!is_null)
- std::memcpy (v, i, 16);
- else
- std::memset (v, 0, 16);
- }
-
- static void
- set_image (unsigned char* i, bool& is_null, const unsigned char v[16])
- {
- is_null = false;
- std::memcpy (i, v, 16);
- }
- };
-
- template <>
class value_traits<string_ptr, id_string>
{
public: