From: Date: November 29 2006 6:45pm Subject: Connector/NET commit: r471 - in branches/1.0: . TestSuite mysqlclient List-Archive: http://lists.mysql.com/commits/16133 X-Bug: 24565 Message-Id: <200611291745.kATHjrUI010513@bk-internal.mysql.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Modified: branches/1.0/CHANGES branches/1.0/TestSuite/ParameterTests.cs branches/1.0/mysqlclient/parameter.cs Log: Bug #24565 Inferring DbType fails when reusing commands and the first time the value is nul This is fixed by not marking the parameter as having it's type set when null is given as the value. Modified: branches/1.0/CHANGES =================================================================== --- branches/1.0/CHANGES 2006-11-29 17:45:20 UTC (rev 470) +++ branches/1.0/CHANGES 2006-11-29 17:45:52 UTC (rev 471) @@ -7,6 +7,7 @@ Bug #23758 Unable to connect to any server - IPv6 related Bug #23749 VarChar field size over 255 causes a System.OverflowException Bug #18186 Problem with implementation of PreparedStatement + Bug #24565 Inferring DbType fails when reusing commands and the first time the value is nul Other changes ------------- Modified: branches/1.0/TestSuite/ParameterTests.cs =================================================================== --- branches/1.0/TestSuite/ParameterTests.cs 2006-11-29 17:45:20 UTC (rev 470) +++ branches/1.0/TestSuite/ParameterTests.cs 2006-11-29 17:45:52 UTC (rev 471) @@ -363,5 +363,35 @@ Assert.AreEqual(2, dt.Rows.Count); Assert.AreEqual(2, dt.Rows[1]["foo"]); } - } + + /// + /// Bug #24565 Inferring DbType fails when reusing commands and the first time the value is nul + /// + [Test] + public void UnTypedParameterBeingReused() + { + MySqlCommand cmd = new MySqlCommand("INSERT INTO test (id, dt) VALUES (?id, ?dt)", conn); + cmd.Parameters.Add("?id", 1); + MySqlParameter p = cmd.CreateParameter(); + p.ParameterName = "?dt"; + p.Value = DBNull.Value; + cmd.Parameters.Add(p); + cmd.ExecuteNonQuery(); + + cmd.Parameters[0].Value = 2; + p.Value = DateTime.Now; + cmd.ExecuteNonQuery(); + + cmd.CommandText = "SELECT * FROM test"; + cmd.Parameters.Clear(); + using (MySqlDataReader reader = cmd.ExecuteReader()) + { + reader.Read(); + Assert.IsTrue(reader.IsDBNull(2)); + reader.Read(); + Assert.IsFalse(reader.IsDBNull(2)); + Assert.IsFalse(reader.Read()); + } + } + } } Modified: branches/1.0/mysqlclient/parameter.cs =================================================================== --- branches/1.0/mysqlclient/parameter.cs 2006-11-29 17:45:20 UTC (rev 470) +++ branches/1.0/mysqlclient/parameter.cs 2006-11-29 17:45:52 UTC (rev 471) @@ -346,8 +346,11 @@ private void SetMySqlDbType(MySqlDbType mySqlDbType) { - if (this.mySqlDbType != mySqlDbType) + // if the user is changing types, then we will need to + // regenerate the value object + if (this.mySqlDbType != mySqlDbType) valueObject = null; + this.mySqlDbType = mySqlDbType; switch (mySqlDbType) { @@ -391,6 +394,11 @@ private void SetDbType(DbType dbType) { + // if the user is changing types, then we will need to + // regenerate the value object + if (this.dbType != dbType) + valueObject = null; + this.dbType = dbType; switch (dbType) { @@ -434,7 +442,7 @@ private void SetTypeFromValue() { - if (paramValue == null) return; + if (paramValue == null || paramValue == DBNull.Value) return; if (paramValue is Guid) DbType = DbType.String; @@ -465,6 +473,7 @@ default: DbType = DbType.Object; break; } } + valueObject = null; }