diff options
Diffstat (limited to 'odb-tests/mssql')
25 files changed, 3983 insertions, 0 deletions
diff --git a/odb-tests/mssql/custom/custom.sql b/odb-tests/mssql/custom/custom.sql new file mode 100644 index 0000000..44ef512 --- /dev/null +++ b/odb-tests/mssql/custom/custom.sql @@ -0,0 +1,42 @@ +/* This file contains helper functions. + */ + +IF OBJECT_ID('dbo.variant_to_string', 'FN') IS NOT NULL + DROP FUNCTION dbo.variant_to_string; +GO + +IF OBJECT_ID('dbo.string_to_variant', 'FN') IS NOT NULL + DROP FUNCTION dbo.string_to_variant; +GO + +CREATE FUNCTION dbo.variant_to_string (@val SQL_VARIANT) RETURNS VARCHAR(max) +AS +BEGIN + RETURN CAST(SQL_VARIANT_PROPERTY(@val, 'BaseType') AS SYSNAME) + ' ' + + CAST(@val AS VARCHAR(max)) +END; +GO + +CREATE FUNCTION dbo.string_to_variant (@val VARCHAR(max)) RETURNS SQL_VARIANT +AS +BEGIN + DECLARE @ret SQL_VARIANT + + DECLARE @pos BIGINT + DECLARE @vtype SYSNAME + DECLARE @vtext VARCHAR(max) + + SET @pos = CHARINDEX(' ', @val) + SET @vtype = SUBSTRING(@val, 1, @pos - 1) + SET @vtext = SUBSTRING(@val, @pos + 1, LEN(@val)) + + IF @vtype = 'tinyint' SET @ret = CAST(@vtext AS TINYINT) + ELSE IF @vtype = 'smallint' SET @ret = CAST(@vtext AS SMALLINT) + ELSE IF @vtype = 'int' SET @ret = CAST(@vtext AS INT) + ELSE IF @vtype = 'bigint' SET @ret = CAST(@vtext AS BIGINT) + ELSE IF @vtype = 'char' SET @ret = CAST(@vtext AS CHAR(8000)) + ELSE IF @vtype = 'varchar' SET @ret = CAST(@vtext AS VARCHAR(8000)) + + RETURN @ret +END; +GO diff --git a/odb-tests/mssql/custom/driver.cxx b/odb-tests/mssql/custom/driver.cxx new file mode 100644 index 0000000..bde7eb6 --- /dev/null +++ b/odb-tests/mssql/custom/driver.cxx @@ -0,0 +1,135 @@ +// file : mssql/custom/driver.cxx +// license : GNU GPL v2; see accompanying LICENSE file + +// Test custom database type mapping in SQL Server. +// + +#include <memory> // std::auto_ptr +#include <cassert> +#include <iostream> + +#include <odb/mssql/database.hxx> +#include <odb/mssql/transaction.hxx> + +#include <common/common.hxx> + +#include "test.hxx" +#include "test-odb.hxx" + +using namespace std; +namespace mssql = odb::mssql; +using namespace mssql; + +int +main (int argc, char* argv[]) +{ + try + { + auto_ptr<database> db (create_specific_database<database> (argc, argv)); + + object o (1); + + o.v = variant (123); + o.vv.push_back (variant (string (1024, 'a'))); + o.vv.push_back (variant (123)); + +#if !defined(MSSQL_SERVER_VERSION) || MSSQL_SERVER_VERSION >= 1000 + o.p = point (1.1111, 2222222222.2); + o.pv.push_back (point (1.1234, 2.2345)); + o.pv.push_back (point (3.3456, 4.4567)); + o.pv.push_back (point (0.0000001, 0.000000001)); // Scientific notation. +#endif + + o.xml = "<root x=\"1\"><a>AAA</a><b>BBB</b><c>CCC</c></root>"; + + // Persist. + // + { + transaction t (db->begin ()); + db->persist (o); + t.commit (); + } + + // Load. + // + { + transaction t (db->begin ()); + auto_ptr<object> o1 (db->load<object> (1)); + t.commit (); + + assert (o == *o1); + } + + // Query. + // + typedef mssql::query<object> query; + typedef odb::result<object> result; + + { + transaction t (db->begin ()); + + // Variant comparison. + // + { + result r (db->query<object> (query::v == o.v)); + assert (!r.empty ()); + } + +#if !defined(MSSQL_SERVER_VERSION) || MSSQL_SERVER_VERSION >= 1000 + // Point comparison. + // + { + result r (db->query<object> (query::p == o.p)); + assert (!r.empty ()); + } + + // Point comparison using native query. + // + { + result r (db->query<object> ( + query::p + ".STEquals(" + query::_val (o.p) + ") = 1")); + assert (!r.empty ()); + } + + // Access to individual members. + // + { + result r (db->query<object> (query::p.x == o.p.x)); + assert (!r.empty ()); + } +#endif + + t.commit (); + } + + // Update. + // +#if !defined(MSSQL_SERVER_VERSION) || MSSQL_SERVER_VERSION >= 1000 + o.p.x++; + o.p.y--; + o.pv[1].x--; + o.pv[1].y++; +#endif + + o.xml = "<root x=\"2\"><a>BBB</a><b>CCC</b><c>DDD</c></root>"; + + { + transaction t (db->begin ()); + db->update (o); + t.commit (); + } + + { + transaction t (db->begin ()); + auto_ptr<object> o1 (db->load<object> (1)); + t.commit (); + + assert (o == *o1); + } + } + catch (const odb::exception& e) + { + cerr << e.what () << endl; + return 1; + } +} diff --git a/odb-tests/mssql/custom/query.hxx b/odb-tests/mssql/custom/query.hxx new file mode 100644 index 0000000..fc63378 --- /dev/null +++ b/odb-tests/mssql/custom/query.hxx @@ -0,0 +1,183 @@ +// file : mssql/custom/query.hxx +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef QUERY_HXX +#define QUERY_HXX + +#include <string> + +#include <odb/mssql/query.hxx> + +#include "test.hxx" // point + +namespace odb +{ + namespace mssql + { +#if !defined(MSSQL_SERVER_VERSION) || MSSQL_SERVER_VERSION >= 1000 + template <> + struct query_column<point, id_string> + { + private: + const char* table_; + const char* column_; + const char* conversion_; + + unsigned short prec_; + unsigned short scale_; + + std::string x_column_; + std::string y_column_; + + // Sub-columns for individual members. + // + public: + query_column<double, id_float8> x, y; + + // is_null, is_not_null + // + public: + query_base + is_null () const + { + query_base q (table_, column_); + q += "IS NULL"; + return q; + } + + query_base + is_not_null () const + { + query_base q (table_, column_); + q += "IS NOT NULL"; + return q; + } + + // = + // + public: + query_base + equal (const point& v) const + { + return equal (val_bind<point> (v)); + } + + query_base + equal (val_bind<point> v) const + { + query_base q (table_, column_); + q += ".STEquals("; + q.append<point, id_string> (v, conversion_); + q += ") = 1"; + return q; + } + + query_base + equal (ref_bind<point> r) const + { + query_base q (table_, column_); + q += ".STEquals("; + q.append<point, id_string> (r, conversion_); + q += ") = 1"; + return q; + } + + friend query_base + operator== (const query_column& c, const point& v) + { + return c.equal (v); + } + + friend query_base + operator== (const point& v, const query_column& c) + { + return c.equal (v); + } + + friend query_base + operator== (const query_column& c, val_bind<point> v) + { + return c.equal (v); + } + + friend query_base + operator== (val_bind<point> v, const query_column& c) + { + return c.equal (v); + } + + friend query_base + operator== (const query_column& c, ref_bind<point> r) + { + return c.equal (r); + } + + friend query_base + operator== (ref_bind<point> r, const query_column& c) + { + return c.equal (r); + } + + // Column comparison. + // + public: + query_base + operator== (const query_column<point, id_string>& c) const + { + query_base q (table_, column_); + q += ".STEquals("; + q.append (c.table (), c.column ()); + q += ") = 1"; + return q; + } + + public: + query_column (const char* table, + const char* column, + const char* conv, + unsigned short prec = 0, + unsigned short scale = 0xFFFF) + : table_ (table), column_ (column), conversion_ (conv), + prec_ (prec), scale_ (scale), + x_column_ (std::string (column) + ".STX"), + y_column_ (std::string (column) + ".STY"), + x (table, x_column_.c_str (), 0), + y (table, y_column_.c_str (), 0) + { + } + + const char* + table () const + { + return table_; + } + + const char* + column () const + { + return column_; + } + + const char* + conversion () const + { + return conversion_; + } + + unsigned short + prec () const + { + return prec_; + } + + unsigned short + scale () const + { + return scale_; + } + }; +#endif // SQL Server > 2005 + } +} + +#endif // QUERY_HXX diff --git a/odb-tests/mssql/custom/test.hxx b/odb-tests/mssql/custom/test.hxx new file mode 100644 index 0000000..4b8a5d7 --- /dev/null +++ b/odb-tests/mssql/custom/test.hxx @@ -0,0 +1,121 @@ +// file : mssql/types/test.hxx +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef TEST_HXX +#define TEST_HXX + +#include <string> +#include <vector> + +#include <odb/core.hxx> + +// Map SQL Server SQL_VARIANT type to our variant C++ class that is capable +// of storing either an integer or a string (QVariant and boost::variant +// would be natural alternatives to our own type). The SQL Server functions +// that are used in the 'to' and 'from' expressions below are defined in +// the custom.sql file. The other half of this mapping is in traits.hxx +// (value_traits<variant, id_long_string>). +// +#pragma db map type("SQL_VARIANT") \ + as("VARCHAR(max)") \ + to("dbo.string_to_variant((?))") \ + from("dbo.variant_to_string((?))") + +#pragma db value type("SQL_VARIANT") +struct variant +{ + variant (unsigned long v = 0): val_type (type_int), int_val (v) {} + variant (const std::string& v): val_type (type_str), str_val (v) {} + + enum {type_int, type_str} val_type; + unsigned long int_val; + std::string str_val; +}; + +inline bool +operator== (const variant& a, const variant& b) +{ + if (a.val_type != b.val_type) + return false; + + switch (a.val_type) + { + case variant::type_int: + return a.int_val == b.int_val; + case variant::type_str: + return a.str_val == b.str_val; + } + + return false; +} + +#if !defined(MSSQL_SERVER_VERSION) || MSSQL_SERVER_VERSION >= 1000 +// Map GEOMETRY SQL Server type to the point C++ struct. The other half +// of this mapping is in traits.hxx (value_traits<point, id_string>). +// Note that GEOMETRY is not available in SQL Server 2005. +// +#pragma db map type("GEOMETRY") \ + as("VARCHAR(256)") \ + to("GEOMETRY::STGeomFromText((?), 0)") \ + from("(?).STAsText()") + +#pragma db value type("GEOMETRY") +struct point +{ + point () {} + point (double x_, double y_): x (x_), y (y_) {} + + double x; + double y; +}; + +inline bool +operator== (const point& a, const point& b) +{ + return a.x == b.x && a.y == b.y; +} +#endif // SQL Server > 2005 + +// Map XML SQL Server type to std::string (or any other type that provides +// the value_traits<?, id_long_string> specialization). Note also that +// another alternative would be to interface with the XML data type using +// VARBINARY or NVARCHAR. Here we use implicit string to/from XML conversion, +// however, CAST/CONVERT can be used instead for greater control over +// whitespace handling, etc. +// +#pragma db map type("XML *(\\(.+\\))?") as("VARCHAR(max)") + +#pragma db object +struct object +{ + object () {} + object (unsigned long id_) : id (id_) {} + + #pragma db id + unsigned long id; + + variant v; + std::vector<variant> vv; + +#if !defined(MSSQL_SERVER_VERSION) || MSSQL_SERVER_VERSION >= 1000 + point p; + std::vector<point> pv; +#endif + + #pragma db type("XML") + std::string xml; + + bool + operator== (const object& y) const + { + return id == y.id + && vv == y.vv +#if !defined(MSSQL_SERVER_VERSION) || MSSQL_SERVER_VERSION >= 1000 + && p == y.p + && pv == y.pv +#endif + && xml == y.xml; + } +}; + +#endif // TEST_HXX diff --git a/odb-tests/mssql/custom/traits.cxx b/odb-tests/mssql/custom/traits.cxx new file mode 100644 index 0000000..3f14ae7 --- /dev/null +++ b/odb-tests/mssql/custom/traits.cxx @@ -0,0 +1,128 @@ +// file : mssql/types/traits.cxx +// license : GNU GPL v2; see accompanying LICENSE file + +#include "traits.hxx" + +using namespace std; + +namespace odb +{ + namespace mssql + { + void value_traits<variant, id_long_string>:: + param_callback (const void* context, + size_t*, + const void** buffer, + size_t* size, + chunk_type* chunk, + void* tmp_buf, + size_t tmp_capacity) + { + const variant& v (*static_cast<const variant*> (context)); + string str; + + switch (v.val_type) + { + case variant::type_int: + { + ostringstream os; + os << v.int_val; + + str = "bigint "; + str += os.str (); + break; + } + case variant::type_str: + { + str = "varchar "; + str += v.str_val; + break; + } + } + + // Here we assume that the temoprary buffer is large enough to fit + // the whole string in one go. If that were not the case, then we + // would have had to chunk it. + // + assert (tmp_capacity >= str.size ()); + memcpy (tmp_buf, str.c_str (), str.size ()); + + *buffer = tmp_buf; + *size = str.size (); + *chunk = chunk_one; + } + + void value_traits<variant, id_long_string>:: + result_callback (void* context, + size_t*, + void** buffer, + size_t* size, + chunk_type chunk, + size_t, + void* tmp_buf, + size_t tmp_capacity) + { + variant& v (*static_cast<variant*> (context)); + + switch (chunk) + { + case chunk_null: + case chunk_one: + { + assert (false); // The value cannot be NULL or empty. + break; + } + case chunk_first: + { + // Use the variant's string value as a temporary buffer. If this + // were not possible, we could have allocated one as part of + // context. + // + v.str_val.clear (); + + *buffer = tmp_buf; + *size = tmp_capacity; + break; + } + case chunk_next: + { + v.str_val.append (static_cast<char*> (tmp_buf), *size); + + *buffer = tmp_buf; + *size = tmp_capacity; + break; + } + case chunk_last: + { + v.str_val.append (static_cast<char*> (tmp_buf), *size); + + // Figure out what we've got. + // + string::size_type p (v.str_val.find (' ')); + assert (p != string::npos); // Must have type followed by value. + string type (v.str_val, 0, p); + string text (v.str_val, p + 1, string::npos); + + if (type == "tinyint" || + type == "smallint" || + type == "int" || + type == "bigint") + { + istringstream is (text); + is >> v.int_val; + v.val_type = variant::type_int; + } + else if (type == "char" || type == "varchar") + { + v.str_val = text; + v.val_type = variant::type_str; + } + else + assert (false); // Unknown type. + + break; + } + } + } + } +} diff --git a/odb-tests/mssql/custom/traits.hxx b/odb-tests/mssql/custom/traits.hxx new file mode 100644 index 0000000..2bd99cb --- /dev/null +++ b/odb-tests/mssql/custom/traits.hxx @@ -0,0 +1,148 @@ +// file : mssql/types/traits.hxx +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef TRAITS_HXX +#define TRAITS_HXX + +#include <limits> // std::numeric_limits +#include <sstream> +#include <cstring> // std::memcpy +#include <cassert> + +#include <odb/mssql/traits.hxx> + +#include "test.hxx" // variant, point + +namespace odb +{ + namespace mssql + { + template <> + class value_traits<variant, id_long_string> + { + public: + typedef variant value_type; + typedef variant query_type; + typedef long_callback image_type; + + static void + set_value (variant& v, + result_callback_type& cb, + void*& context) + { + cb = &result_callback; + context = &v; + } + + static void + set_image (param_callback_type& cb, + const void*& context, + bool& is_null, + const variant& v) + { + is_null = false; + cb = ¶m_callback; + context = &v; + } + + static void + param_callback (const void* context, + std::size_t* position, + const void** buffer, + std::size_t* size, + chunk_type* chunk, + void* tmp_buffer, + std::size_t tmp_capacity); + + static void + result_callback (void* context, + std::size_t* position, + void** buffer, + std::size_t* size, + chunk_type chunk, + std::size_t size_left, + void* tmp_buffer, + std::size_t tmp_capacity); + }; + + template <> + struct type_traits<variant> + { + static const database_type_id db_type_id = id_long_string; + + struct conversion + { + static const char* to () {return "dbo.string_to_variant((?))";} + }; + }; + +#if !defined(MSSQL_SERVER_VERSION) || MSSQL_SERVER_VERSION >= 1000 + template <> + class value_traits<point, id_string> + { + public: + typedef point value_type; + typedef point query_type; + + typedef char* image_type; + + static void + set_value (point& v, + const char* b, + std::size_t n, + bool is_null) + { + if (is_null) + v = point (); + else + { + // Point format is "POINT (x y)". + // + std::istringstream is (std::string (b + 7, n - 7)); + + is >> v.x; + is >> v.y; + } + } + + static void + set_image (char* b, + std::size_t c, + std::size_t& n, + bool& is_null, + const point& v) + { + is_null = false; + std::ostringstream os; + + // The formula for the number of decimla digits required is given in: + // + // http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2005/n1822.pdf + // + os.precision (std::numeric_limits<double>::digits10); + // os.precision (2 + std::numeric_limits<double>::digits * 301/1000); + + os << "POINT (" << v.x << ' ' << v.y << ')'; + + const std::string& s (os.str ()); + n = s.size (); + assert (n <= c); + std::memcpy (b, s.c_str (), n); + } + }; + + template <> + struct type_traits<point> + { + static const database_type_id db_type_id = id_string; + + struct conversion + { + static const char* to () {return "GEOMETRY::STGeomFromText((?), 0)";} + }; + }; +#endif // SQL Server > 2005 + } +} + +#endif // TRAITS_HXX diff --git a/odb-tests/mssql/database/driver.cxx b/odb-tests/mssql/database/driver.cxx new file mode 100644 index 0000000..08ad34f --- /dev/null +++ b/odb-tests/mssql/database/driver.cxx @@ -0,0 +1,105 @@ +// file : mssql/database/driver.cxx +// license : GNU GPL; see accompanying LICENSE file + +// Test that database constructors are unambiguous (compilation only). +// + +#include <string> +#include <cassert> + +#include <odb/mssql/database.hxx> + +namespace mssql = odb::mssql; +using namespace mssql; + +static const char* isolation_map[] = {"1", "2", "3", "5", "4"}; + +static bool +check_isolation (connection& c, transaction_isolation i) +{ + std::string s ("SELECT 1 FROM sys.dm_exec_sessions WHERE session_id = @@SPID" + " AND transaction_isolation_level = "); + s += isolation_map[i]; + return c.execute (s) == 1; +} + +int +main (int argc, char* argv[]) +{ + // This code should not execute. + // + if (argc == 0) + { + { + database d1 ("bob", "secret", "db1", "server1"); + database d2 ("bob", "secret", "db1", "server1", "driver1"); + database d3 ("bob", "secret", "db1", "server1", "driver1", "extra"); + database d4 ("bob", "secret", "db1", "server1", "driver1", "extra", + isolation_read_uncommitted); + } + + { + database d1 ("bob", "secret", "db1", protocol_auto); + database d2 ("bob", "secret", "db1", protocol_auto, "server1"); + database d3 ("bob", "secret", "db1", protocol_auto, "server1", "inst1"); + database d4 ("bob", "secret", "db1", protocol_auto, "server1", "inst1", + "driver1"); + database d5 ("bob", "secret", "db1", protocol_auto, "server1", "inst1", + "driver1", "extra"); + database d6 ("bob", "secret", "db1", protocol_auto, "server1", "inst1", + "driver1", "extra", isolation_read_uncommitted); + } + + { + database d1 ("bob", "secret", "db1", "server1", 0); + database d2 ("bob", "secret", "db1", "server1", 999, "driver1"); + database d3 ("bob", "secret", "db1", "server1", 999, "driver1", "extra"); + database d4 ("bob", "secret", "db1", "server1", 999, "driver1", "extra", + isolation_read_uncommitted); + } + + { + database d1 ("conn1"); + database d2 ("conn1", isolation_read_uncommitted); + } + + { + database d1 (argc, argv); + database d2 (argc, argv, false); + database d3 (argc, argv, true, "extra"); + database d4 (argc, argv, false, "extra", isolation_read_uncommitted); + } + } + + // Test transaction isolation levels. + // + { + database d (argc, argv, false, "", isolation_read_uncommitted); + connection_ptr c (d.connection ()); + assert (check_isolation (*c, isolation_read_uncommitted)); + } + + { + database d (argc, argv, false, ""); + connection_ptr c (d.connection ()); + assert (check_isolation (*c, isolation_read_committed)); + } + + { + database d (argc, argv, false, "", isolation_repeatable_read); + connection_ptr c (d.connection ()); + assert (check_isolation (*c, isolation_repeatable_read)); + } + + { + database d (argc, argv, false, "", isolation_snapshot); + connection_ptr c (d.connection ()); + assert (check_isolation (*c, isolation_snapshot)); + } + + { + database d (argc, argv, false, "", isolation_serializable); + connection_ptr c (d.connection ()); + assert (check_isolation (*c, isolation_serializable)); + } +} diff --git a/odb-tests/mssql/native/driver.cxx b/odb-tests/mssql/native/driver.cxx new file mode 100644 index 0000000..f4b4fd7 --- /dev/null +++ b/odb-tests/mssql/native/driver.cxx @@ -0,0 +1,73 @@ +// file : mssql/native/driver.cxx +// license : GNU GPL; see accompanying LICENSE file + +// Test native SQL execution. +// + +#include <memory> // std::auto_ptr +#include <cassert> +#include <iostream> + +#include <odb/mssql/database.hxx> +#include <odb/mssql/transaction.hxx> + +#include <common/common.hxx> + +using namespace std; +namespace mssql = odb::mssql; +using namespace mssql; + +int +main (int argc, char* argv[]) +{ + try + { + auto_ptr<database> db (create_specific_database<database> (argc, argv)); + + // Create the database schema. + // + { + transaction t (db->begin ()); + + db->execute ("IF OBJECT_ID('mssql_native_test', 'U') IS NOT NULL\n" + " DROP TABLE mssql_native_test"); + + db->execute ("CREATE TABLE mssql_native_test (n int)"); + + t.commit (); + } + + // Insert a few rows. + // + { + transaction t (db->begin ()); + + assert ( + db->execute ("INSERT INTO mssql_native_test (n) VALUES (1)") == 1); + + assert ( + db->execute ("INSERT INTO mssql_native_test (n) VALUES (2)") == 1); + + t.commit (); + } + + // Select a few rows. + // + { + transaction t (db->begin ()); + + assert ( + db->execute ("SELECT n FROM mssql_native_test WHERE n < 3") == 2); + + assert ( + db->execute ("SELECT n FROM mssql_native_test WHERE n > 3") == 0); + + t.commit (); + } + } + catch (const odb::exception& e) + { + cerr << e.what () << endl; + return 1; + } +} diff --git a/odb-tests/mssql/query/driver.cxx b/odb-tests/mssql/query/driver.cxx new file mode 100644 index 0000000..5600c81 --- /dev/null +++ b/odb-tests/mssql/query/driver.cxx @@ -0,0 +1,188 @@ +// file : mssql/query/driver.cxx +// license : GNU GPL v2; see accompanying LICENSE file + +// Test SQL Server-specific query support aspects. +// + +#include <memory> // std::auto_ptr +#include <cassert> +#include <iostream> + +#include <odb/mssql/database.hxx> +#include <odb/mssql/transaction.hxx> + +#include <common/common.hxx> + +#include "test.hxx" +#include "test-odb.hxx" + +using namespace std; +namespace mssql = odb::mssql; +using namespace mssql; + +int +main (int argc, char* argv[]) +{ + try + { + auto_ptr<database> db (create_specific_database<database> (argc, argv)); + + { + object o1; + object o2; + object o3; + + o1.num = 1; + o1.str = "aaa"; + o1.nstr = L"aaa"; + o1.lstr.assign (1024, 'a'); + o1.lnstr.assign (1024, L'a'); + o1.smoney = 11000; + o1.money = 1.1; + + o2.num = 2; + o2.str = "bbb"; + o2.nstr = L"bbb"; + o2.lstr.assign (1024, 'b'); + o2.lnstr.assign (1024, L'b'); + o2.smoney = 22000; + o2.money = 2.2; + + o3.num = 3; + o3.str = "ccc"; + o3.nstr = L"ccc"; + o3.lstr.assign (1024, 'c'); + o3.lnstr.assign (1024, L'c'); + o3.smoney = 33000; + o3.money = 3.3; + + transaction t (db->begin ()); + db->persist (o1); + db->persist (o2); + db->persist (o3); + t.commit (); + } + + typedef mssql::query<object> query; + typedef odb::result<object> result; + + { + transaction t (db->begin ()); + + // Money and small money. + // + { + result r (db->query<object> (query::smoney < 22000)); + result::iterator i (r.begin ()); + assert (i != r.end ()); + assert (i->smoney == 11000); + assert (++i == r.end ()); + } + + { + result r (db->query<object> ("smoney < " + query::_val (2.1F))); + result::iterator i (r.begin ()); + assert (i != r.end ()); + assert (i->smoney == 11000); + assert (++i == r.end ()); + } + + { + result r (db->query<object> (query::money < 2.2)); + result::iterator i (r.begin ()); + assert (i != r.end ()); + assert (i->money == 1.1); + assert (++i == r.end ()); + } + + { + result r (db->query<object> ("money < " + query::_val (2.2))); + result::iterator i (r.begin ()); + assert (i != r.end ()); + assert (i->money == 1.1); + assert (++i == r.end ()); + } + + // Short/long string. + // + { + result r (db->query<object> (query::str < "bbb")); + result::iterator i (r.begin ()); + assert (i != r.end ()); + assert (i->str == "aaa"); + assert (++i == r.end ()); + } + + { + result r (db->query<object> ("str < " + query::_val ("bbb", 3))); + result::iterator i (r.begin ()); + assert (i != r.end ()); + assert (i->str == "aaa"); + assert (++i == r.end ()); + } + + { + result r (db->query<object> (query::nstr < L"bbb")); + result::iterator i (r.begin ()); + assert (i != r.end ()); + assert (i->nstr == L"aaa"); + assert (++i == r.end ()); + } + + { + result r (db->query<object> (query::lstr < string (1024, 'b'))); + result::iterator i (r.begin ()); + assert (i != r.end ()); + assert (i->lstr == string (1024, 'a')); + assert (++i == r.end ()); + } + + { + string v (1024, 'b'); + result r (db->query<object> (query::lstr < query::_ref (v))); + result::iterator i (r.begin ()); + assert (i != r.end ()); + assert (i->lstr == string (1024, 'a')); + assert (++i == r.end ()); + } + + { + result r (db->query<object> (query::lnstr < wstring (1024, L'b'))); + result::iterator i (r.begin ()); + assert (i != r.end ()); + assert (i->lnstr == wstring (1024, L'a')); + assert (++i == r.end ()); + } + + // Test image copying with long data. + // + { + result r (db->query<object> (query::str < "ccc")); + result::iterator i (r.begin ()); + + assert (i != r.end ()); + ++i; + assert (i != r.end ()); + + { + result r (db->query<object> (query::str < "bbb")); + result::iterator i (r.begin ()); + assert (i != r.end ()); + assert (i->str == "aaa"); + assert (++i == r.end ()); + } + + assert (i->str == "bbb"); // Load from copy. + assert (++i == r.end ()); + } + + t.commit (); + } + + } + catch (const odb::exception& e) + { + cerr << e.what () << endl; + return 1; + } +} diff --git a/odb-tests/mssql/query/test.hxx b/odb-tests/mssql/query/test.hxx new file mode 100644 index 0000000..85c644e --- /dev/null +++ b/odb-tests/mssql/query/test.hxx @@ -0,0 +1,38 @@ +// file : mssql/query/test.hxx +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef TEST_HXX +#define TEST_HXX + +#include <string> + +#include <odb/core.hxx> + +#pragma db object +struct object +{ + #pragma db id auto + unsigned long id_; + + unsigned int num; + + #pragma db type ("SMALLMONEY") + int smoney; + + #pragma db type ("MONEY") + double money; + + #pragma db type ("VARCHAR(256)") + std::string str; + + #pragma db type ("NVARCHAR(128)") + std::wstring nstr; + + #pragma db type ("VARCHAR(max)") + std::string lstr; + + #pragma db type ("NVARCHAR(max)") + std::wstring lnstr; +}; + +#endif // TEST_HXX diff --git a/odb-tests/mssql/stored-proc/driver.cxx b/odb-tests/mssql/stored-proc/driver.cxx new file mode 100644 index 0000000..2389798 --- /dev/null +++ b/odb-tests/mssql/stored-proc/driver.cxx @@ -0,0 +1,231 @@ +// file : mssql/stored-proc/driver.cxx +// license : GNU GPL v2; see accompanying LICENSE file + +// Test SQL Server stored procedure support. +// + +#include <memory> // std::auto_ptr +#include <cassert> +#include <iostream> + +#include <odb/mssql/database.hxx> +#include <odb/mssql/transaction.hxx> + +#include <common/common.hxx> + +#include "test.hxx" +#include "test-odb.hxx" + +using namespace std; +namespace mssql = odb::mssql; +using namespace mssql; + +void +create_procedure (database& db, const string& name, const string& body) +{ + transaction t (db.begin ()); + + string s (db.query_value<default_schema> ().name); + + db.execute ( + "IF EXISTS (" + " SELECT * FROM sysobjects" + " WHERE name = '" + name + "' AND user_name(uid) = '" + s +"')" + " DROP PROCEDURE [" + s + "].[" + name + "]"); + + db.execute ("CREATE PROCEDURE [" + s + "].[" + name + "] " + body); + + t.commit (); +} + +int +main (int argc, char* argv[]) +{ + try + { + auto_ptr<database> db (create_specific_database<database> (argc, argv)); + + object o1 (1, "a"); + object o2 (2, "b"); + object o3 (3, "c"); + + { + transaction t (db->begin ()); + db->persist (o1); + db->persist (o2); + db->persist (o3); + t.commit (); + } + + { + create_procedure ( + *db, "select_all_objects", + "AS" + " SELECT num, str FROM mssql_stored_proc_object ORDER BY id;"); + + typedef odb::result<select_all_objects> result; + + transaction t (db->begin ()); + + result r (db->query<select_all_objects> ()); + + for (result::iterator i (r.begin ()); i != r.end (); ++i) + cout << i->num << " " << i->str << endl; + cout << endl; + + t.commit (); + } + + { + create_procedure ( + *db, "select_objects", + "(@id INT, @n VARCHAR(512))" + "AS" + " SELECT str FROM mssql_stored_proc_object " + " WHERE [id] = @id OR [num] = @n ORDER BY id;"); + + typedef mssql::query<select_objects> query; + typedef odb::result<select_objects> result; + + transaction t (db->begin ()); + + result r (db->query<select_objects> ( + query::_val (o1.id) + "," + query::_val (o2.num))); + + for (result::iterator i (r.begin ()); i != r.end (); ++i) + cout << i->str << endl; + cout << endl; + + t.commit (); + } + + { + create_procedure ( + *db, "objects_min_max", + "(@min INT = NULL OUTPUT, @max INT = NULL OUTPUT)" + "AS" + " SELECT @min = MIN(num), @max = MAX(num)" + " FROM mssql_stored_proc_object;"); + + create_procedure ( + *db, "objects_min_max_odb", + "AS" + " DECLARE @min INT, @max INT;" + " EXEC objects_min_max @min OUTPUT, @max OUTPUT;" + " SELECT @min, @max;"); + + transaction t (db->begin ()); + + objects_min_max omm (db->query_value<objects_min_max> ()); + cout << omm.num_min << " " << omm.num_max << endl + << endl; + + t.commit (); + } + + { + create_procedure ( + *db, "insert_object_id", + "(@n INT, @s VARCHAR(512))" + "AS" + " INSERT INTO mssql_stored_proc_object([num], [str])" + " VALUES(@n, @s);"); + + { + typedef mssql::query<insert_object> query; + + transaction t (db->begin ()); + + db->query_one<insert_object> ( + query::_val (4) + "," + query::_val ("d")); + + auto_ptr<object> o (db->load<object> (4)); + cout << o->num << " " << o->str << endl + << endl; + + t.commit (); + } + + { + typedef mssql::query<no_result> query; + + transaction t (db->begin ()); + + db->query_one<no_result> ( + "EXEC insert_object_id" + query::_val (5) + "," + query::_val ("e")); + + auto_ptr<object> o (db->load<object> (5)); + cout << o->num << " " << o->str << endl + << endl; + + t.commit (); + } + } + + { + create_procedure ( + *db, "insert_object_id", + "(@n INT, @s VARCHAR(512), @id INT = NULL OUTPUT)" + "AS" + " INSERT INTO mssql_stored_proc_object([num], [str])" + " VALUES(@n, @s);" + " SET @id = SCOPE_IDENTITY();" + " RETURN 123;"); + + typedef mssql::query<insert_object_id> query; + + { + create_procedure ( + *db, "insert_object_id_odb", + "(@n INT, @s VARCHAR(512))" + "AS" + " DECLARE @id INT;" + " DECLARE @ret INT;" + " EXEC @ret = insert_object_id @n, @s, @id OUTPUT;" + " SELECT @ret, @id;"); + + transaction t (db->begin ()); + + insert_object_id io ( + db->query_value<insert_object_id> ( + query::_val (6) + "," + query::_val ("f"))); + + cout << io.ret << " " << io.id << endl + << endl; + + t.commit (); + } + + // An alternative implementation that produces a different + // result set configuration at the ODBC level. + // + { + create_procedure ( + *db, "insert_object_id_odb", + "(@n INT, @s VARCHAR(512))" + "AS" + " DECLARE @id INT;" + " DECLARE @ret INT;" + " DECLARE @tbl TABLE(dummy INT);" + " INSERT INTO @tbl EXEC @ret = insert_object_id @n, @s, @id OUTPUT;" + " SELECT @ret, @id;"); + + transaction t (db->begin ()); + + insert_object_id io ( + db->query_value<insert_object_id> ( + query::_val (7) + "," + query::_val ("g"))); + + cout << io.ret << " " << io.id << endl + << endl; + + t.commit (); + } + } + } + catch (const odb::exception& e) + { + cerr << e.what () << endl; + return 1; + } +} diff --git a/odb-tests/mssql/stored-proc/test.hxx b/odb-tests/mssql/stored-proc/test.hxx new file mode 100644 index 0000000..5958ea3 --- /dev/null +++ b/odb-tests/mssql/stored-proc/test.hxx @@ -0,0 +1,63 @@ +// file : mssql/stored-proc/test.hxx +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef TEST_HXX +#define TEST_HXX + +#include <string> + +#include <odb/core.hxx> + +#pragma db view query("SELECT SCHEMA_NAME()") +struct default_schema +{ + std::string name; +}; + +#pragma db object +struct object +{ + object () {} + object (unsigned int n, std::string s): num (n), str (s) {} + + #pragma db id auto + unsigned long id; + + unsigned int num; + std::string str; +}; + +#pragma db view +struct no_result {}; + +#pragma db view query("EXEC select_all_objects") +struct select_all_objects +{ + unsigned int num; + std::string str; +}; + +#pragma db view query("EXEC select_objects (?)") +struct select_objects +{ + std::string str; +}; + +#pragma db view query("EXEC objects_min_max_odb") +struct objects_min_max +{ + unsigned int num_min; + unsigned int num_max; +}; + +#pragma db view query("EXEC insert_object_id (?)") +struct insert_object {}; + +#pragma db view query("EXEC insert_object_id_odb (?)") +struct insert_object_id +{ + unsigned int ret; + unsigned long id; +}; + +#endif // TEST_HXX diff --git a/odb-tests/mssql/template/driver.cxx b/odb-tests/mssql/template/driver.cxx new file mode 100644 index 0000000..ded03f1 --- /dev/null +++ b/odb-tests/mssql/template/driver.cxx @@ -0,0 +1,40 @@ +// file : mssql/template/driver.cxx +// license : GNU GPL v2; see accompanying LICENSE file + +// PLACE TEST DESCRIPTION HERE +// + +#include <memory> // std::auto_ptr +#include <cassert> +#include <iostream> + +#include <odb/mssql/database.hxx> +#include <odb/mssql/transaction.hxx> + +#include <common/common.hxx> + +#include "test.hxx" +#include "test-odb.hxx" + +using namespace std; +namespace mssql = odb::mssql; +using namespace mssql; + +int +main (int argc, char* argv[]) +{ + try + { + auto_ptr<database> db (create_specific_database<database> (argc, argv)); + + { + transaction t (db->begin ()); + t.commit (); + } + } + catch (const odb::exception& e) + { + cerr << e.what () << endl; + return 1; + } +} diff --git a/odb-tests/mssql/template/template-vc10.vcxproj b/odb-tests/mssql/template/template-vc10.vcxproj new file mode 100644 index 0000000..5875d9b --- /dev/null +++ b/odb-tests/mssql/template/template-vc10.vcxproj @@ -0,0 +1,180 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <ItemGroup Label="ProjectConfigurations"> + <ProjectConfiguration Include="Debug|Win32"> + <Configuration>Debug</Configuration> + <Platform>Win32</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Debug|x64"> + <Configuration>Debug</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Release|Win32"> + <Configuration>Release</Configuration> + <Platform>Win32</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Release|x64"> + <Configuration>Release</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> + </ItemGroup> + <PropertyGroup Label="Globals"> + <ProjectGuid>{__uuid__()}</ProjectGuid> + <Keyword>Win32Proj</Keyword> + <RootNamespace>__value__(name)</RootNamespace> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> + <ConfigurationType>Application</ConfigurationType> + <UseDebugLibraries>true</UseDebugLibraries> + <CharacterSet>Unicode</CharacterSet> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> + <ConfigurationType>Application</ConfigurationType> + <UseDebugLibraries>true</UseDebugLibraries> + <CharacterSet>Unicode</CharacterSet> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> + <ConfigurationType>Application</ConfigurationType> + <UseDebugLibraries>false</UseDebugLibraries> + <WholeProgramOptimization>true</WholeProgramOptimization> + <CharacterSet>Unicode</CharacterSet> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> + <ConfigurationType>Application</ConfigurationType> + <UseDebugLibraries>false</UseDebugLibraries> + <WholeProgramOptimization>true</WholeProgramOptimization> + <CharacterSet>Unicode</CharacterSet> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> + <ImportGroup Label="ExtensionSettings"> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <PropertyGroup Label="UserMacros" /> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <LinkIncremental>true</LinkIncremental> + <OutDir>$(Configuration)\</OutDir> + <TargetName>driver</TargetName> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <LinkIncremental>true</LinkIncremental> + <OutDir>$(Platform)\$(Configuration)\</OutDir> + <TargetName>driver</TargetName> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <LinkIncremental>false</LinkIncremental> + <OutDir>$(Configuration)\</OutDir> + <TargetName>driver</TargetName> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <LinkIncremental>false</LinkIncremental> + <OutDir>$(Platform)\$(Configuration)\</OutDir> + <TargetName>driver</TargetName> + </PropertyGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <ClCompile> + <PrecompiledHeader> + </PrecompiledHeader> + <WarningLevel>Level3</WarningLevel> + <Optimization>Disabled</Optimization> + <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;HAVE_CONFIG_VC_H;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <AdditionalIncludeDirectories>$(SolutionDir)\..\libcommon</AdditionalIncludeDirectories> + <DisableSpecificWarnings>4068;4355;4800;4290;%(DisableSpecificWarnings)</DisableSpecificWarnings> + </ClCompile> + <Link> + <AdditionalDependencies>$(SolutionDir)\..\libcommon\lib\common-d.lib;odb-mssql-d.lib;odb-d.lib;%(AdditionalDependencies)</AdditionalDependencies> + <SubSystem>Console</SubSystem> + <GenerateDebugInformation>true</GenerateDebugInformation> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <ClCompile> + <PrecompiledHeader> + </PrecompiledHeader> + <WarningLevel>Level3</WarningLevel> + <Optimization>Disabled</Optimization> + <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;HAVE_CONFIG_VC_H;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <AdditionalIncludeDirectories>$(SolutionDir)\..\libcommon</AdditionalIncludeDirectories> + <DisableSpecificWarnings>4068;4355;4800;4290;%(DisableSpecificWarnings)</DisableSpecificWarnings> + </ClCompile> + <Link> + <AdditionalDependencies>$(SolutionDir)\..\libcommon\lib64\common-d.lib;odb-mssql-d.lib;odb-d.lib;%(AdditionalDependencies)</AdditionalDependencies> + <SubSystem>Console</SubSystem> + <GenerateDebugInformation>true</GenerateDebugInformation> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <ClCompile> + <WarningLevel>Level3</WarningLevel> + <PrecompiledHeader> + </PrecompiledHeader> + <Optimization>MaxSpeed</Optimization> + <FunctionLevelLinking>true</FunctionLevelLinking> + <IntrinsicFunctions>true</IntrinsicFunctions> + <PreprocessorDefinitions>WIN32;_CONSOLE;HAVE_CONFIG_VC_H;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <AdditionalIncludeDirectories>$(SolutionDir)\..\libcommon</AdditionalIncludeDirectories> + <DisableSpecificWarnings>4068;4355;4800;4290;%(DisableSpecificWarnings)</DisableSpecificWarnings> + </ClCompile> + <Link> + <AdditionalDependencies>$(SolutionDir)\..\libcommon\lib\common.lib;odb-mssql.lib;odb.lib;%(AdditionalDependencies)</AdditionalDependencies> + <SubSystem>Console</SubSystem> + <GenerateDebugInformation>true</GenerateDebugInformation> + <EnableCOMDATFolding>true</EnableCOMDATFolding> + <OptimizeReferences>true</OptimizeReferences> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <ClCompile> + <WarningLevel>Level3</WarningLevel> + <PrecompiledHeader> + </PrecompiledHeader> + <Optimization>MaxSpeed</Optimization> + <FunctionLevelLinking>true</FunctionLevelLinking> + <IntrinsicFunctions>true</IntrinsicFunctions> + <PreprocessorDefinitions>WIN32;_CONSOLE;HAVE_CONFIG_VC_H;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <AdditionalIncludeDirectories>$(SolutionDir)\..\libcommon</AdditionalIncludeDirectories> + <DisableSpecificWarnings>4068;4355;4800;4290;%(DisableSpecificWarnings)</DisableSpecificWarnings> + </ClCompile> + <Link> + <AdditionalDependencies>$(SolutionDir)\..\libcommon\lib64\common.lib;odb-mssql.lib;odb.lib;%(AdditionalDependencies)</AdditionalDependencies> + <SubSystem>Console</SubSystem> + <GenerateDebugInformation>true</GenerateDebugInformation> + <EnableCOMDATFolding>true</EnableCOMDATFolding> + <OptimizeReferences>true</OptimizeReferences> + </Link> + </ItemDefinitionGroup> +__ifelse__(__value__(odb_options),,, +m4_dnl + <ItemGroup> +__custom_build_entry__( +test.hxx, +odb test.hxx, +odb.exe --std c++11 __xml__(__shell_quotes__(m4_patsubst(__value__(odb_options), __value__(src_base)/, ) -DHAVE_CONFIG_VC_H -DODB_MSC_VER=1600 -I$(SolutionDir)\..\libcommon)) test.hxx, +test-odb.hxx;test-odb.ixx;test-odb.cxx) + </ItemGroup>) + <ItemGroup> +__ifelse__(__value__(odb_options),,, +__header_entry__(test-odb.hxx) +__header_entry__(test-odb.ixx)) +__header_entries__(extra_headers) + </ItemGroup> + <ItemGroup> +__source_entry__(driver.cxx) +__ifelse__(__value__(odb_options),,,__source_entry__(test-odb.cxx)) +__source_entries__(extra_sources) + </ItemGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> + <ImportGroup Label="ExtensionTargets"> + </ImportGroup> +</Project> diff --git a/odb-tests/mssql/template/template-vc10.vcxproj.filters b/odb-tests/mssql/template/template-vc10.vcxproj.filters new file mode 100644 index 0000000..8ac18a3 --- /dev/null +++ b/odb-tests/mssql/template/template-vc10.vcxproj.filters @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <ItemGroup> + <Filter Include="Source Files"> + <UniqueIdentifier>{__uuid__()}</UniqueIdentifier> + <Extensions>cxx</Extensions> + </Filter> + <Filter Include="Header Files"> + <UniqueIdentifier>{__uuid__()}</UniqueIdentifier> + <Extensions>h;hxx;ixx;txx</Extensions> + </Filter> + </ItemGroup> + <ItemGroup> +__ifelse__(__value__(odb_options),,, +__header_filter_entry__(test.hxx) +__header_filter_entry__(test-odb.hxx) +__header_filter_entry__(test-odb.ixx)) +__header_filter_entries__(extra_headers) + </ItemGroup> + <ItemGroup> +__source_filter_entry__(driver.cxx) +__ifelse__(__value__(odb_options),,,__source_filter_entry__(test-odb.cxx)) +__source_filter_entries__(extra_sources) + </ItemGroup> +</Project>
\ No newline at end of file diff --git a/odb-tests/mssql/template/template-vc11.vcxproj b/odb-tests/mssql/template/template-vc11.vcxproj new file mode 100644 index 0000000..0bee18f --- /dev/null +++ b/odb-tests/mssql/template/template-vc11.vcxproj @@ -0,0 +1,184 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <ItemGroup Label="ProjectConfigurations"> + <ProjectConfiguration Include="Debug|Win32"> + <Configuration>Debug</Configuration> + <Platform>Win32</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Debug|x64"> + <Configuration>Debug</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Release|Win32"> + <Configuration>Release</Configuration> + <Platform>Win32</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Release|x64"> + <Configuration>Release</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> + </ItemGroup> + <PropertyGroup Label="Globals"> + <ProjectGuid>{__uuid__()}</ProjectGuid> + <Keyword>Win32Proj</Keyword> + <RootNamespace>__value__(name)</RootNamespace> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> + <ConfigurationType>Application</ConfigurationType> + <UseDebugLibraries>true</UseDebugLibraries> + <PlatformToolset>v110</PlatformToolset> + <CharacterSet>Unicode</CharacterSet> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> + <ConfigurationType>Application</ConfigurationType> + <UseDebugLibraries>true</UseDebugLibraries> + <PlatformToolset>v110</PlatformToolset> + <CharacterSet>Unicode</CharacterSet> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> + <ConfigurationType>Application</ConfigurationType> + <UseDebugLibraries>false</UseDebugLibraries> + <PlatformToolset>v110</PlatformToolset> + <WholeProgramOptimization>true</WholeProgramOptimization> + <CharacterSet>Unicode</CharacterSet> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> + <ConfigurationType>Application</ConfigurationType> + <UseDebugLibraries>false</UseDebugLibraries> + <PlatformToolset>v110</PlatformToolset> + <WholeProgramOptimization>true</WholeProgramOptimization> + <CharacterSet>Unicode</CharacterSet> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> + <ImportGroup Label="ExtensionSettings"> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <PropertyGroup Label="UserMacros" /> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <LinkIncremental>true</LinkIncremental> + <OutDir>$(Configuration)\</OutDir> + <TargetName>driver</TargetName> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <LinkIncremental>true</LinkIncremental> + <OutDir>$(Platform)\$(Configuration)\</OutDir> + <TargetName>driver</TargetName> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <LinkIncremental>false</LinkIncremental> + <OutDir>$(Configuration)\</OutDir> + <TargetName>driver</TargetName> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <LinkIncremental>false</LinkIncremental> + <OutDir>$(Platform)\$(Configuration)\</OutDir> + <TargetName>driver</TargetName> + </PropertyGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <ClCompile> + <PrecompiledHeader> + </PrecompiledHeader> + <WarningLevel>Level3</WarningLevel> + <Optimization>Disabled</Optimization> + <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;HAVE_CONFIG_VC_H;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <AdditionalIncludeDirectories>$(SolutionDir)\..\libcommon</AdditionalIncludeDirectories> + <DisableSpecificWarnings>4068;4355;4800;4290;%(DisableSpecificWarnings)</DisableSpecificWarnings> + </ClCompile> + <Link> + <AdditionalDependencies>$(SolutionDir)\..\libcommon\lib\common-d.lib;odb-mssql-d.lib;odb-d.lib;%(AdditionalDependencies)</AdditionalDependencies> + <SubSystem>Console</SubSystem> + <GenerateDebugInformation>true</GenerateDebugInformation> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <ClCompile> + <PrecompiledHeader> + </PrecompiledHeader> + <WarningLevel>Level3</WarningLevel> + <Optimization>Disabled</Optimization> + <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;HAVE_CONFIG_VC_H;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <AdditionalIncludeDirectories>$(SolutionDir)\..\libcommon</AdditionalIncludeDirectories> + <DisableSpecificWarnings>4068;4355;4800;4290;%(DisableSpecificWarnings)</DisableSpecificWarnings> + </ClCompile> + <Link> + <AdditionalDependencies>$(SolutionDir)\..\libcommon\lib64\common-d.lib;odb-mssql-d.lib;odb-d.lib;%(AdditionalDependencies)</AdditionalDependencies> + <SubSystem>Console</SubSystem> + <GenerateDebugInformation>true</GenerateDebugInformation> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <ClCompile> + <WarningLevel>Level3</WarningLevel> + <PrecompiledHeader> + </PrecompiledHeader> + <Optimization>MaxSpeed</Optimization> + <FunctionLevelLinking>true</FunctionLevelLinking> + <IntrinsicFunctions>true</IntrinsicFunctions> + <PreprocessorDefinitions>WIN32;_CONSOLE;HAVE_CONFIG_VC_H;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <AdditionalIncludeDirectories>$(SolutionDir)\..\libcommon</AdditionalIncludeDirectories> + <DisableSpecificWarnings>4068;4355;4800;4290;%(DisableSpecificWarnings)</DisableSpecificWarnings> + </ClCompile> + <Link> + <AdditionalDependencies>$(SolutionDir)\..\libcommon\lib\common.lib;odb-mssql.lib;odb.lib;%(AdditionalDependencies)</AdditionalDependencies> + <SubSystem>Console</SubSystem> + <GenerateDebugInformation>true</GenerateDebugInformation> + <EnableCOMDATFolding>true</EnableCOMDATFolding> + <OptimizeReferences>true</OptimizeReferences> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <ClCompile> + <WarningLevel>Level3</WarningLevel> + <PrecompiledHeader> + </PrecompiledHeader> + <Optimization>MaxSpeed</Optimization> + <FunctionLevelLinking>true</FunctionLevelLinking> + <IntrinsicFunctions>true</IntrinsicFunctions> + <PreprocessorDefinitions>WIN32;_CONSOLE;HAVE_CONFIG_VC_H;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <AdditionalIncludeDirectories>$(SolutionDir)\..\libcommon</AdditionalIncludeDirectories> + <DisableSpecificWarnings>4068;4355;4800;4290;%(DisableSpecificWarnings)</DisableSpecificWarnings> + </ClCompile> + <Link> + <AdditionalDependencies>$(SolutionDir)\..\libcommon\lib64\common.lib;odb-mssql.lib;odb.lib;%(AdditionalDependencies)</AdditionalDependencies> + <SubSystem>Console</SubSystem> + <GenerateDebugInformation>true</GenerateDebugInformation> + <EnableCOMDATFolding>true</EnableCOMDATFolding> + <OptimizeReferences>true</OptimizeReferences> + </Link> + </ItemDefinitionGroup> +__ifelse__(__value__(odb_options),,, +m4_dnl + <ItemGroup> +__custom_build_entry__( +test.hxx, +odb test.hxx, +odb.exe --std c++11 __xml__(__shell_quotes__(m4_patsubst(__value__(odb_options), __value__(src_base)/, ) -DHAVE_CONFIG_VC_H -DODB_MSC_VER=1700 -I$(SolutionDir)\..\libcommon)) test.hxx, +test-odb.hxx;test-odb.ixx;test-odb.cxx) + </ItemGroup>) + <ItemGroup> +__ifelse__(__value__(odb_options),,, +__header_entry__(test-odb.hxx) +__header_entry__(test-odb.ixx)) +__header_entries__(extra_headers) + </ItemGroup> + <ItemGroup> +__source_entry__(driver.cxx) +__ifelse__(__value__(odb_options),,,__source_entry__(test-odb.cxx)) +__source_entries__(extra_sources) + </ItemGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> + <ImportGroup Label="ExtensionTargets"> + </ImportGroup> +</Project> diff --git a/odb-tests/mssql/template/template-vc11.vcxproj.filters b/odb-tests/mssql/template/template-vc11.vcxproj.filters new file mode 100644 index 0000000..8ac18a3 --- /dev/null +++ b/odb-tests/mssql/template/template-vc11.vcxproj.filters @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <ItemGroup> + <Filter Include="Source Files"> + <UniqueIdentifier>{__uuid__()}</UniqueIdentifier> + <Extensions>cxx</Extensions> + </Filter> + <Filter Include="Header Files"> + <UniqueIdentifier>{__uuid__()}</UniqueIdentifier> + <Extensions>h;hxx;ixx;txx</Extensions> + </Filter> + </ItemGroup> + <ItemGroup> +__ifelse__(__value__(odb_options),,, +__header_filter_entry__(test.hxx) +__header_filter_entry__(test-odb.hxx) +__header_filter_entry__(test-odb.ixx)) +__header_filter_entries__(extra_headers) + </ItemGroup> + <ItemGroup> +__source_filter_entry__(driver.cxx) +__ifelse__(__value__(odb_options),,,__source_filter_entry__(test-odb.cxx)) +__source_filter_entries__(extra_sources) + </ItemGroup> +</Project>
\ No newline at end of file diff --git a/odb-tests/mssql/template/template-vc12.vcxproj b/odb-tests/mssql/template/template-vc12.vcxproj new file mode 100644 index 0000000..35ffb0f --- /dev/null +++ b/odb-tests/mssql/template/template-vc12.vcxproj @@ -0,0 +1,188 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <ItemGroup Label="ProjectConfigurations"> + <ProjectConfiguration Include="Debug|Win32"> + <Configuration>Debug</Configuration> + <Platform>Win32</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Debug|x64"> + <Configuration>Debug</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Release|Win32"> + <Configuration>Release</Configuration> + <Platform>Win32</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Release|x64"> + <Configuration>Release</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> + </ItemGroup> + <PropertyGroup Label="Globals"> + <ProjectGuid>{__uuid__()}</ProjectGuid> + <Keyword>Win32Proj</Keyword> + <RootNamespace>__value__(name)</RootNamespace> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> + <ConfigurationType>Application</ConfigurationType> + <UseDebugLibraries>true</UseDebugLibraries> + <PlatformToolset>v120</PlatformToolset> + <CharacterSet>Unicode</CharacterSet> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> + <ConfigurationType>Application</ConfigurationType> + <UseDebugLibraries>true</UseDebugLibraries> + <PlatformToolset>v120</PlatformToolset> + <CharacterSet>Unicode</CharacterSet> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> + <ConfigurationType>Application</ConfigurationType> + <UseDebugLibraries>false</UseDebugLibraries> + <PlatformToolset>v120</PlatformToolset> + <WholeProgramOptimization>true</WholeProgramOptimization> + <CharacterSet>Unicode</CharacterSet> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> + <ConfigurationType>Application</ConfigurationType> + <UseDebugLibraries>false</UseDebugLibraries> + <PlatformToolset>v120</PlatformToolset> + <WholeProgramOptimization>true</WholeProgramOptimization> + <CharacterSet>Unicode</CharacterSet> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> + <ImportGroup Label="ExtensionSettings"> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <PropertyGroup Label="UserMacros" /> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <LinkIncremental>true</LinkIncremental> + <OutDir>$(Configuration)\</OutDir> + <TargetName>driver</TargetName> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <LinkIncremental>true</LinkIncremental> + <OutDir>$(Platform)\$(Configuration)\</OutDir> + <TargetName>driver</TargetName> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <LinkIncremental>false</LinkIncremental> + <OutDir>$(Configuration)\</OutDir> + <TargetName>driver</TargetName> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <LinkIncremental>false</LinkIncremental> + <OutDir>$(Platform)\$(Configuration)\</OutDir> + <TargetName>driver</TargetName> + </PropertyGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <ClCompile> + <PrecompiledHeader> + </PrecompiledHeader> + <WarningLevel>Level3</WarningLevel> + <Optimization>Disabled</Optimization> + <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;HAVE_CONFIG_VC_H;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <AdditionalIncludeDirectories>$(SolutionDir)\..\libcommon</AdditionalIncludeDirectories> + <DisableSpecificWarnings>4068;4355;4800;4290;%(DisableSpecificWarnings)</DisableSpecificWarnings> + <SDLCheck>true</SDLCheck> + </ClCompile> + <Link> + <AdditionalDependencies>$(SolutionDir)\..\libcommon\lib\common-d.lib;odb-mssql-d.lib;odb-d.lib;%(AdditionalDependencies)</AdditionalDependencies> + <SubSystem>Console</SubSystem> + <GenerateDebugInformation>true</GenerateDebugInformation> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <ClCompile> + <PrecompiledHeader> + </PrecompiledHeader> + <WarningLevel>Level3</WarningLevel> + <Optimization>Disabled</Optimization> + <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;HAVE_CONFIG_VC_H;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <AdditionalIncludeDirectories>$(SolutionDir)\..\libcommon</AdditionalIncludeDirectories> + <DisableSpecificWarnings>4068;4355;4800;4290;%(DisableSpecificWarnings)</DisableSpecificWarnings> + <SDLCheck>true</SDLCheck> + </ClCompile> + <Link> + <AdditionalDependencies>$(SolutionDir)\..\libcommon\lib64\common-d.lib;odb-mssql-d.lib;odb-d.lib;%(AdditionalDependencies)</AdditionalDependencies> + <SubSystem>Console</SubSystem> + <GenerateDebugInformation>true</GenerateDebugInformation> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <ClCompile> + <WarningLevel>Level3</WarningLevel> + <PrecompiledHeader> + </PrecompiledHeader> + <Optimization>MaxSpeed</Optimization> + <FunctionLevelLinking>true</FunctionLevelLinking> + <IntrinsicFunctions>true</IntrinsicFunctions> + <PreprocessorDefinitions>WIN32;_CONSOLE;HAVE_CONFIG_VC_H;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <AdditionalIncludeDirectories>$(SolutionDir)\..\libcommon</AdditionalIncludeDirectories> + <DisableSpecificWarnings>4068;4355;4800;4290;%(DisableSpecificWarnings)</DisableSpecificWarnings> + <SDLCheck>true</SDLCheck> + </ClCompile> + <Link> + <AdditionalDependencies>$(SolutionDir)\..\libcommon\lib\common.lib;odb-mssql.lib;odb.lib;%(AdditionalDependencies)</AdditionalDependencies> + <SubSystem>Console</SubSystem> + <GenerateDebugInformation>true</GenerateDebugInformation> + <EnableCOMDATFolding>true</EnableCOMDATFolding> + <OptimizeReferences>true</OptimizeReferences> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <ClCompile> + <WarningLevel>Level3</WarningLevel> + <PrecompiledHeader> + </PrecompiledHeader> + <Optimization>MaxSpeed</Optimization> + <FunctionLevelLinking>true</FunctionLevelLinking> + <IntrinsicFunctions>true</IntrinsicFunctions> + <PreprocessorDefinitions>WIN32;_CONSOLE;HAVE_CONFIG_VC_H;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <AdditionalIncludeDirectories>$(SolutionDir)\..\libcommon</AdditionalIncludeDirectories> + <DisableSpecificWarnings>4068;4355;4800;4290;%(DisableSpecificWarnings)</DisableSpecificWarnings> + <SDLCheck>true</SDLCheck> + </ClCompile> + <Link> + <AdditionalDependencies>$(SolutionDir)\..\libcommon\lib64\common.lib;odb-mssql.lib;odb.lib;%(AdditionalDependencies)</AdditionalDependencies> + <SubSystem>Console</SubSystem> + <GenerateDebugInformation>true</GenerateDebugInformation> + <EnableCOMDATFolding>true</EnableCOMDATFolding> + <OptimizeReferences>true</OptimizeReferences> + </Link> + </ItemDefinitionGroup> +__ifelse__(__value__(odb_options),,, +m4_dnl + <ItemGroup> +__custom_build_entry__( +test.hxx, +odb test.hxx, +odb.exe --std c++11 __xml__(__shell_quotes__(m4_patsubst(__value__(odb_options), __value__(src_base)/, ) -DHAVE_CONFIG_VC_H -DODB_MSC_VER=1700 -I$(SolutionDir)\..\libcommon)) test.hxx, +test-odb.hxx;test-odb.ixx;test-odb.cxx) + </ItemGroup>) + <ItemGroup> +__ifelse__(__value__(odb_options),,, +__header_entry__(test-odb.hxx) +__header_entry__(test-odb.ixx)) +__header_entries__(extra_headers) + </ItemGroup> + <ItemGroup> +__source_entry__(driver.cxx) +__ifelse__(__value__(odb_options),,,__source_entry__(test-odb.cxx)) +__source_entries__(extra_sources) + </ItemGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> + <ImportGroup Label="ExtensionTargets"> + </ImportGroup> +</Project> diff --git a/odb-tests/mssql/template/template-vc12.vcxproj.filters b/odb-tests/mssql/template/template-vc12.vcxproj.filters new file mode 100644 index 0000000..8ac18a3 --- /dev/null +++ b/odb-tests/mssql/template/template-vc12.vcxproj.filters @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <ItemGroup> + <Filter Include="Source Files"> + <UniqueIdentifier>{__uuid__()}</UniqueIdentifier> + <Extensions>cxx</Extensions> + </Filter> + <Filter Include="Header Files"> + <UniqueIdentifier>{__uuid__()}</UniqueIdentifier> + <Extensions>h;hxx;ixx;txx</Extensions> + </Filter> + </ItemGroup> + <ItemGroup> +__ifelse__(__value__(odb_options),,, +__header_filter_entry__(test.hxx) +__header_filter_entry__(test-odb.hxx) +__header_filter_entry__(test-odb.ixx)) +__header_filter_entries__(extra_headers) + </ItemGroup> + <ItemGroup> +__source_filter_entry__(driver.cxx) +__ifelse__(__value__(odb_options),,,__source_filter_entry__(test-odb.cxx)) +__source_filter_entries__(extra_sources) + </ItemGroup> +</Project>
\ No newline at end of file diff --git a/odb-tests/mssql/template/template-vc8.vcproj b/odb-tests/mssql/template/template-vc8.vcproj new file mode 100644 index 0000000..cfd697f --- /dev/null +++ b/odb-tests/mssql/template/template-vc8.vcproj @@ -0,0 +1,354 @@ +<?xml version="1.0" encoding="Windows-1252"?> +<VisualStudioProject + ProjectType="Visual C++" + Version="8.00" + Name="__value__(name)" + ProjectGUID="{__uuid__()}" + RootNamespace="__value__(name)" + Keyword="Win32Proj" + > + <Platforms> + <Platform + Name="Win32" + /> + <Platform + Name="x64" + /> + </Platforms> + <ToolFiles> + </ToolFiles> + <Configurations> + <Configuration + Name="Debug|Win32" + OutputDirectory="$(ConfigurationName)" + IntermediateDirectory="$(ConfigurationName)" + ConfigurationType="1" + CharacterSet="1" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + AdditionalOptions="/wd4068 /wd4355 /wd4800 /wd4290" + Optimization="0" + AdditionalIncludeDirectories="$(SolutionDir)\..\libcommon" + PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;HAVE_CONFIG_VC_H" + MinimalRebuild="true" + BasicRuntimeChecks="3" + RuntimeLibrary="3" + UsePrecompiledHeader="0" + WarningLevel="3" + DebugInformationFormat="4" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLinkerTool" + AdditionalDependencies="$(SolutionDir)\..\libcommon\lib\common-d.lib odb-mssql-d.lib odb-d.lib" + OutputFile="$(OutDir)\driver.exe" + LinkIncremental="2" + GenerateDebugInformation="true" + SubSystem="1" + TargetMachine="1" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCManifestTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCAppVerifierTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </Configuration> + <Configuration + Name="Release|Win32" + OutputDirectory="$(ConfigurationName)" + IntermediateDirectory="$(ConfigurationName)" + ConfigurationType="1" + CharacterSet="1" + WholeProgramOptimization="1" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + AdditionalOptions="/wd4068 /wd4355 /wd4800 /wd4290" + AdditionalIncludeDirectories="$(SolutionDir)\..\libcommon" + PreprocessorDefinitions="WIN32;_CONSOLE;HAVE_CONFIG_VC_H" + RuntimeLibrary="2" + UsePrecompiledHeader="0" + WarningLevel="3" + DebugInformationFormat="3" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLinkerTool" + AdditionalDependencies="$(SolutionDir)\..\libcommon\lib\common.lib odb-mssql.lib odb.lib" + OutputFile="$(OutDir)\driver.exe" + LinkIncremental="1" + GenerateDebugInformation="true" + SubSystem="1" + OptimizeReferences="2" + EnableCOMDATFolding="2" + TargetMachine="1" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCManifestTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCAppVerifierTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </Configuration> + <Configuration + Name="Debug|x64" + OutputDirectory="$(PlatformName)\$(ConfigurationName)" + IntermediateDirectory="$(PlatformName)\$(ConfigurationName)" + ConfigurationType="1" + CharacterSet="1" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + TargetEnvironment="3" + /> + <Tool + Name="VCCLCompilerTool" + AdditionalOptions="/wd4068 /wd4355 /wd4800 /wd4290" + Optimization="0" + AdditionalIncludeDirectories="$(SolutionDir)\..\libcommon" + PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;HAVE_CONFIG_VC_H" + MinimalRebuild="true" + BasicRuntimeChecks="3" + RuntimeLibrary="3" + UsePrecompiledHeader="0" + WarningLevel="3" + DebugInformationFormat="3" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLinkerTool" + AdditionalDependencies="$(SolutionDir)\..\libcommon\lib64\common-d.lib odb-mssql-d.lib odb-d.lib" + OutputFile="$(OutDir)\driver.exe" + LinkIncremental="2" + GenerateDebugInformation="true" + SubSystem="1" + TargetMachine="17" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCManifestTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCAppVerifierTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </Configuration> + <Configuration + Name="Release|x64" + OutputDirectory="$(PlatformName)\$(ConfigurationName)" + IntermediateDirectory="$(PlatformName)\$(ConfigurationName)" + ConfigurationType="1" + CharacterSet="1" + WholeProgramOptimization="1" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + TargetEnvironment="3" + /> + <Tool + Name="VCCLCompilerTool" + AdditionalOptions="/wd4068 /wd4355 /wd4800 /wd4290" + AdditionalIncludeDirectories="$(SolutionDir)\..\libcommon" + PreprocessorDefinitions="WIN32;_CONSOLE;HAVE_CONFIG_VC_H" + RuntimeLibrary="2" + UsePrecompiledHeader="0" + WarningLevel="3" + DebugInformationFormat="3" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLinkerTool" + AdditionalDependencies="$(SolutionDir)\..\libcommon\lib64\common.lib odb-mssql.lib odb.lib" + OutputFile="$(OutDir)\driver.exe" + LinkIncremental="1" + GenerateDebugInformation="true" + SubSystem="1" + OptimizeReferences="2" + EnableCOMDATFolding="2" + TargetMachine="17" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCManifestTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCAppVerifierTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </Configuration> + </Configurations> + <References> + </References> + <Files> + <Filter + Name="Source Files" + Filter="cxx" + UniqueIdentifier="{__uuid__()}" + > +__source_entry__(driver.cxx) +__ifelse__(__value__(odb_options),,,__source_entry__(test-odb.cxx)) +__source_entries__(extra_sources) + </Filter> + <Filter + Name="Header Files" + Filter="h;hxx;ixx;txx" + UniqueIdentifier="{__uuid__()}" + > +__ifelse__(__value__(odb_options),,, +__file_entry_custom_build__( +test.hxx, +odb test.hxx, +odb.exe __xml__(__shell_quotes__(m4_patsubst(__value__(odb_options), __value__(src_base)/, ) -DHAVE_CONFIG_VC_H -DODB_MSC_VER=1400 -I$(SolutionDir)\..\libcommon)) test.hxx, +test-odb.hxx;test-odb.ixx;test-odb.cxx) +__file_entry__(test-odb.hxx) +__file_entry__(test-odb.ixx)) +__file_entries__(extra_headers) + </Filter> + </Files> + <Globals> + </Globals> +</VisualStudioProject> diff --git a/odb-tests/mssql/template/template-vc9.vcproj b/odb-tests/mssql/template/template-vc9.vcproj new file mode 100644 index 0000000..72a95d9 --- /dev/null +++ b/odb-tests/mssql/template/template-vc9.vcproj @@ -0,0 +1,361 @@ +<?xml version="1.0" encoding="Windows-1252"?> +<VisualStudioProject + ProjectType="Visual C++" + Version="9.00" + Name="__value__(name)" + ProjectGUID="{__uuid__()}" + RootNamespace="__value__(name)" + Keyword="Win32Proj" + TargetFrameworkVersion="196613" + > + <Platforms> + <Platform + Name="Win32" + /> + <Platform + Name="x64" + /> + </Platforms> + <ToolFiles> + </ToolFiles> + <Configurations> + <Configuration + Name="Debug|Win32" + OutputDirectory="$(ConfigurationName)" + IntermediateDirectory="$(ConfigurationName)" + ConfigurationType="1" + CharacterSet="1" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + AdditionalOptions="/wd4068 /wd4355 /wd4800 /wd4290" + Optimization="0" + AdditionalIncludeDirectories="$(SolutionDir)\..\libcommon" + PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;HAVE_CONFIG_VC_H" + MinimalRebuild="true" + BasicRuntimeChecks="3" + RuntimeLibrary="3" + UsePrecompiledHeader="0" + WarningLevel="3" + DebugInformationFormat="4" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLinkerTool" + AdditionalDependencies="$(SolutionDir)\..\libcommon\lib\common-d.lib odb-mssql-d.lib odb-d.lib" + OutputFile="$(OutDir)\driver.exe" + LinkIncremental="2" + GenerateDebugInformation="true" + SubSystem="1" + TargetMachine="1" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCManifestTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCAppVerifierTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </Configuration> + <Configuration + Name="Release|Win32" + OutputDirectory="$(ConfigurationName)" + IntermediateDirectory="$(ConfigurationName)" + ConfigurationType="1" + CharacterSet="1" + WholeProgramOptimization="1" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + AdditionalOptions="/wd4068 /wd4355 /wd4800 /wd4290" + Optimization="2" + EnableIntrinsicFunctions="true" + AdditionalIncludeDirectories="$(SolutionDir)\..\libcommon" + PreprocessorDefinitions="WIN32;_CONSOLE;HAVE_CONFIG_VC_H" + RuntimeLibrary="2" + EnableFunctionLevelLinking="true" + UsePrecompiledHeader="0" + WarningLevel="3" + DebugInformationFormat="3" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLinkerTool" + AdditionalDependencies="$(SolutionDir)\..\libcommon\lib\common.lib odb-mssql.lib odb.lib" + OutputFile="$(OutDir)\driver.exe" + LinkIncremental="1" + GenerateDebugInformation="true" + SubSystem="1" + OptimizeReferences="2" + EnableCOMDATFolding="2" + TargetMachine="1" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCManifestTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCAppVerifierTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </Configuration> + <Configuration + Name="Debug|x64" + OutputDirectory="$(PlatformName)\$(ConfigurationName)" + IntermediateDirectory="$(PlatformName)\$(ConfigurationName)" + ConfigurationType="1" + CharacterSet="1" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + TargetEnvironment="3" + /> + <Tool + Name="VCCLCompilerTool" + AdditionalOptions="/wd4068 /wd4355 /wd4800 /wd4290" + Optimization="0" + AdditionalIncludeDirectories="$(SolutionDir)\..\libcommon" + PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;HAVE_CONFIG_VC_H" + MinimalRebuild="true" + BasicRuntimeChecks="3" + RuntimeLibrary="3" + UsePrecompiledHeader="0" + WarningLevel="3" + DebugInformationFormat="3" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLinkerTool" + AdditionalDependencies="$(SolutionDir)\..\libcommon\lib64\common-d.lib odb-mssql-d.lib odb-d.lib" + OutputFile="$(OutDir)\driver.exe" + LinkIncremental="2" + GenerateDebugInformation="true" + SubSystem="1" + TargetMachine="17" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCManifestTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCAppVerifierTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </Configuration> + <Configuration + Name="Release|x64" + OutputDirectory="$(PlatformName)\$(ConfigurationName)" + IntermediateDirectory="$(PlatformName)\$(ConfigurationName)" + ConfigurationType="1" + CharacterSet="1" + WholeProgramOptimization="1" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + TargetEnvironment="3" + /> + <Tool + Name="VCCLCompilerTool" + AdditionalOptions="/wd4068 /wd4355 /wd4800 /wd4290" + Optimization="2" + EnableIntrinsicFunctions="true" + AdditionalIncludeDirectories="$(SolutionDir)\..\libcommon" + PreprocessorDefinitions="WIN32;_CONSOLE;HAVE_CONFIG_VC_H" + RuntimeLibrary="2" + EnableFunctionLevelLinking="true" + UsePrecompiledHeader="0" + WarningLevel="3" + DebugInformationFormat="3" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLinkerTool" + AdditionalDependencies="$(SolutionDir)\..\libcommon\lib64\common.lib odb-mssql.lib odb.lib" + OutputFile="$(OutDir)\driver.exe" + LinkIncremental="1" + GenerateDebugInformation="true" + SubSystem="1" + OptimizeReferences="2" + EnableCOMDATFolding="2" + TargetMachine="17" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCManifestTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCAppVerifierTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </Configuration> + </Configurations> + <References> + </References> + <Files> + <Filter + Name="Source Files" + Filter="cxx" + UniqueIdentifier="{__uuid__()}" + > +__source_entry__(driver.cxx) +__ifelse__(__value__(odb_options),,,__source_entry__(test-odb.cxx)) +__source_entries__(extra_sources) + </Filter> + <Filter + Name="Header Files" + Filter="h;hxx;ixx;txx" + UniqueIdentifier="{__uuid__()}" + > +__ifelse__(__value__(odb_options),,, +__file_entry_custom_build__( +test.hxx, +odb test.hxx, +odb.exe __xml__(__shell_quotes__(m4_patsubst(__value__(odb_options), __value__(src_base)/, ) -DHAVE_CONFIG_VC_H -DODB_MSC_VER=1500 -I$(SolutionDir)\..\libcommon)) test.hxx, +test-odb.hxx;test-odb.ixx;test-odb.cxx) +__file_entry__(test-odb.hxx) +__file_entry__(test-odb.ixx)) +__file_entries__(extra_headers) + </Filter> + </Files> + <Globals> + </Globals> +</VisualStudioProject> diff --git a/odb-tests/mssql/template/test.hxx b/odb-tests/mssql/template/test.hxx new file mode 100644 index 0000000..0bc1f95 --- /dev/null +++ b/odb-tests/mssql/template/test.hxx @@ -0,0 +1,25 @@ +// file : mssql/template/test.hxx +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef TEST_HXX +#define TEST_HXX + +#include <odb/core.hxx> + +#pragma db object +struct object +{ + object (unsigned long id) + : id_ (id) + { + } + + object () + { + } + + #pragma db id + unsigned long id_; +}; + +#endif // TEST_HXX diff --git a/odb-tests/mssql/types/driver.cxx b/odb-tests/mssql/types/driver.cxx new file mode 100644 index 0000000..d900a95 --- /dev/null +++ b/odb-tests/mssql/types/driver.cxx @@ -0,0 +1,381 @@ +// file : mssql/types/driver.cxx +// license : GNU GPL v2; see accompanying LICENSE file + +// Test SQL Server type conversion. +// + +#include <memory> // std::auto_ptr +#include <cassert> +#include <iostream> + +#include <odb/exceptions.hxx> +#include <odb/mssql/database.hxx> +#include <odb/mssql/transaction.hxx> + +#include <common/common.hxx> + +#include "test.hxx" +#include "test-odb.hxx" + +using namespace std; +namespace mssql = odb::mssql; +using namespace mssql; + +int +main (int argc, char* argv[]) +{ + try + { + auto_ptr<database> db (create_specific_database<database> (argc, argv)); + + { + object o (1); + + o.bit_ = 1; + o.utint_ = 222; + o.stint_ = -123; + o.usint_ = 65000; + o.ssint_ = -12345; + o.uint_ = 4294967290U; + o.sint_ = -1234567890; + o.ubint_ = 18446744073709551610ULL; + o.sbint_ = -1234567890123456789LL; + + o.fsm_ = -214748.3648F; + o.dsm_ = 214748.3647; + o.ism_ = -2147483647 -1; + + o.dm1_ = -922337203685477.5808; + o.dm2_ = 922337203685476.3520; // 922337203685477.5807 + o.im_ = 9223372036854775807LL; + + o.f4_ = 123.123F; + o.f8_ = 123.1234567; + + o.schar_ = "short data char "; + o.svchar_ = "short data varchar"; + + o.lchar_.assign (1025, 'a'); + o.lvchar_ = "long data varchar"; // Test the short string optimization. + o.mvchar_.assign (70000, 'm'); + o.text_.assign (70000, 't'); + + o.snchar_ = L"short data nchar\x1FFF\xD7FF "; + o.snvchar_ = L"short data nvarchar \x1FFF\xD7FF"; + + o.lnchar_.assign (513, L'\x1234'); + o.lnvchar_ = L""; // Test empty string. + o.mnvchar_.assign (70000, L'\x2345'); + o.ntext_.assign (70000, L'\x4356'); + + const char sdata[] = "abc""\x00\x01""def"; + memcpy (o.sbin_, sdata, sizeof (sdata)); + o.svbin_.assign (sdata, sdata + sizeof (sdata)); + + string ldata (256 * 1024, '\x01'); + memset (o.lbin_, 2, sizeof (o.lbin_)); + o.lvbin_.assign (50, '\x03'); + o.mvbin_.assign (ldata.begin (), ldata.end ()); + o.image_.assign (ldata.begin (), ldata.end ()); + +#if !defined(MSSQL_SERVER_VERSION) || MSSQL_SERVER_VERSION >= 1000 + o.date_ = date_time (2011, 12, 20, 0, 0, 0, 0, 0, 0); + o.time7_ = date_time (0, 0, 0, 13, 34, 39, 123456789, 0, 0); + o.time4_ = date_time (0, 0, 0, 13, 34, 39, 123456700, 0, 0); +#endif + o.sdt_ = date_time (2011, 12, 20, 15, 44, 29, 123456700, 0, 0); + o.dt_ = date_time (2011, 12, 20, 15, 44, 29, 123456700, 0, 0); +#if !defined(MSSQL_SERVER_VERSION) || MSSQL_SERVER_VERSION >= 1000 + o.dt2_ = date_time (2011, 12, 20, 15, 44, 29, 123456700, 0, 0); + o.dto7_ = date_time (2011, 12, 20, 15, 44, 29, 123456700, 2, 0); + o.dto0_ = date_time (2011, 12, 20, 15, 44, 29, 123456700, 2, 0); +#endif + +#ifdef _WIN32 + // 6F846D41-C89A-4E4D-B22F-56443CFA543F + o.guid_.Data1 = 0x6F846D41; + o.guid_.Data2 = 0xC89A; + 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. + // + { + transaction t (db->begin ()); + db->persist (o); + t.commit (); + } + +#if !defined(MSSQL_SERVER_VERSION) || MSSQL_SERVER_VERSION >= 1000 + o.time7_ = date_time (0, 0, 0, 13, 34, 39, 123456700, 0, 0); + o.time4_ = date_time (0, 0, 0, 13, 34, 39, 123400000, 0, 0); +#endif + o.sdt_ = date_time (2011, 12, 20, 15, 44, 0, 0, 0, 0); + o.dt_ = date_time (2011, 12, 20, 15, 44, 29, 123000000, 0, 0); +#if !defined(MSSQL_SERVER_VERSION) || MSSQL_SERVER_VERSION >= 1000 + o.dto0_ = date_time (2011, 12, 20, 15, 44, 29, 0, 2, 0); +#endif + + // Load. + // + { + transaction t (db->begin ()); + auto_ptr<object> o1 (db->load<object> (1)); + t.commit (); + + assert (o == *o1); + } + + typedef mssql::query<object> query; + typedef odb::result<object> result; + + // Test UUID in queries. + // + { + char uuid[16]; + memcpy (uuid, o.uuid_, 16); + + transaction t (db->begin ()); + + { + result r (db->query<object> (query::uuid == uuid)); + assert (size (r) == 1); + } + + { + result r (db->query<object> (query::uuid == query::_val (uuid))); + assert (size (r) == 1); + } + + { + result r (db->query<object> (query::uuid == query::_ref (uuid))); + assert (size (r) == 1); + } + + { + const char* d (uuid); + result r (db->query<object> (query::uuid == d)); + assert (size (r) == 1); + } + + t.commit (); + } + + // Test short/long data in queries. + // + { + transaction t (db->begin ()); + + { + result r (db->query<object> (query::svchar == o.svchar_)); + assert (size (r) == 1); + } + + { + result r (db->query<object> (query::snvchar == o.snvchar_)); + assert (size (r) == 1); + } + + { + result r (db->query<object> (query::mvchar == o.mvchar_)); + assert (size (r) == 1); + } + + { + result r (db->query<object> (query::mnvchar == o.mnvchar_)); + assert (size (r) == 1); + } + + t.commit (); + } + } + + // Test long NULL data. + // + { + long_null o1 (1); + long_null o2 (2); + o2.str_.reset (new string); + o2.str_->assign (70000, 'x'); + + // Persist. + // + { + transaction t (db->begin ()); + db->persist (o1); + db->persist (o2); + t.commit (); + } + + // Load. + // + { + transaction t (db->begin ()); + auto_ptr<long_null> p1 (db->load<long_null> (1)); + auto_ptr<long_null> p2 (db->load<long_null> (2)); + t.commit (); + + assert (o1 == *p1); + assert (o2 == *p2); + } + } + + // Test long data in containers. + // + { + long_cont o (1); + o.v.push_back (long_comp ("aaa", 123)); + o.v.push_back (long_comp (string (500, 'b'), 234)); + o.v.push_back (long_comp (string (70000, 'c'), 345)); + + // Persist. + // + { + transaction t (db->begin ()); + db->persist (o); + t.commit (); + } + + // Load. + // + { + transaction t (db->begin ()); + auto_ptr<long_cont> p (db->load<long_cont> (1)); + t.commit (); + + assert (o == *p); + } + } + + // Test char/wchar_t arrays. + // + { + char_array o1 (1, "", L""); + char_array o2 (2, "1234567890", L"12345678\x1FFF\xD7FF"); + char_array o3 (3, "1234567890123456", L"12345678901234\x1FFF\xD7FF"); + + { + transaction t (db->begin ()); + db->persist (o1); + db->persist (o2); + db->persist (o3); + t.commit (); + } + + // SQL Server returns padded values for CHAR(N)/NCHAR(N). + // + memcpy (o1.s2, " ", 16); + o1.s3[0] = o1.c1 = ' '; + memcpy (o2.s2, "1234567890 ", 16); + + memset (o1.ls2, ' ', 1025); + memset (o2.ls2 + 10, ' ', 1025 - 10); + + memcpy (o1.ws2, L" ", 16 * sizeof (wchar_t)); + o1.ws3[0] = o1.wc1 = L' '; + memcpy (o2.ws2, L"12345678\x1FFF\xD7FF ", 16 * sizeof (wchar_t)); + + for (size_t i (0); i < 257; ++i) + o1.lws2[i] = L' '; + + for (size_t i (10); i < 257; ++i) + o2.lws2[i] = L' '; + + { + transaction t (db->begin ()); + auto_ptr<char_array> p1 (db->load<char_array> (1)); + auto_ptr<char_array> p2 (db->load<char_array> (2)); + auto_ptr<char_array> p3 (db->load<char_array> (3)); + t.commit (); + + assert (o1 == *p1); + assert (o2 == *p2); + assert (o3 == *p3); + } + } + + // Test optimistic concurrency using ROWVERSION. + // + { + rowversion o (123); + o.str = "abc"; + + { + transaction t (db->begin ()); + db->persist (o); + assert (o.ver != 0); + t.commit (); + } + + { + transaction t (db->begin ()); + auto_ptr<rowversion> p (db->load<rowversion> (o.id_)); + assert (p->ver == o.ver); + p->str += 'd'; + db->update (*p); + assert (p->ver > o.ver); + + // Double-check object version was updated. + // + { + auto_ptr<rowversion> p1 (db->load<rowversion> (o.id_)); + assert (p->ver == p1->ver); + } + + o.str += 'D'; + try + { + db->update (o); + assert (false); + } + catch (const odb::object_changed&) {} + db->reload (o); + assert (o.ver == p->ver); + o.str += 'D'; + db->update (o); + t.commit (); + } + } + + { + rowversion_auto o; + o.str = "abc"; + + { + transaction t (db->begin ()); + db->persist (o); + assert (o.ver != 0); + t.commit (); + } + + { + transaction t (db->begin ()); + auto_ptr<rowversion_auto> p (db->load<rowversion_auto> (o.id_)); + assert (p->ver == o.ver); + p->str += 'd'; + db->update (*p); + assert (p->ver > o.ver); + o.str += 'D'; + try + { + db->update (o); + assert (false); + } + catch (const odb::object_changed&) {} + db->reload (o); + assert (o.ver == p->ver); + o.str += 'D'; + db->update (o); + t.commit (); + } + } + } + catch (const odb::exception& e) + { + cerr << e.what () << endl; + return 1; + } +} diff --git a/odb-tests/mssql/types/test.hxx b/odb-tests/mssql/types/test.hxx new file mode 100644 index 0000000..5d651a8 --- /dev/null +++ b/odb-tests/mssql/types/test.hxx @@ -0,0 +1,517 @@ +// file : mssql/types/test.hxx +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef TEST_HXX +#define TEST_HXX + +#ifdef _WIN32 +# ifndef WIN32_LEAN_AND_MEAN +# define WIN32_LEAN_AND_MEAN +# endif +# include <windows.h> // GUID +#elif defined(HOST_WIN32) +typedef struct _GUID +{ + unsigned int Data1; + unsigned short Data2; + unsigned short Data3; + unsigned char Data4[8]; +} GUID; +#endif + +#include <common/config.hxx> // HAVE_CXX11 + +#include <string> +#include <vector> +#include <memory> // std::auto_ptr +#include <cstring> // std::memcmp, std::memcpy, std::str[n]cmp, std::strlen +#include <cwchar> // std::wcslen, std::wcs[n]cmp + +#include <odb/core.hxx> + +struct date_time +{ + date_time () + { + } + + date_time (short y, + unsigned short m, + unsigned short d, + unsigned short h, + unsigned short min, + unsigned short sec, + unsigned int f, + short tzh, + short tzm) + : year (y), + month (m), + day (d), + hour (h), + minute (min), + second (sec), + fraction (f), + timezone_hour (tzh), + timezone_minute (tzm) + { + } + + bool + operator== (const date_time& y) const + { + return + year == y.year && + month == y.month && + day == y.day && + hour == y.hour && + minute == y.minute && + second == y.second && + fraction == y.fraction && + timezone_hour == y.timezone_hour && + timezone_minute == y.timezone_minute; + } + + short year; + unsigned short month; + unsigned short day; + unsigned short hour; + unsigned short minute; + unsigned short second; + unsigned int fraction; + short timezone_hour; + short timezone_minute; +}; + +#pragma db object +struct object +{ + object () {} + object (unsigned int id): id_ (id) {} + + #pragma db id + unsigned int id_; + + // Integer types. + // + #pragma db type ("BIT") + unsigned char bit_; + + #pragma db type ("TINYINT") + unsigned char utint_; + + #pragma db type ("TINYINT") + unsigned char stint_; + + #pragma db type ("SMALLINT") + unsigned short usint_; + + #pragma db type ("SMALLINT") + short ssint_; + + #pragma db type ("INT") + unsigned int uint_; + + #pragma db type ("INTEGER") + int sint_; + + #pragma db type ("BIGINT") + unsigned long long ubint_; + + #pragma db type ("BIGINT") + long long sbint_; + + // Floating/fixed point types. + // + #pragma db type ("SMALLMONEY") + float fsm_; + + #pragma db type ("SMALLMONEY") + double dsm_; + + #pragma db type ("SMALLMONEY") + int ism_; + + #pragma db type ("MONEY") + double dm1_; + + #pragma db type ("MONEY") + double dm2_; + + #pragma db type ("MONEY") + long long im_; + + #pragma db type ("REAL") + float f4_; + + #pragma db type ("FLOAT") + double f8_; + + // Strings. + // + #pragma db type ("CHAR(20)") + std::string schar_; + + #pragma db type ("VARCHAR(128)") + std::string svchar_; + + #pragma db type ("CHAR(1025)") + std::string lchar_; + + #pragma db type ("CHARACTER VARYING(8000)") + std::string lvchar_; + + #pragma db type ("VARCHAR(max)") + std::string mvchar_; + + #pragma db type ("TEXT") + std::string text_; + + // National strings. + // + #pragma db type ("NCHAR(20)") + std::wstring snchar_; + + #pragma db type ("NVARCHAR(128)") + std::wstring snvchar_; + + #pragma db type ("NCHAR(513)") + std::wstring lnchar_; + + #pragma db type ("NATIONAL CHARACTER VARYING(4000)") + std::wstring lnvchar_; + + #pragma db type ("NVARCHAR(max)") + std::wstring mnvchar_; + + #pragma db type ("NTEXT") + std::wstring ntext_; + + // Binary. + // + #pragma db type ("BINARY(9)") + unsigned char sbin_[9]; + + #pragma db type ("VARBINARY(256)") + std::vector<char> svbin_; + + #pragma db type ("BINARY(1025)") + char lbin_[1025]; + + #pragma db type ("BINARY VARYING(8000)") + std::vector<char> lvbin_; + + #pragma db type ("VARBINARY(max)") + std::vector<unsigned char> mvbin_; + + #pragma db type ("IMAGE") + std::vector<char> image_; + + // Date-time. SQL Server 2005 (9.0) only has DATETIME and SMALLDATETIME. + // +#if !defined(MSSQL_SERVER_VERSION) || MSSQL_SERVER_VERSION >= 1000 + #pragma db type ("DATE") + date_time date_; + + #pragma db type ("TIME") + date_time time7_; + + #pragma db type ("TIME(4)") + date_time time4_; +#endif + + #pragma db type ("SMALLDATETIME") + date_time sdt_; + + #pragma db type ("DATETIME") + date_time dt_; + +#if !defined(MSSQL_SERVER_VERSION) || MSSQL_SERVER_VERSION >= 1000 + #pragma db type ("DATETIME2") + date_time dt2_; + + #pragma db type ("DATETIMEOFFSET") + date_time dto7_; + + #pragma db type ("DATETIMEOFFSET(0)") + date_time dto0_; +#endif + + // Other types. + // +#if defined(_WIN32) || defined(HOST_WIN32) + //#pragma db type ("UNIQUEIDENTIFIER") + GUID guid_; +#endif + + #pragma db type ("UNIQUEIDENTIFIER") + char uuid_[16]; + + bool + operator== (const object& y) const + { + return + id_ == y.id_ && + bit_ == y.bit_ && + utint_ == y.utint_ && + stint_ == y.stint_ && + usint_ == y.usint_ && + ssint_ == y.ssint_ && + uint_ == y.uint_ && + sint_ == y.sint_ && + ubint_ == y.ubint_ && + sbint_ == y.sbint_ && + fsm_ == y.fsm_ && + dsm_ == y.dsm_ && + ism_ == y.ism_ && + dm1_ == y.dm1_ && + dm2_ == y.dm2_ && + im_ == y.im_ && + f4_ == y.f4_ && + f8_ == y.f8_ && + + schar_ == y.schar_ && + svchar_ == y.svchar_ && + lchar_ == y.lchar_ && + lvchar_ == y.lvchar_ && + mvchar_ == y.mvchar_ && + text_ == y.text_ && + + snchar_ == y.snchar_ && + snvchar_ == y.snvchar_ && + lnchar_ == y.lnchar_ && + lnvchar_ == y.lnvchar_ && + mnvchar_ == y.mnvchar_ && + ntext_ == y.ntext_ && + + std::memcmp (sbin_, y.sbin_, sizeof (sbin_)) == 0 && + svbin_ == y.svbin_ && + std::memcmp (lbin_, y.lbin_, sizeof (lbin_)) == 0 && + lvbin_ == y.lvbin_ && + mvbin_ == y.mvbin_ && + image_ == y.image_ + +#if !defined(MSSQL_SERVER_VERSION) || MSSQL_SERVER_VERSION >= 1000 + && date_ == y.date_ + && time7_ == y.time7_ + && time4_ == y.time4_ +#endif + && sdt_ == y.sdt_ + && dt_ == y.dt_ +#if !defined(MSSQL_SERVER_VERSION) || MSSQL_SERVER_VERSION >= 1000 + && dt2_ == y.dt2_ + && dto7_ == y.dto7_ + && dto0_ == y.dto0_ +#endif + +#ifdef _WIN32 + && std::memcmp (&guid_, &y.guid_, sizeof (guid_)) == 0 +#endif + && std::memcmp (uuid_, y.uuid_, sizeof (uuid_)) == 0; + } +}; + +// Test long NULL data. +// +#pragma db object +struct long_null +{ + long_null () {} + long_null (unsigned int id): id_ (id) {} + + #pragma db id + unsigned int id_; + + #pragma db type ("VARCHAR(max)") null +#ifdef HAVE_CXX11 + std::unique_ptr<std::string> str_; +#else + std::auto_ptr<std::string> str_; +#endif + + bool + operator== (const long_null& y) const + { + return + id_ == y.id_ && + ((str_.get () == 0 && y.str_.get () == 0) || *str_ == *y.str_); + } +}; + +// Test long data in containers, in particular column re-arrangement. +// +#pragma db value +struct long_comp +{ + long_comp () {} + long_comp (std::string s, unsigned int n): str (s), num (n) {} + + #pragma db type ("VARCHAR(max)") + std::string str; + + unsigned int num; + + bool + operator== (const long_comp& y) const + { + return str == y.str && num == y.num; + } +}; + +#pragma db object +struct long_cont +{ + long_cont () {} + long_cont (unsigned int id): id_ (id) {} + + #pragma db id + unsigned int id_; + + std::vector<long_comp> v; + + bool + operator== (const long_cont& y) const + { + return id_ == y.id_ && v == y.v; + } +}; + +// Test char/wchar_t arrays. +// +#pragma db object +struct char_array +{ + char_array () {} + char_array (unsigned long id, const char* s, const wchar_t* ws) + : id_ (id) + { + std::memcpy (s1, s, std::strlen (s) + 1); // VC++ strncpy deprecation. + std::memcpy (s2, s, std::strlen (s) + 1); + s3[0] = c1 = *s; + + std::memcpy (ws1, ws, (std::wcslen (ws) + 1) * sizeof (wchar_t)); + std::memcpy (ws2, ws, (std::wcslen (ws) + 1) * sizeof (wchar_t)); + ws3[0] = wc1 = *ws; + + if (std::strlen (s) == sizeof (s2)) + { + std::memset (ls1, '1', 1025); + ls1[1025] = '\0'; + std::memset (ls2, '2', 1025); + + for (std::size_t i (0); i < 257; ++i) + { + lws1[i] = L'1'; + lws2[i] = L'2'; + } + lws1[257] = L'\0'; + } + else + { + std::memcpy (ls1, s, std::strlen (s) + 1); // VC++ strcpy deprecation. + std::memcpy (ls2, s, std::strlen (s) + 1); + + std::memcpy (lws1, ws, (std::wcslen (ws) + 1) * sizeof (wchar_t)); + std::memcpy (lws2, ws, (std::wcslen (ws) + 1) * sizeof (wchar_t)); + } + } + + #pragma db id + unsigned long id_; + + // + // + char s1[17]; + + #pragma db type("CHAR(16)") + char s2[16]; + + char s3[1]; + char c1; + + // Long data. + // + char ls1[1026]; + + #pragma db type("CHAR(1025)") + char ls2[1025]; + + // + // + wchar_t ws1[17]; + + #pragma db type("NCHAR(16)") + wchar_t ws2[16]; + + wchar_t ws3[1]; + wchar_t wc1; + + // Long data. + // + wchar_t lws1[258]; + + #pragma db type("NCHAR(257)") + wchar_t lws2[257]; + + bool + operator== (const char_array& y) const + { + return id_ == y.id_ && + + std::strcmp (s1, y.s1) == 0 && + std::strncmp (s2, y.s2, sizeof (s2)) == 0 && + s3[0] == y.s3[0] && + c1 == y.c1 && + + std::strcmp (ls1, y.ls1) == 0 && + std::strncmp (ls2, y.ls2, sizeof (ls2)) == 0 && + + std::wcscmp (ws1, y.ws1) == 0 && + std::wcsncmp (ws2, y.ws2, sizeof (ws2) / sizeof (wchar_t)) == 0 && + ws3[0] == y.ws3[0] && + wc1 == y.wc1 && + + std::wcscmp (lws1, y.lws1) == 0 && + std::wcsncmp (lws2, y.lws2, sizeof (lws2) / sizeof (wchar_t)) == 0; + } +}; + +// Test optimistic concurrency using ROWVERSION, both with auto and +// manually-assigned ids. +// +#pragma db object optimistic +struct rowversion +{ + rowversion (unsigned int id = 0): id_ (id), ver (0) {} + + #pragma db id + unsigned int id_; + + #pragma db version type("ROWVERSION") +#ifdef _WIN32 + unsigned __int64 ver; +#else + unsigned long long ver; +#endif + + std::string str; +}; + +#pragma db object optimistic +struct rowversion_auto +{ + rowversion_auto (): ver (0) {} + + #pragma db id auto + unsigned int id_; + + #pragma db version type("ROWVERSION") +#ifdef _WIN32 + unsigned __int64 ver; +#else + unsigned long long ver; +#endif + + std::string str; +}; + +#endif // TEST_HXX diff --git a/odb-tests/mssql/types/traits.hxx b/odb-tests/mssql/types/traits.hxx new file mode 100644 index 0000000..5881f50 --- /dev/null +++ b/odb-tests/mssql/types/traits.hxx @@ -0,0 +1,223 @@ +// file : mssql/types/traits.hxx +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef TRAITS_HXX +#define TRAITS_HXX + +#include <odb/mssql/mssql-fwd.hxx> // date, time, datetime, datetimeoffset +#include <odb/mssql/traits.hxx> + +#include "test.hxx" // date_time + +namespace odb +{ + namespace mssql + { + template <> + class value_traits<date_time, id_date> + { + public: + typedef date_time value_type; + typedef date_time query_type; + typedef date image_type; + + static void + set_value (date_time& v, const date& i, bool is_null) + { + if (!is_null) + { + v.year = i.year; + v.month = i.month; + v.day = i.day; + v.hour = 0; + v.minute = 0; + v.second = 0; + v.fraction = 0; + v.timezone_hour = 0; + v.timezone_minute = 0; + } + } + + static void + set_image (date& i, bool& is_null, const date_time& v) + { + is_null = false; + i.year = v.year; + i.month = v.month; + i.day = v.day; + } + }; + + template <> + class value_traits<date_time, id_time> + { + public: + typedef date_time value_type; + typedef date_time query_type; + typedef time image_type; + + static void + set_value (date_time& v, const time& i, bool is_null) + { + if (!is_null) + { + v.year = 0; + v.month = 0; + v.day = 0; + v.hour = i.hour; + v.minute = i.minute; + v.second = i.second; + v.fraction = i.fraction; + v.timezone_hour = 0; + v.timezone_minute = 0; + } + } + + static void + set_image (time& i, unsigned short s, bool& is_null, const date_time& v) + { + const unsigned int divider[8] = + { + 1000000000, + 100000000, + 10000000, + 1000000, + 100000, + 10000, + 1000, + 100 + }; + + is_null = false; + i.hour = v.hour; + i.minute = v.minute; + i.second = v.second; + i.fraction = v.fraction - v.fraction % divider[s]; + } + }; + + template <> + class value_traits<date_time, id_datetime> + { + public: + typedef date_time value_type; + typedef date_time query_type; + typedef datetime image_type; + + static void + set_value (date_time& v, const datetime& i, bool is_null) + { + if (!is_null) + { + v.year = i.year; + v.month = i.month; + v.day = i.day; + v.hour = i.hour; + v.minute = i.minute; + v.second = i.second; + v.fraction = i.fraction; + v.timezone_hour = 0; + v.timezone_minute = 0; + } + } + + static void + set_image (datetime& i, + unsigned short s, + bool& is_null, + const date_time& v) + { + const unsigned int divider[8] = + { + 1000000000, + 100000000, + 10000000, + 1000000, + 100000, + 10000, + 1000, + 100 + }; + + is_null = false; + i.year = v.year; + i.month = v.month; + i.day = v.day; + i.hour = v.hour; + i.minute = v.minute; + + // Scale value 8 indicates we are dealing with SMALLDATETIME + // which has the minutes precision. + // + if (s != 8) + { + i.second = v.second; + i.fraction = v.fraction - v.fraction % divider[s]; + } + else + { + i.second = 0; + i.fraction = 0; + } + } + }; + + template <> + class value_traits<date_time, id_datetimeoffset> + { + public: + typedef date_time value_type; + typedef date_time query_type; + typedef datetimeoffset image_type; + + static void + set_value (date_time& v, const datetimeoffset& i, bool is_null) + { + if (!is_null) + { + v.year = i.year; + v.month = i.month; + v.day = i.day; + v.hour = i.hour; + v.minute = i.minute; + v.second = i.second; + v.fraction = i.fraction; + v.timezone_hour = i.timezone_hour; + v.timezone_minute = i.timezone_minute; + } + } + + static void + set_image (datetimeoffset& i, + unsigned short s, + bool& is_null, + const date_time& v) + { + const unsigned int divider[8] = + { + 1000000000, + 100000000, + 10000000, + 1000000, + 100000, + 10000, + 1000, + 100 + }; + + is_null = false; + i.year = v.year; + i.month = v.month; + i.day = v.day; + i.hour = v.hour; + i.minute = v.minute; + i.second = v.second; + i.fraction = v.fraction - v.fraction % divider[s]; + i.timezone_hour = v.timezone_hour; + i.timezone_minute = v.timezone_minute; + } + }; + } +} + +#endif // TRAITS_HXX |