From b89a4af4d103c1ddbbe2cabdc3d02971288e61be Mon Sep 17 00:00:00 2001 From: "Brian R. Toonen" Date: Thu, 7 Mar 2013 13:16:45 -0600 Subject: [PATCH] added implementation of get_affected_rows to the db2 backend --- src/backends/db2/statement.cpp | 15 +++++++++++++-- src/backends/db2/test/test-db2.cpp | 14 ++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/backends/db2/statement.cpp b/src/backends/db2/statement.cpp index 80a3a6d5b..5f57decdf 100644 --- a/src/backends/db2/statement.cpp +++ b/src/backends/db2/statement.cpp @@ -191,8 +191,19 @@ db2_statement_backend::fetch(int number ) long long db2_statement_backend::get_affected_rows() { - // ... - return -1; + SQLLEN rows; + + SQLRETURN cliRC = SQLRowCount(hStmt, &rows); + if (cliRC != SQL_SUCCESS && cliRC != SQL_SUCCESS_WITH_INFO) + { + throw db2_soci_error(db2_soci_error::sqlState("Error while getting affected row count", SQL_HANDLE_STMT, hStmt), cliRC); + } + else if (rows == -1) + { + throw soci_error("Error getting affected row count: statement did not perform an update, insert, delete, or merge"); + } + + return rows; } int db2_statement_backend::get_number_of_rows() diff --git a/src/backends/db2/test/test-db2.cpp b/src/backends/db2/test/test-db2.cpp index c80870451..471e336da 100644 --- a/src/backends/db2/test/test-db2.cpp +++ b/src/backends/db2/test/test-db2.cpp @@ -54,6 +54,15 @@ struct table_creator_three : public table_creator_base } }; +struct table_creator_for_get_affected_rows : table_creator_base +{ + table_creator_for_get_affected_rows(session & sql) + : table_creator_base(sql) + { + sql << "CREATE TABLE SOCI_TEST(VAL INTEGER)"; + } +}; + class test_context :public test_context_base { public: @@ -78,6 +87,11 @@ class test_context :public test_context_base return new table_creator_three(pr_s); } + table_creator_base* table_creator_4(session& s) const + { + return new table_creator_for_get_affected_rows(s); + } + std::string to_date_time(std::string const & pi_datdt_string) const { return "to_date('" + pi_datdt_string + "', 'YYYY-MM-DD HH24:MI:SS')";