Overview
Features
Download
Documentation
Community
Add-Ons & Services

Can NOT get the affected record number of UPDATE or DELETE

Please post support and help requests here.

Can NOT get the affected record number of UPDATE or DELETE

Postby byronk » 08 Jun 2009, 11:02

I'm using SQLite database engine to store data. When I use following code to update data, I can't get the number of records affected. The result of execute() is always 0. How to get the number of UPDATE or DELETE statement affected? Anyone has suggestions?

Code: Select all
   Statement update(*_session);
   update << "UPDATE MailAccount SET Type=?, Host=?, Port=?, User=?, Pass=?, Status=? WHERE ID=?",
      use(account.accType),
      use(account.host),
      use(account.port),
      use(account.user),
      use(account.pass),
      use(account.status),
      use(account.id);

   try
   {
      int rowAffected = update.execute();
      debugLog("Update record count: "+N2S(rowAffected));
   }
   catch (Exception& exc)
   {
      debugLog(exc.displayText());
      return false;
   }
byronk
 
Posts: 2
Joined: 08 Jun 2009, 10:54

Re: Can NOT get the affected record number of UPDATE or DELETE

Postby guenter » 08 Jun 2009, 18:53

Statement::execute() returns the number of rows extracted from the database.

You could try the following:

Code: Select all
*_session << "PRAGMA count_changes = ON", now;
int changes;
Statement update(*_session);
   update << "UPDATE MailAccount SET Type=?, Host=?, Port=?, User=?, Pass=?, Status=? WHERE ID=?",
      use(account.accType),
      use(account.host),
      use(account.port),
      use(account.user),
      use(account.pass),
      use(account.status),
      use(account.id),
      into(changes);


This is, however, SQLite specific. Another option would be to extend the Session class so that it provides a way to call sqlite3_changes(). This could be through a property, for example.
guenter
 
Posts: 1119
Joined: 11 Jul 2006, 16:27
Location: Austria

Re: Can NOT get the affected record number of UPDATE or DELETE

Postby byronk » 09 Jun 2009, 09:23

It works! Thanks.
byronk
 
Posts: 2
Joined: 08 Jun 2009, 10:54

Re: Can NOT get the affected record number of UPDATE or DELE

Postby HardRock » 10 Oct 2012, 14:52

It does not work for me =(

MySQL connector. POCO 1.4.4


*stm << "UPDATE _table SET title = ?, WHERE id = ?",
Poco::Data::use( Info.Title ),
Poco::Data::use( Info.Id ),
Poco::Data::into( RowsAffected )
;

RowsAffected always == 0

How to get it work?
HardRock
 
Posts: 5
Joined: 10 Oct 2012, 13:46


Return to Support

Who is online

Users browsing this forum: No registered users and 1 guest

cron