When using felixge\'s mysql for node.js, how can I ask the result object for the number of returned rows? I have a rather expensive query so I don\'t want to run a COU
With the version of mssql 2.1.2 as of 2015-04-13:
delete from DeviceAccountLinks where DeviceAccountId = @deviceAccountId and DeviceType = @deviceType
statement will produce no results as 'undefined'
I have changed the statement to:
delete from DeviceAccountLinks where DeviceAccountId = @deviceAccountId and DeviceType = @deviceType; select @@rowcount "rowCount"
to get the output of: [{rowCount:1}]
If it's a select query, just take the length of the returned array.
connection.query(sql, [var1,var2], function(err, results) {
numRows = results.length;
});
If it's an update/delete query, the returned dictionary will have an affectedRows variable.
connection.query(sql, [var1,var2], function(err, result) {
numRows = result.affectedRows;
});
If you're using the examples in the readme just look at the length property of the rows object (i.e. rows.length).