diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2012-01-20 10:30:22 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2012-01-20 15:43:46 +0200 |
commit | 64cc9e9f0ed1ac6742ce9d5b370bf7de7b1cb461 (patch) | |
tree | ade429bd15d070efc66386d455745cb64ce8af22 /odb/relational/mssql/source.cxx | |
parent | 89c06fb9ce3470c7a1b55cc906f2165791917957 (diff) |
Work around SQL Server 2005 bug with long data and OUTPUT clause
Diffstat (limited to 'odb/relational/mssql/source.cxx')
-rw-r--r-- | odb/relational/mssql/source.cxx | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/odb/relational/mssql/source.cxx b/odb/relational/mssql/source.cxx index 0e449dd..afb5887 100644 --- a/odb/relational/mssql/source.cxx +++ b/odb/relational/mssql/source.cxx @@ -1297,12 +1297,41 @@ namespace relational relational::query_parameters&, persist_position p) { - if (p != persist_after_columns) + semantics::data_member* id (id_member (c)); + + if (id == 0 || !auto_ (*id)) return; - semantics::data_member* id (id_member (c)); + // SQL Server 2005 has a bug that causes it to fail on an + // INSERT statement with the OUTPUT clause if data for one + // of the inserted columns is supplied at execution (long + // data). To work around this problem we use the less + // efficient batch of INSERT and SELECT statements. + // + if (options.mssql_server_version () <= mssql_version (9, 0)) + { + bool ld (false); + + if (c.count ("mssql-has-long-data")) + ld = c.get<bool> ("mssql-has-long-data"); + else + { + has_long_data t (ld); + t.traverse (c); + c.set ("mssql-has-long-data", ld); + } + + if (ld) + { + if (p == persist_after_values) + os << endl + << strlit ("; SELECT SCOPE_IDENTITY()"); + + return; + } + } - if (id != 0 && id->count ("auto")) + if (p == persist_after_columns) os << strlit (" OUTPUT INSERTED." + column_qname (*id)) << endl; } |