R Getting the number of rows which have been updat

2019-08-05 06:15发布

问题:

How can we get the number of rows affected by the executed UPDATE query?

r <- sqlQuery(channel, 'UPDATE foo SET bar = 1')

What I get (from a connection to a MS SQL Server DB) is just a character(0)...

回答1:

From the Microsoft Data Access SDK ODBC Help guide:

SQLRowCount returns the number of rows affected by an UPDATE, INSERT, or DELETE statement; an SQL_ADD, SQL_UPDATE_BY_BOOKMARK, or SQL_DELETE_BY_BOOKMARK operation in SQLBulkOperations; or an SQL_UPDATE or SQL_DELETE operation in SQLSetPos.

I expect that there is a way to invoke this ODBC function via the api you are using.



标签: sql r odbc rodbc