aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2014-11-18 14:53:05 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2014-11-18 14:53:05 +0200
commit3b3c82b31116cc55f0e752fe69b15861e8f13d97 (patch)
treec07fe3d6750277ee3794894e08c090ce8be4f1bf
parent05ff680189f689d5bf82cd514e9d650c59aaf3da (diff)
Extra result set processing for stored procedure support
-rw-r--r--odb/mssql/statement.cxx44
1 files changed, 38 insertions, 6 deletions
diff --git a/odb/mssql/statement.cxx b/odb/mssql/statement.cxx
index 15037a0..00180ee 100644
--- a/odb/mssql/statement.cxx
+++ b/odb/mssql/statement.cxx
@@ -839,23 +839,55 @@ namespace odb
{
SQLRETURN r (statement::execute ());
- if (!SQL_SUCCEEDED (r))
- translate_error (r, conn_, stmt_);
+ // Skip empty result sets that seem to be added as a result of
+ // executing DML statements in stored procedures (e.g., INSERT
+ // INTO EXEC).
+ //
+ if (r == SQL_NO_DATA)
+ {
+ r = SQLMoreResults (stmt_);
-#ifndef NDEBUG
- SQLSMALLINT cols;
- r = SQLNumResultCols (stmt_, &cols);
+ if (r == SQL_NO_DATA)
+ {
+ throw database_exception (
+ 0,
+ "?????",
+ "another result set expected after SQL_NO_DATA");
+ }
+ }
if (!SQL_SUCCEEDED (r))
translate_error (r, conn_, stmt_);
+ // Skip result sets that have no columns. These seem to be added
+ // by DML statements that don't produce any result (e.g., EXEC).
+ //
+ SQLSMALLINT cols (0);
+
+ while (cols == 0)
+ {
+ r = SQLNumResultCols (stmt_, &cols);
+
+ if (!SQL_SUCCEEDED (r))
+ translate_error (r, conn_, stmt_);
+
+ if (cols == 0)
+ {
+ r = SQLMoreResults (stmt_);
+
+ if (r == SQL_NO_DATA)
+ break;
+ else if (!SQL_SUCCEEDED (r))
+ translate_error (r, conn_, stmt_);
+ }
+ }
+
// Make sure that the number of columns in the result returned by
// the database matches the number that we expect. A common cause
// of this assertion is a native view with a number of data members
// not matching the number of columns in the SELECT-list.
//
assert (static_cast<SQLUSMALLINT> (cols) == result_count_ + long_count_);
-#endif
}
select_statement::result select_statement::