Bug #9237 MySqlDataReader.AffectedRecords not set to -1
Submitted: 17 Mar 2005 0:17 Modified: 22 Mar 2005 3:50
Reporter: John Boucher Email Updates:
Status: Closed
Category:Connector/Net Severity:S2 (Serious)
Version:MySQL Connector Net 1.0.4 OS:Microsoft Windows (WinXP Pro SP2)
Assigned to: Reggie Burnett Target Version:

[17 Mar 2005 0:17] John Boucher
Description:
The MySqlDataReader's AffectedRecords property is not set to -1 when a SELECT command is
used. Not even after the DataReader is closed. I need to see this value to know whether
or not the command was a SELECT.

How to repeat:
Set the command's text to a select; e.g. "SELECT * FROM mytable" or even "SHOW TABLES",
call ExecuteReader,
look at the DataReader's AffectedRecords property.

The value should be -1, but is 0.

Suggested fix:
I don't know. I did look through the source code, but didn't see what to fix. If I try to
fix it I would start with removing the 

reader.NextResult();

in MySqlCommand.ExecuteReader
[17 Mar 2005 16:22] John Boucher
OK, in command.cs, in GetNextResultSet, I commented out:

//				if (updateCount == -1) 
//					updateCount = 0;

and it's OK for selects, but I'm having a problem with an update, which may be my
problem, so I'm still looking at it.
[17 Mar 2005 16:43] John Boucher
OK, undo that, and just a little lower do:

			if (result.IsResultSet) 
			{
				lastResult = result;
Add>>				updateCount = -1 ;
				return result;
			}
[17 Mar 2005 18:18] John Boucher
That seems to have done it, but it could be neater.
[22 Mar 2005 3:50] Reggie Burnett
Thank you for your bug report. This issue has been committed to our
source repository of that product and will be incorporated into the
next release.

If necessary, you can access the source repository and build the latest
available version, including the bugfix, yourself. More information 
about accessing the source trees is available at
    http://www.mysql.com/doc/en/Installing_source_tree.html

Additional info:

John

You were close but you have to keep in mind that RecordsAffected is for the entire batch.
 So, setting it to -1 if lastResult is a resultset will lose data.  I've checked in a fix
for this.  THanks for the bug report.

Reggie