aboutsummaryrefslogtreecommitdiff
path: root/odb/mssql/statement.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2012-01-20 10:30:21 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2012-01-20 10:30:21 +0200
commit9c6c3aab8607b351aead5c45de5e0eb539daf6cb (patch)
tree5c331c423125076629675bc0330d5ef37c8e6b26 /odb/mssql/statement.cxx
parent1df3d141a070c123e46d807517190f792b3a7f6e (diff)
Work around SQL Server 2005 bug with long data and OUTPUT clause
Diffstat (limited to 'odb/mssql/statement.cxx')
-rw-r--r--odb/mssql/statement.cxx27
1 files changed, 26 insertions, 1 deletions
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 <cstring> // std::strlen
+#include <cstring> // std::strlen, std::strstr
#include <cassert>
#include <odb/tracer.hxx>
@@ -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))