Skip to content

Commit 4ce8516

Browse files
committed
MySQL: Implemented affectedRowCount
1 parent ae26e45 commit 4ce8516

3 files changed

Lines changed: 14 additions & 2 deletions

File tree

‎Data/MySQL/include/Poco/Data/MySQL/StatementExecutor.h‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ class StatementExecutor
8585

8686
bool fetchColumn(std::size_t n, MYSQL_BIND *bind);
8787
/// Fetches the column.
88+
89+
std::size_t getAffectedRowCount() const;
8890

8991
operator MYSQL_STMT* ();
9092
/// Cast operator to native handle type.
@@ -95,9 +97,10 @@ class StatementExecutor
9597
StatementExecutor& operator=(const StatementExecutor&);
9698

9799
private:
98-
100+
MYSQL* _pSessionHandle;
99101
MYSQL_STMT* _pHandle;
100102
int _state;
103+
std::size_t _affectedRowCount;
101104
std::string _query;
102105
};
103106

‎Data/MySQL/src/MySQLStatementImpl.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ std::size_t MySQLStatementImpl::columnsReturned() const
6363

6464
std::size_t MySQLStatementImpl::affectedRowCount() const
6565
{
66-
return 0;
66+
return _stmt.getAffectedRowCount();
6767
}
6868

6969

‎Data/MySQL/src/StatementExecutor.cpp‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ namespace MySQL {
4545

4646

4747
StatementExecutor::StatementExecutor(MYSQL* mysql)
48+
: _pSessionHandle(mysql)
49+
, _affectedRowCount(0)
4850
{
4951
if (!(_pHandle = mysql_stmt_init(mysql)))
5052
throw StatementException("mysql_stmt_init error");
@@ -115,6 +117,8 @@ void StatementExecutor::execute()
115117
throw StatementException("mysql_stmt_execute error", _pHandle, _query);
116118

117119
_state = STMT_EXECUTED;
120+
121+
_affectedRowCount = mysql_affected_rows(_pSessionHandle);
118122
}
119123

120124

@@ -149,5 +153,10 @@ bool StatementExecutor::fetchColumn(std::size_t n, MYSQL_BIND *bind)
149153
return (res == 0);
150154
}
151155

156+
std::size_t StatementExecutor::getAffectedRowCount() const
157+
{
158+
return _affectedRowCount;
159+
}
160+
152161

153162
}}}

0 commit comments

Comments
 (0)