Bug #19294 IDataRecord.GetString method should return null for null values
Submitted: 24 Apr 2006 9:15 Modified: 24 Aug 2006 9:27
Reporter: Thomas Krüger Email Updates:
Status: Closed Impact on me:
Category:Connector / NET Severity:S3 (Non-critical)
Version:1.0.7 OS:
Assigned to: Reggie Burnett CPU Architecture:Any

[24 Apr 2006 9:15] Thomas Krüger
When MySqlDataReader encounters a null value during GetString, a NullPointerException occurs. This needs to be avoided as GetString is also used for more generic purposes (when the actual type is not string).

How to repeat:
show index from host from mysql

Using the result set with
will crash when the cardinality field is a null value.

Suggested fix:
		public String GetString(int index)
			MySqlValue val = GetFieldValue(index);
			MySqlString str = (val as MySqlString);
			if (str != null) return str.Value;

                        if (val.IsNull) return null;

			if (val is MySqlBinary)
				return (currentResult[index] as MySqlBinary).ToString( fields[index].Encoding );

			return val.ToString();
[22 May 2006 16:27] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

[24 Aug 2006 9:27] MC Brown
I've added the fix to the 1.0.8 Connector/NET changelog: 

IDataRecord.GetString</literal> would raise <literal>NullPointerException</literal> for null values in returned rows. Method now throws <literal>SqlNullValueException</literal>