Bug #11052 Attempting to INSERT null values into nullable columns => exception, crash
Submitted: 2 Jun 2005 21:13 Modified: 28 May 2013 10:51
Reporter: Mark Modrall Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / ODBC Severity:S2 (Serious)
Version:3.51 OS:Windows (Windows/.Net)
Assigned to: CPU Architecture:Any

[2 Jun 2005 21:13] Mark Modrall
Description:
Using MyOdbc 3.51/.Net C# to populate a database, I'm trying to use a generic template command to insert rows.  This table has a number of columns that can be null.  When I try to create an OdbcParamter() to pass that value, the code compiles and runs but throws a NullReference exception when I try
cmd.ExecuteNonQuery();.

More disturbing is that immediately after throwing that exception, the program crashes with an access violation.  Since .Net is all pointerless and memory managed my concern is that the hole is in the MyOdbc driver.

How to repeat:
In C#:
OdbcConnection activeDb = new OdbcConnection ("DSN=MySqldb");
activeDb.Open();
OdbcCommand cmd = activeDb.CreateCommand();
			
// Create table for this test if not existent
cmd.CommandText = "create table if not exists temp3 (\n"+
		"query TEXT NOT NULL,\n" +
		"first VARCHAR (10)\n" + // can be null
		") CHARACTER SET UTF8;";
cmd.ExecuteNonQuery();

// Set up insert command
cmd.CommandText = "INSERT INTO temp3 VALUES (?, ?)";
cmd.Parameters.Clear();
cmd.Add (new OdbcParameter("query", "here's a value"));
// Attempt 1 - NullReference exception, then crash on execute
     cmd.Add (new OdbcParameter("first", null));
/* also tried 
--------- Null reference exception, then crash on execute
     OdbcParameter x = new OdbcParameter("first", null);
     x.IsNullable = true;
     cmd.Add (x);
--------- NullReference exception, then crash on execute
     OdbcParameter x = new OdbcParameter ();
     x.IsNullable = true;
     cmd.Add (x);
--------- Conversion error; doesn't know how to use DBNull on constructor
     OdbcParameter x = new OdbcParameter ("first", DBNull.Value);
     cmd.Add (x);
*/
cmd.ExecuteNonQuery(); 
// crash occurs after exception is thrown

Suggested fix:
changing code to use .Net connector; seems to allow this operatio
[2 Jun 2005 23:25] Jorge del Conde
Hi,

Could you please give us a fully functional test-case that reproduces this behaviour ?  Adding a complete C# project that reproduces this behavour would be of great help.

Thanks!!
[3 Jun 2005 9:01] Vasily Kishkin
I could reproduce this bug. Test case is attached.
[3 Jun 2005 9:02] Vasily Kishkin
Test case

Attachment: 11052.zip (application/x-zip-compressed, text), 3.76 KiB.

[6 Jun 2005 23:13] Mark Matthews
Is there a reason you're not using Connector/Net?
[13 Jun 2005 17:45] Mark Modrall
Hi Mark...
I used MyOdbc first because I figured it had been around longer and would probably be more stable.  I've had some similar problems with both, as you've seen in the cases I've filed.  Is development on MyOdbc still going on, or should everyone be better off to convert to Connector/Net?

Thanks
_mark
[21 Aug 2007 16:56] MySQL Verification Team
Could you please try with latest released version 3.51.19. Thanks in advance.
[21 Sep 2007 23:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
[28 May 2013 10:51] Bogdan Degtyariov
I'm closing this bug because I can not continue without feedback from the reporter. If you have new info, please reopen the report.