diff options
-rw-r--r-- | odb/qt/basic/basic-mssql.options | 1 | ||||
-rw-r--r-- | odb/qt/basic/basic-mysql.options | 1 | ||||
-rw-r--r-- | odb/qt/basic/basic-oracle.options | 1 | ||||
-rw-r--r-- | odb/qt/basic/basic-pgsql.options | 1 | ||||
-rw-r--r-- | odb/qt/basic/basic-sqlite.options | 1 | ||||
-rw-r--r-- | odb/qt/basic/mssql/default-mapping.hxx | 7 | ||||
-rw-r--r-- | odb/qt/basic/mssql/quuid-traits.hxx | 59 | ||||
-rw-r--r-- | odb/qt/basic/mysql/default-mapping.hxx | 7 | ||||
-rw-r--r-- | odb/qt/basic/mysql/quuid-traits.hxx | 75 | ||||
-rw-r--r-- | odb/qt/basic/oracle/default-mapping.hxx | 7 | ||||
-rw-r--r-- | odb/qt/basic/oracle/quuid-traits.hxx | 71 | ||||
-rw-r--r-- | odb/qt/basic/pgsql/default-mapping.hxx | 7 | ||||
-rw-r--r-- | odb/qt/basic/pgsql/quuid-traits.hxx | 59 | ||||
-rw-r--r-- | odb/qt/basic/sqlite/default-mapping.hxx | 7 | ||||
-rw-r--r-- | odb/qt/basic/sqlite/quuid-traits.hxx | 75 |
15 files changed, 379 insertions, 0 deletions
diff --git a/odb/qt/basic/basic-mssql.options b/odb/qt/basic/basic-mssql.options index 986f77e..e4f0636 100644 --- a/odb/qt/basic/basic-mssql.options +++ b/odb/qt/basic/basic-mssql.options @@ -11,3 +11,4 @@ --hxx-prologue '#include <odb/qt/basic/mssql/qstring-traits.hxx>' --hxx-prologue '#include <odb/qt/basic/mssql/qbyte-array-traits.hxx>' +--hxx-prologue '#include <odb/qt/basic/mssql/quuid-traits.hxx>' diff --git a/odb/qt/basic/basic-mysql.options b/odb/qt/basic/basic-mysql.options index 896389a..5810744 100644 --- a/odb/qt/basic/basic-mysql.options +++ b/odb/qt/basic/basic-mysql.options @@ -11,3 +11,4 @@ --hxx-prologue '#include <odb/qt/basic/mysql/qstring-traits.hxx>' --hxx-prologue '#include <odb/qt/basic/mysql/qbyte-array-traits.hxx>' +--hxx-prologue '#include <odb/qt/basic/mysql/quuid-traits.hxx>' diff --git a/odb/qt/basic/basic-oracle.options b/odb/qt/basic/basic-oracle.options index 61a3e7c..dc4cdf5 100644 --- a/odb/qt/basic/basic-oracle.options +++ b/odb/qt/basic/basic-oracle.options @@ -11,3 +11,4 @@ --hxx-prologue '#include <odb/qt/basic/oracle/qstring-traits.hxx>' --hxx-prologue '#include <odb/qt/basic/oracle/qbyte-array-traits.hxx>' +--hxx-prologue '#include <odb/qt/basic/oracle/quuid-traits.hxx>' diff --git a/odb/qt/basic/basic-pgsql.options b/odb/qt/basic/basic-pgsql.options index 72ed520..bc8eb0c 100644 --- a/odb/qt/basic/basic-pgsql.options +++ b/odb/qt/basic/basic-pgsql.options @@ -11,3 +11,4 @@ --hxx-prologue '#include <odb/qt/basic/pgsql/qstring-traits.hxx>' --hxx-prologue '#include <odb/qt/basic/pgsql/qbyte-array-traits.hxx>' +--hxx-prologue '#include <odb/qt/basic/pgsql/quuid-traits.hxx>' diff --git a/odb/qt/basic/basic-sqlite.options b/odb/qt/basic/basic-sqlite.options index 1486e4d..3ef354b 100644 --- a/odb/qt/basic/basic-sqlite.options +++ b/odb/qt/basic/basic-sqlite.options @@ -11,3 +11,4 @@ --hxx-prologue '#include <odb/qt/basic/sqlite/qstring-traits.hxx>' --hxx-prologue '#include <odb/qt/basic/sqlite/qbyte-array-traits.hxx>' +--hxx-prologue '#include <odb/qt/basic/sqlite/quuid-traits.hxx>' diff --git a/odb/qt/basic/mssql/default-mapping.hxx b/odb/qt/basic/mssql/default-mapping.hxx index 2a1b6af..916d306 100644 --- a/odb/qt/basic/mssql/default-mapping.hxx +++ b/odb/qt/basic/mssql/default-mapping.hxx @@ -7,6 +7,7 @@ #include <QtCore/QString> #include <QtCore/QByteArray> +#include <QtCore/QUuid> // By default map QString to SQL Server VARCHAR(512) for non-id members // and to VARCHAR(256) for id members (the same as the default mapping @@ -20,4 +21,10 @@ // #pragma db value(QByteArray) type("VARBINARY(max)") null +// By default map QUuid to SQL Server UNIQUEIDENTIFIER and use NULL to +// represent null UUIDs. If NULL is disabled (e.g., at the member level), +// then we store the null UUID (i.e., all bytes are zero). +// +#pragma db value(QUuid) type("UNIQUEIDENTIFIER") null + #endif // ODB_QT_BASIC_MSSQL_DEFAULT_MAPPING_HXX diff --git a/odb/qt/basic/mssql/quuid-traits.hxx b/odb/qt/basic/mssql/quuid-traits.hxx new file mode 100644 index 0000000..7302921 --- /dev/null +++ b/odb/qt/basic/mssql/quuid-traits.hxx @@ -0,0 +1,59 @@ +// file : odb/qt/basic/mssql/uuid-traits.hxx +// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_QT_BASIC_MSSQL_UUID_TRAITS_HXX +#define ODB_QT_BASIC_MSSQL_UUID_TRAITS_HXX + +#include <odb/pre.hxx> + +#include <cstring> // std::memcpy + +#include <QtCore/QUuid> + +#include <odb/mssql/traits.hxx> + +namespace odb +{ + namespace mssql + { + template <> + class default_value_traits<QUuid, id_uniqueidentifier> + { + public: + typedef QUuid value_type; + typedef value_type query_type; + typedef uniqueidentifier image_type; + + static void + set_value (value_type& v, const uniqueidentifier& i, bool is_null) + { + if (!is_null) + std::memcpy (&v.data1, &i, 16); + else + v = QUuid (); + } + + static void + set_image (uniqueidentifier& i, bool& is_null, const value_type& v) + { + // If we can, store nil as NULL. Otherwise, store it as a value. + // + is_null = is_null && v.isNull (); + + if (!is_null) + std::memcpy (&i, &v.data1, 16); + } + }; + + template <> + struct default_type_traits<QUuid> + { + static const database_type_id db_type_id = id_uniqueidentifier; + }; + } +} + +#include <odb/post.hxx> + +#endif // ODB_QT_BASIC_MSSQL_UUID_TRAITS_HXX diff --git a/odb/qt/basic/mysql/default-mapping.hxx b/odb/qt/basic/mysql/default-mapping.hxx index 49f28fa..492a30e 100644 --- a/odb/qt/basic/mysql/default-mapping.hxx +++ b/odb/qt/basic/mysql/default-mapping.hxx @@ -7,6 +7,7 @@ #include <QtCore/QString> #include <QtCore/QByteArray> +#include <QtCore/QUuid> // Map QString to MySQL TEXT for non-id and to VARCHAR(256) for id members. // MySQL cannot have primary key of the TEXT type. Allow NULL values by @@ -19,4 +20,10 @@ // #pragma db value(QByteArray) type("BLOB") null +// By default map QUuid to MySQL BINARY(16) and use NULL to represent null +// UUIDs. If NULL is disabled (e.g., at the member level), then we store +// the null UUID (i.e., all bytes are zero). +// +#pragma db value(QUuid) type("BINARY(16)") null + #endif // ODB_QT_BASIC_MYSQL_DEFAULT_MAPPING_HXX diff --git a/odb/qt/basic/mysql/quuid-traits.hxx b/odb/qt/basic/mysql/quuid-traits.hxx new file mode 100644 index 0000000..9b66e8b --- /dev/null +++ b/odb/qt/basic/mysql/quuid-traits.hxx @@ -0,0 +1,75 @@ +// file : odb/qt/basic/mysql/uuid-traits.hxx +// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_QT_BASIC_MYSQL_UUID_TRAITS_HXX +#define ODB_QT_BASIC_MYSQL_UUID_TRAITS_HXX + +#include <odb/pre.hxx> + +#include <cstring> // std::memcpy +#include <cassert> + +#include <QtCore/QUuid> + +#include <odb/mysql/traits.hxx> + +namespace odb +{ + namespace mysql + { + template <> + struct default_value_traits<QUuid, id_blob> + { + typedef QUuid value_type; + typedef value_type query_type; + typedef details::buffer image_type; + + static void + set_value (value_type& v, + const details::buffer& b, + std::size_t n, + bool is_null) + { + if (!is_null) + { + assert (n == 16); + std::memcpy (&v.data1, b.data (), 16); + } + else + v = QUuid (); + } + + static void + set_image (details::buffer& b, + std::size_t& n, + bool& is_null, + const value_type& v) + { + // If we can, store nil as NULL. Otherwise, store it as a value. + // + is_null = is_null && v.isNull (); + + if (!is_null) + { + n = 16; + + if (n > b.capacity ()) + b.capacity (n); + + std::memcpy (b.data (), &v.data1, n); + } + } + }; + + template <> + struct default_type_traits<QUuid> + { + static const database_type_id db_type_id = id_blob; + }; + } +} + +#include <odb/post.hxx> + +#endif // ODB_QT_BASIC_MYSQL_UUID_TRAITS_HXX diff --git a/odb/qt/basic/oracle/default-mapping.hxx b/odb/qt/basic/oracle/default-mapping.hxx index d2097ca..40f7815 100644 --- a/odb/qt/basic/oracle/default-mapping.hxx +++ b/odb/qt/basic/oracle/default-mapping.hxx @@ -7,6 +7,7 @@ #include <QtCore/QString> #include <QtCore/QByteArray> +#include <QtCore/QUuid> // Map QString to Oracle VARCHAR2 by default. Allow NULL values by default as // QString provides a null representation. @@ -18,4 +19,10 @@ // #pragma db value(QByteArray) type("BLOB") null +// By default map QUuid to Oracle RAW(16) and use NULL to represent null +// UUIDs. If NULL is disabled (e.g., at the member level), then we store +// the null UUID (i.e., all bytes are zero). +// +#pragma db value(QUuid) type("RAW(16)") null + #endif // ODB_QT_BASIC_ORACLE_DEFAULT_MAPPING_HXX diff --git a/odb/qt/basic/oracle/quuid-traits.hxx b/odb/qt/basic/oracle/quuid-traits.hxx new file mode 100644 index 0000000..11342fa --- /dev/null +++ b/odb/qt/basic/oracle/quuid-traits.hxx @@ -0,0 +1,71 @@ +// file : odb/qt/basic/oracle/uuid-traits.hxx +// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_QT_BASIC_ORACLE_UUID_TRAITS_HXX +#define ODB_QT_BASIC_ORACLE_UUID_TRAITS_HXX + +#include <odb/pre.hxx> + +#include <cstring> // std::memcpy +#include <cassert> + +#include <QtCore/QUuid> + +#include <odb/oracle/traits.hxx> + +namespace odb +{ + namespace oracle + { + template <> + struct default_value_traits<QUuid, id_raw> + { + public: + typedef QUuid value_type; + typedef value_type query_type; + typedef char* image_type; + + static void + set_value (value_type& v, const char* b, std::size_t n, bool is_null) + { + if (!is_null) + { + assert (n == 16); + std::memcpy (&v.data1, b, 16); + } + else + v = QUuid (); + } + + static void + set_image (char* b, + std::size_t c, + std::size_t& n, + bool& is_null, + const value_type& v) + { + // If we can, store nil as NULL. Otherwise, store it as a value. + // + is_null = is_null && v.isNull (); + + if (!is_null) + { + n = 16; + assert (c >= n); + std::memcpy (b, &v.data1, n); + } + } + }; + + template <> + struct default_type_traits<QUuid> + { + static const database_type_id db_type_id = id_raw; + }; + } +} + +#include <odb/post.hxx> + +#endif // ODB_QT_BASIC_ORACLE_UUID_TRAITS_HXX diff --git a/odb/qt/basic/pgsql/default-mapping.hxx b/odb/qt/basic/pgsql/default-mapping.hxx index 6633fc5..5f3c2c1 100644 --- a/odb/qt/basic/pgsql/default-mapping.hxx +++ b/odb/qt/basic/pgsql/default-mapping.hxx @@ -7,6 +7,7 @@ #include <QtCore/QString> #include <QtCore/QByteArray> +#include <QtCore/QUuid> // Map QString to PostgreSQL TEXT by default. Allow NULL values by default as // QString provides a null representation. @@ -18,4 +19,10 @@ // #pragma db value(QByteArray) type("BYTEA") null +// By default map QUuid to PostgreSQL UUID and use NULL to represent null +// UUIDs. If NULL is disabled (e.g., at the member level), then we store +// the null UUID (i.e., all bytes are zero). +// +#pragma db value(QUuid) type("UUID") null + #endif // ODB_QT_BASIC_PGSQL_DEFAULT_MAPPING_HXX diff --git a/odb/qt/basic/pgsql/quuid-traits.hxx b/odb/qt/basic/pgsql/quuid-traits.hxx new file mode 100644 index 0000000..c4439a7 --- /dev/null +++ b/odb/qt/basic/pgsql/quuid-traits.hxx @@ -0,0 +1,59 @@ +// file : odb/qt/basic/pgsql/uuid-traits.hxx +// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_QT_BASIC_PGSQL_UUID_TRAITS_HXX +#define ODB_QT_BASIC_PGSQL_UUID_TRAITS_HXX + +#include <odb/pre.hxx> + +#include <cstring> // std::memcpy + +#include <QtCore/QUuid> + +#include <odb/pgsql/traits.hxx> + +namespace odb +{ + namespace pgsql + { + template <> + class default_value_traits<QUuid, id_uuid> + { + public: + typedef QUuid value_type; + typedef value_type query_type; + typedef unsigned char* image_type; + + static void + set_value (value_type& v, const unsigned char* i, bool is_null) + { + if (!is_null) + std::memcpy (&v.data1, i, 16); + else + v = QUuid (); + } + + static void + set_image (unsigned char* i, bool& is_null, const value_type& v) + { + // If we can, store nil as NULL. Otherwise, store it as a value. + // + is_null = is_null && v.isNull (); + + if (!is_null) + std::memcpy (i, &v.data1, 16); + } + }; + + template <> + struct default_type_traits<QUuid> + { + static const database_type_id db_type_id = id_uuid; + }; + } +} + +#include <odb/post.hxx> + +#endif // ODB_QT_BASIC_PGSQL_UUID_TRAITS_HXX diff --git a/odb/qt/basic/sqlite/default-mapping.hxx b/odb/qt/basic/sqlite/default-mapping.hxx index 1b5296d..bdb19b3 100644 --- a/odb/qt/basic/sqlite/default-mapping.hxx +++ b/odb/qt/basic/sqlite/default-mapping.hxx @@ -7,6 +7,7 @@ #include <QtCore/QString> #include <QtCore/QByteArray> +#include <QtCore/QUuid> // Map QString to SQLite TEXT by default. Allow NULL values by default as // QString provides a null representation. @@ -18,4 +19,10 @@ // #pragma db value(QByteArray) type("BLOB") null +// By default map QUuid to SQLite BLOB and use NULL to represent null UUIDs. +// If NULL is disabled (e.g., at the member level), then we store the null +// UUID (i.e., all bytes are zero). +// +#pragma db value(QUuid) type("BLOB") null + #endif // ODB_QT_BASIC_SQLITE_DEFAULT_MAPPING_HXX diff --git a/odb/qt/basic/sqlite/quuid-traits.hxx b/odb/qt/basic/sqlite/quuid-traits.hxx new file mode 100644 index 0000000..c99a417 --- /dev/null +++ b/odb/qt/basic/sqlite/quuid-traits.hxx @@ -0,0 +1,75 @@ +// file : odb/qt/basic/sqlite/uuid-traits.hxx +// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_QT_BASIC_SQLITE_UUID_TRAITS_HXX +#define ODB_QT_BASIC_SQLITE_UUID_TRAITS_HXX + +#include <odb/pre.hxx> + +#include <cstring> // std::memcpy +#include <cassert> + +#include <QtCore/QUuid> + +#include <odb/sqlite/traits.hxx> + +namespace odb +{ + namespace sqlite + { + template <> + struct default_value_traits<QUuid, id_blob> + { + typedef QUuid value_type; + typedef value_type query_type; + typedef details::buffer image_type; + + static void + set_value (value_type& v, + const details::buffer& b, + std::size_t n, + bool is_null) + { + if (!is_null) + { + assert (n == 16); + std::memcpy (&v.data1, b.data (), 16); + } + else + v = QUuid (); + } + + static void + set_image (details::buffer& b, + std::size_t& n, + bool& is_null, + const value_type& v) + { + // If we can, store nil as NULL. Otherwise, store it as a value. + // + is_null = is_null && v.isNull (); + + if (!is_null) + { + n = 16; + + if (n > b.capacity ()) + b.capacity (n); + + std::memcpy (b.data (), &v.data1, n); + } + } + }; + + template <> + struct default_type_traits<QUuid> + { + static const database_type_id db_type_id = id_blob; + }; + } +} + +#include <odb/post.hxx> + +#endif // ODB_QT_BASIC_SQLITE_UUID_TRAITS_HXX |