Bug #5388 DataReader reports all rows as NULL if one row is NULL
Submitted: 3 Sep 2004 12:15 Modified: 30 Sep 2004 12:23
Reporter: Christian Hornung Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / NET Severity:S1 (Critical)
Version:1.0.0.22722 OS:Windows (Win XP SP1)
Assigned to: Reggie Burnett CPU Architecture:Any

[3 Sep 2004 12:15] Christian Hornung
Description:
A query result is being read by a MySqlDataReader or MySqlDataAdapter. If there is a row with a NULL value in any column, all following rows will also have this column set to NULL, although they have other values in the actual table.

How to repeat:
Run this code:

MySqlConnection conn = new MySqlConnection("Server=...;Database=test;Password=...;User ID=...");
conn.Open();

MySqlCommand cmd = conn.CreateCommand();

cmd.CommandText = "CREATE TABLE testnull (val SMALLINT(5) NULL)";
cmd.ExecuteNonQuery();

cmd.CommandText = "INSERT INTO testnull VALUES (1000), (2000), (3000), (NULL), (4000), (5000), (6000)";
cmd.ExecuteNonQuery();

cmd.CommandText = "SELECT val FROM testnull";
MySqlDataReader rd = cmd.ExecuteReader();
while (rd.Read()) {
	if (rd.IsDBNull(0)) {
		System.Console.WriteLine("NULL");
	} else {
		System.Console.WriteLine(rd[0]);
	}
}
rd.Close();
System.Console.ReadLine();

conn.Close();

------------------------------------------------------------------------

Logically, the output should be:
1000
2000
3000
NULL
4000
5000
6000

But it is:
1000
2000
3000
NULL
NULL
NULL
NULL
[4 Sep 2004 4:14] 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
[19 Sep 2004 21:44] Bob Strogg
Can you confirm '3rd Sep' mentioned on this bug is 2004? (there's no mention of a year anywhere, so I can't tell if this is a recent bug or not).

I upgraded due to ByteFX's problem reading BLOB fields, but seem to be hitting many more bugs in the MySql provider :o(

Thanks.
[29 Sep 2004 0:03] Danilo Tuler
MySqlClient\Field.cs, line 263
+ colValue.IsNull = false;

MySqlClient\Field41.cs, line 79
+ colValue.IsNull = false;

That fixed the problem for me. I don't know if there is another cleaner way to fix it.
[30 Sep 2004 12:23] Reggie Burnett
Yes, the fix was very similar