From 9c6c3aab8607b351aead5c45de5e0eb539daf6cb Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 20 Jan 2012 10:30:21 +0200 Subject: Work around SQL Server 2005 bug with long data and OUTPUT clause --- odb/mssql/statement.cxx | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'odb/mssql/statement.cxx') diff --git a/odb/mssql/statement.cxx b/odb/mssql/statement.cxx index b6130b9..5b6ed3c 100644 --- a/odb/mssql/statement.cxx +++ b/odb/mssql/statement.cxx @@ -3,7 +3,7 @@ // copyright : Copyright (c) 2005-2011 Code Synthesis Tools CC // license : ODB NCUEL; see accompanying LICENSE file -#include // std::strlen +#include // std::strlen, std::strstr #include #include @@ -839,6 +839,16 @@ namespace odb void insert_statement:: init_result () { + // Figure out if we are using the OUTPUT clause or a batch of + // INSERT and SELECT statements. The latter is used to work + // around a bug in SQL Server 2005 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). + // + batch_ = strstr (text_, "OUTPUT INSERTED.") == 0 && + strstr (text_, "output inserted.") == 0; + SQLRETURN r ( SQLBindCol (stmt_, 1, @@ -914,6 +924,21 @@ namespace odb // if (returning_) { + if (batch_) + { + r = SQLMoreResults (stmt_); + + if (r == SQL_NO_DATA) + { + throw database_exception ( + 0, + "?????", + "multiple result sets expected from a batch of statements"); + } + else if (!SQL_SUCCEEDED (r)) + translate_error (r, conn_, stmt_); + } + r = SQLFetch (stmt_); if (r != SQL_NO_DATA && !SQL_SUCCEEDED (r)) -- cgit v1.1