From: Date: July 10 2008 11:14pm Subject: Connector/NET commit: r1332 - in branches/5.0: . Driver/Source/Types TestSuite/Source List-Archive: http://lists.mysql.com/commits/49501 X-Bug: 37968 Message-Id: <200807102114.m6ALEcHd018129@bk-internal.mysql.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Modified: branches/5.0/CHANGES branches/5.0/Driver/Source/Types/MySqlByte.cs branches/5.0/Driver/Source/Types/MySqlUByte.cs branches/5.0/TestSuite/Source/PreparedStatements.cs Log: Fixed problem with byte and unsigned byte values writing more too many bytes when using prepared statements (bug #37968) Modified: branches/5.0/CHANGES =================================================================== --- branches/5.0/CHANGES 2008-07-09 16:44:37 UTC (rev 1331) +++ branches/5.0/CHANGES 2008-07-10 21:14:38 UTC (rev 1332) @@ -7,7 +7,11 @@ when there is room to make a new connection and the pool has no idle connections. - Fixed MySqlConnectionStringBuilder to first remove old keyword settings when setting a value that was previously set (bug #37955) - + - Fixed problem where executing a command that results in a fatal exception would not + close the connection. (bug #37991) + - Fixed problem with byte and unsigned byte values writing more too many bytes when + using prepared statements (bug #37968) + Version 5.0.9 - 4/14/08 - Fixed problem where fields that were blobs but did not include the BLOB flag were treated Modified: branches/5.0/Driver/Source/Types/MySqlByte.cs =================================================================== --- branches/5.0/Driver/Source/Types/MySqlByte.cs 2008-07-09 16:44:37 UTC (rev 1331) +++ branches/5.0/Driver/Source/Types/MySqlByte.cs 2008-07-10 21:14:38 UTC (rev 1332) @@ -82,10 +82,13 @@ void IMySqlValue.WriteValue(MySqlStream stream, bool binary, object val, int length) { sbyte v = ((IConvertible)val).ToSByte(null); - if (binary) - stream.Write(BitConverter.GetBytes(v)); - else - stream.WriteStringNoNull(v.ToString()); + if (binary) + { + byte[] b = BitConverter.GetBytes(v); + stream.WriteByte(b[0]); + } + else + stream.WriteStringNoNull(v.ToString()); } IMySqlValue IMySqlValue.ReadValue(MySqlStream stream, long length, bool nullVal) Modified: branches/5.0/Driver/Source/Types/MySqlUByte.cs =================================================================== --- branches/5.0/Driver/Source/Types/MySqlUByte.cs 2008-07-09 16:44:37 UTC (rev 1331) +++ branches/5.0/Driver/Source/Types/MySqlUByte.cs 2008-07-10 21:14:38 UTC (rev 1332) @@ -81,10 +81,13 @@ void IMySqlValue.WriteValue(MySqlStream stream, bool binary, object val, int length) { byte v = ((IConvertible)val).ToByte(null); - if (binary) - stream.Write(BitConverter.GetBytes(v)); - else - stream.WriteStringNoNull(v.ToString()); + if (binary) + { + byte[] b = BitConverter.GetBytes(v); + stream.WriteByte(b[0]); + } + else + stream.WriteStringNoNull(v.ToString()); } IMySqlValue IMySqlValue.ReadValue(MySqlStream stream, long length, bool nullVal) Modified: branches/5.0/TestSuite/Source/PreparedStatements.cs =================================================================== --- branches/5.0/TestSuite/Source/PreparedStatements.cs 2008-07-09 16:44:37 UTC (rev 1331) +++ branches/5.0/TestSuite/Source/PreparedStatements.cs 2008-07-10 21:14:38 UTC (rev 1332) @@ -28,6 +28,12 @@ [TestFixture] public class PreparedStatements : BaseTest { + protected override void FixtureSetup() + { + csAdditions = ";ignore prepare=false;"; + base.FixtureSetup(); + } + protected override void Setup() { base.Setup(); @@ -772,6 +778,39 @@ Assert.AreEqual(initialCount, GetPreparedStatementCount()); } } + + /// + /// Bug #37968 Prepared statements byte/tinyint causes data corruption. + /// + [Test] + public void InsertingUnsignedTinyInt() + { + execSQL("DROP TABLE IF EXISTS Test"); + execSQL(@"CREATE TABLE Test(id TINYINT UNSIGNED NOT NULL, + id2 INT UNSIGNED, id3 TINYINT UNSIGNED, id4 INT UNSIGNED NOT NULL)"); + + MySqlCommand cmd = new MySqlCommand("INSERT INTO Test VALUES (?id, ?id2, ?id3, ?id4)", conn); + cmd.Parameters.Add("?id", MySqlDbType.UByte); + cmd.Parameters.Add("?id2", MySqlDbType.UByte); + cmd.Parameters.Add("?id3", MySqlDbType.UByte); + cmd.Parameters.Add("?id4", MySqlDbType.UByte); + cmd.Prepare(); + + cmd.Parameters[0].Value = 127; + cmd.Parameters[1].Value = 1; + cmd.Parameters[2].Value = 2; + cmd.Parameters[3].Value = 3; + cmd.ExecuteNonQuery(); + + MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM Test", conn); + DataTable dt = new DataTable(); + da.Fill(dt); + Assert.AreEqual(1, dt.Rows.Count); + Assert.AreEqual(127, dt.Rows[0][0]); + Assert.AreEqual(1, dt.Rows[0][1]); + Assert.AreEqual(2, dt.Rows[0][2]); + Assert.AreEqual(3, dt.Rows[0][3]); + } } #region Configs