Skip to content

Commit

Permalink
added implementation of get_affected_rows to the db2 backend
Browse files Browse the repository at this point in the history
  • Loading branch information
toonen committed Mar 7, 2013
1 parent d38e21e commit b89a4af
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/backends/db2/statement.cpp
Expand Up @@ -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()
Expand Down
14 changes: 14 additions & 0 deletions src/backends/db2/test/test-db2.cpp
Expand Up @@ -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:
Expand All @@ -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')";
Expand Down

0 comments on commit b89a4af

Please sign in to comment.