From b10fcbcb273704026641a07e3d09643798a431dd Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 19 Nov 2014 13:54:38 +0200 Subject: Allow empty runtime and execute views Use them to handle INSERT/UPDATE SQL Server stored procedures. --- odb/mssql/statement.cxx | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) (limited to 'odb/mssql/statement.cxx') diff --git a/odb/mssql/statement.cxx b/odb/mssql/statement.cxx index 00180ee..e87374b 100644 --- a/odb/mssql/statement.cxx +++ b/odb/mssql/statement.cxx @@ -862,16 +862,19 @@ namespace odb // 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) + for (columns_ = 0; columns_ == 0;) { - r = SQLNumResultCols (stmt_, &cols); + { + SQLSMALLINT c; + r = SQLNumResultCols (stmt_, &c); - if (!SQL_SUCCEEDED (r)) - translate_error (r, conn_, stmt_); + if (!SQL_SUCCEEDED (r)) + translate_error (r, conn_, stmt_); + + columns_ = static_cast (c); + } - if (cols == 0) + if (columns_ == 0) { r = SQLMoreResults (stmt_); @@ -887,7 +890,7 @@ namespace odb // 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 (cols) == result_count_ + long_count_); + assert (columns_ == result_count_ + long_count_); } select_statement::result select_statement:: @@ -898,15 +901,22 @@ namespace odb if (cc != 0 && cc->callback != 0) (cc->callback) (cc->context); - SQLRETURN r (SQLFetch (stmt_)); - - if (r == SQL_NO_DATA) + // Don't bother calling SQLFetch() if there are no columns. + // + if (columns_ == 0) return no_data; + else + { + SQLRETURN r (SQLFetch (stmt_)); - if (!SQL_SUCCEEDED (r)) - translate_error (r, conn_, stmt_); + if (r == SQL_NO_DATA) + return no_data; - return success; + if (!SQL_SUCCEEDED (r)) + translate_error (r, conn_, stmt_); + + return success; + } } void select_statement:: -- cgit v1.1