Bug #50444 Parameters.Clear() not working
Submitted: 19 Jan 2010 14:14 Modified: 25 Feb 2010 10:29
Reporter: Tonci Grgin Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / NET Severity:S3 (Non-critical)
Version:trunk OS:Microsoft Windows (W2K8SE x64)
Assigned to: Reggie Burnett CPU Architecture:Any
Tags: NET FW 3.5

[19 Jan 2010 14:14] Tonci Grgin
Description:
Rewriting test case attached to Bug#50123 not to use ins2 command but ins, leads to "Parameter "?p1" is not defined" although there is a call to ins.Params.Clear();

How to repeat:
Rest of the test case in Bug#50123, this is just the relevant portion:
  --<cut>--
                if (useMySqlCommandBuilder)
                {
                    builder = new MySqlCommandBuilder(adapter);
                    ins = builder.GetInsertCommand();
                    //WA
                    builder.Dispose();
                }
                else
                {
                    ins = new MySqlCommand(
                      "INSERT INTO bug50123(fldID, fldValue) VALUES (?p1, ?p2)", conn);
                    ins.Parameters.Add("p1", MySqlDbType.Int32).SourceColumn = "fldID";
                    ins.Parameters.Add("p2", MySqlDbType.String).SourceColumn = "fldValue";
                }
  --<cut>--

                //UPDATE VIA SP
                comm.CommandText = "DROP PROCEDURE IF EXISTS pbug50123";
                comm.ExecuteNonQuery();
                comm.CommandText = "CREATE PROCEDURE pbug50123(" +
                    "IN pfldID INT, IN pfldValue VARCHAR(50)) " +
                    "BEGIN INSERT INTO bug50123(fldID, fldValue) " +
                    "VALUES(pfldID, pfldValue); END";
                comm.ExecuteNonQuery();

                // Set the Insert Command
                ins.Parameters.Clear();
                ins.CommandText = "pbug50123";
                ins.CommandType = CommandType.StoredProcedure;
                ins.Parameters.Add("pfldID", MySqlDbType.Int32).SourceColumn = "fldID";
                ins.Parameters.Add("pfldValue", MySqlDbType.String).SourceColumn = "fldValue";
                ins.UpdatedRowSource = UpdateRowSource.None;
                adapter.InsertCommand = ins;
                adapter.UpdateBatchSize = 10;

                for (int i = 21; i < 41; i++)
                {
                    DataRow row = data.NewRow();
                    row["fldID"] = i + 1;
                    row["fldValue"] = "ID = " + (i + 1);
                    data.Rows.Add(row);
                }
                // Do the update
                changed = adapter.Update(data);
                Console.Out.WriteLine("INSERT INTO bug50123 via SP: {0} rows", changed);

Suggested fix:
It appears to me that ins.Parameters.Clear() should have taken care of ?p1 and ?p2...
[19 Feb 2010 15:44] 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:

  http://lists.mysql.com/commits/100888

795 Reggie Burnett	2010-02-19
      - fixed bug where a commands batchable command text was not getting reset when the 
        command text was reset (bug #50444)
      - fixed bug where using a currently non-batchable command in a batch would throw an exception
        (bug #50123)
[19 Feb 2010 15:59] Reggie Burnett
fixed in 6.0.6, 6.1.4, 6.2.3, 6.3.1+
[25 Feb 2010 10:29] Tony Bedford
An entry has been added to the changelogs 6.0.6, 6.1.4, 6.2.3, 6.3.1:

MySqlCommand.Parameters.Clear() did not work.