How to get no of records updated

General PGNP discussions.

How to get no of records updated

Postby drazen » Thu Nov 04, 2010 12:31 pm

Is there any way to get no of records updated/deleted when using CCommand.Open method (DBROWCOUNT)?
Eg, Oracle OLEDB provider always returns no of records, for SELECT, UPDATE, DELETE, etc.
drazen
 
Posts: 2
Joined: Thu Nov 04, 2010 12:25 pm

Re: How to get no of records updated

Postby Moderator » Thu Nov 04, 2010 6:21 pm

There should be a separate method Execute with the parameter:
Code: Select all
CCommand<CNoAccessor, CNoRowset> cmd;
DBROWCOUNT* pRowsAffected;
. . .
cmd.Execute(. . ., pRowsAffected, . . .);
.
User avatar
Moderator
Site Admin
 
Posts: 301
Joined: Wed Oct 29, 2008 11:27 pm

Re: How to get no of records updated

Postby drazen » Fri Nov 05, 2010 1:48 am

cmd.Open calls ExecuteAndBind that calls Execute and RowsAffected is always -1 (from ICommand::Execute method).
Should I set some properties to get correct number of rows affected?
drazen
 
Posts: 2
Joined: Thu Nov 04, 2010 12:25 pm

Re: How to get no of records updated

Postby Moderator » Fri Nov 05, 2010 11:34 pm

Here is fragment of code I used, and the number of affected rows was returned correctly:
Code: Select all
#include <atldbcli.h>
CDataSource dataSource;
CSession session;
HRESULT hr = dataSource.OpenFromInitializationString(CONN_STR);
hr = session.Open(dataSource);

// Start transaction
hr = session.StartTransaction();

// update a record in contact table
CCommand<CNoAccessor, CNoRowset> cmd;
DBROWCOUNT rowsAffected;
hr = cmd.Open(session, "UPDATE contact SET fname='test' WHERE contact_id=1", NULL, &rowsAffected, DBGUID_DBSQL, false);
cmd.Close();

// delete records
hr = cmd.Open(session, "DELETE FROM contact WHERE contact_id<>1", NULL, &rowsAffected, DBGUID_DBSQL, false);
cmd.Close();

// Rollback transaction
session.Abort();


What version of PGNP Provider are you using? Would you send sample code to reproduce the issue?
User avatar
Moderator
Site Admin
 
Posts: 301
Joined: Wed Oct 29, 2008 11:27 pm


Return to Miscellaneous

Who is online

Users browsing this forum: No registered users and 1 guest