Bug #5897 missing Reference in DbType setter
Submitted: 5 Oct 2004 8:08 Modified: 13 Oct 2004 14:35
Reporter: Roman Kunert Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / NET Severity:S2 (Serious)
Version:1.0.0 OS:Windows (Windows 2000)
Assigned to: Reggie Burnett CPU Architecture:Any

[5 Oct 2004 8:08] Roman Kunert
Description:
If you construct a MySqlParameter Object with the default constructor the
member variable paramValue does not get initialized. While the DbType property setter tries to access paramValue a System.NullReferenceException is thrown, the problem is the line with the if clause:

public DbType DbType 
  {
    ...
   set 
    { 
      if (value == paramValue.DbType) return;
      paramValue = MySqlValue.GetMySqlValueFromDbType( value );
    }
}

How to repeat:
MySqlCommand com = new MySqlCommand();
MySqlParameter param = com.CreateParameter();
param.DbType = DbType.Int16;

Suggested fix:
either initialize paramValue in the default constructor or prepend "if(paramValue!=null)"...
[5 Oct 2004 13:50] Roman Kunert
I just saw that in the same class you find the lines:

public MySqlDbType MySqlDbType 
{
  get  
    { 
      return paramValue.MySqlDbType;
    }
  set  
    {
      if (paramValue != null && value == paramValue.MySqlDbType) return;
      paramValue = MySqlValue.GetMySqlValue( value, false, true );
    }
}

here it was done correctly, so one just needs to copy the above line...
[13 Oct 2004 14:35] 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