From 3b3c82b31116cc55f0e752fe69b15861e8f13d97 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 18 Nov 2014 14:53:05 +0200 Subject: Extra result set processing for stored procedure support --- odb/mssql/statement.cxx | 44 ++++++++++++++++++++++++++++++++++++++------ 1 file 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 (cols) == result_count_ + long_count_); -#endif } select_statement::result select_statement:: -- cgit v1.1 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 ++++++++++++++++++++++++-------------- odb/mssql/statement.hxx | 1 + odb/mssql/view-statements.hxx | 4 +++- 3 files changed, 28 insertions(+), 15 deletions(-) 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:: diff --git a/odb/mssql/statement.hxx b/odb/mssql/statement.hxx index 1c012ce..36c87f1 100644 --- a/odb/mssql/statement.hxx +++ b/odb/mssql/statement.hxx @@ -201,6 +201,7 @@ namespace odb binding& result_; SQLUSMALLINT result_count_; // Actual number of columns bound. SQLUSMALLINT long_count_; // Number of long data columns. + SQLUSMALLINT columns_; // Number of columns in result set. }; struct LIBODB_MSSQL_EXPORT auto_result diff --git a/odb/mssql/view-statements.hxx b/odb/mssql/view-statements.hxx index beb8d62..7a315a9 100644 --- a/odb/mssql/view-statements.hxx +++ b/odb/mssql/view-statements.hxx @@ -70,7 +70,9 @@ namespace odb image_type image_; std::size_t image_version_; binding image_binding_; - bind image_bind_[view_traits::column_count]; + bind image_bind_[view_traits::column_count != 0 + ? view_traits::column_count + : 1]; }; } } -- cgit v1.1 From 94f3cb74b800ab25394b22e91b3ece764fb55bb7 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 19 Nov 2014 14:48:06 +0200 Subject: Bump version to 2.4.0.a4 --- odb/mssql/version.hxx | 6 +++--- version | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/odb/mssql/version.hxx b/odb/mssql/version.hxx index 1ff4ab8..4c9b71b 100644 --- a/odb/mssql/version.hxx +++ b/odb/mssql/version.hxx @@ -29,15 +29,15 @@ // Check that we have compatible ODB version. // -#if ODB_VERSION != 20303 +#if ODB_VERSION != 20304 # error incompatible odb interface version detected #endif // libodb-mssql version: odb interface version plus the bugfix // version. // -#define LIBODB_MSSQL_VERSION 2039903 -#define LIBODB_MSSQL_VERSION_STR "2.4.0.a3" +#define LIBODB_MSSQL_VERSION 2039904 +#define LIBODB_MSSQL_VERSION_STR "2.4.0.a4" #include diff --git a/version b/version index 26d9ac3..42645da 100644 --- a/version +++ b/version @@ -1 +1 @@ -2.4.0.a3 +2.4.0.a4 -- cgit v1.1