diff --git a/src/oatpp-postgresql/QueryResult.cpp b/src/oatpp-postgresql/QueryResult.cpp index a1cc670..a000b4c 100644 --- a/src/oatpp-postgresql/QueryResult.cpp +++ b/src/oatpp-postgresql/QueryResult.cpp @@ -97,6 +97,10 @@ v_int64 QueryResult::getKnownCount() const { return 0; } +v_uint64 QueryResult::getRowsAffected() const { + return m_resultData.affectedRowCount; +} + bool QueryResult::hasMoreToFetch() const { return getKnownCount() > 0; } diff --git a/src/oatpp-postgresql/QueryResult.hpp b/src/oatpp-postgresql/QueryResult.hpp index 51a2852..f218031 100644 --- a/src/oatpp-postgresql/QueryResult.hpp +++ b/src/oatpp-postgresql/QueryResult.hpp @@ -71,6 +71,8 @@ class QueryResult : public orm::QueryResult { bool hasMoreToFetch() const override; + v_uint64 getRowsAffected() const override; + oatpp::Void fetch(const oatpp::Type* const resultType, v_int64 count) override; }; diff --git a/src/oatpp-postgresql/mapping/ResultMapper.cpp b/src/oatpp-postgresql/mapping/ResultMapper.cpp index f1054f3..6be2fbe 100644 --- a/src/oatpp-postgresql/mapping/ResultMapper.cpp +++ b/src/oatpp-postgresql/mapping/ResultMapper.cpp @@ -24,6 +24,7 @@ #include "ResultMapper.hpp" #include "oatpp/base/Log.hpp" +#include "oatpp/utils/parser/Caret.hpp" namespace oatpp { namespace postgresql { namespace mapping { @@ -44,6 +45,9 @@ ResultMapper::ResultData::ResultData(PGresult* pDbResult, const std::shared_ptr< } } + char* rowsAffectedStr = PQcmdTuples(dbResult); // will be freed when the result is freed + affectedRowCount = oatpp::utils::parser::Caret(rowsAffectedStr).parseUnsignedInt(); + } ResultMapper::ResultMapper() { diff --git a/src/oatpp-postgresql/mapping/ResultMapper.hpp b/src/oatpp-postgresql/mapping/ResultMapper.hpp index b4e028f..d4d85cb 100644 --- a/src/oatpp-postgresql/mapping/ResultMapper.hpp +++ b/src/oatpp-postgresql/mapping/ResultMapper.hpp @@ -85,6 +85,11 @@ class ResultMapper { */ v_int64 rowCount; + /** + * rows affected by the operation might be 0 + */ + v_uint64 affectedRowCount; + }; private: