From: Date: February 6 2008 7:29pm Subject: Connector/NET commit: r1161 - in branches/5.1: . Driver/Source TestSuite/Source List-Archive: http://lists.mysql.com/commits/41806 X-Bug: 34052 Message-Id: <200802061829.m16ITrYW031648@bk-internal.mysql.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Modified: branches/5.1/CHANGES branches/5.1/Driver/Source/Field.cs branches/5.1/Driver/Source/MySqlConnectionStringBuilder.cs branches/5.1/TestSuite/Source/DataTypeTests.cs Log: - Added connection string option 'Treat Tiny As Boolean' so applications that expect TINYINT(1) to return an integer will not break (bug #34052) Modified: branches/5.1/CHANGES =================================================================== --- branches/5.1/CHANGES 2008-02-05 20:07:19 UTC (rev 1160) +++ branches/5.1/CHANGES 2008-02-06 18:29:53 UTC (rev 1161) @@ -9,6 +9,8 @@ - Fixed problem with opening a connection that was previously closed by sudden server disconnection (bug #33909) - Fixed code to yeild better exception when using different connection strings in a single transaction (bug #34204) - Small bugfix and speed enhancement in Statement.TokenizeSql (bug #34220) + - Added connection string option 'Treat Tiny As Boolean' so applications that expect TINYINT(1) + to return an integer will not break (bug #34052) Version 5.1.4 - 11/12/2007 - Fixed issue where column name metadata was not using the charset given on the connection string Modified: branches/5.1/Driver/Source/Field.cs =================================================================== --- branches/5.1/Driver/Source/Field.cs 2008-02-05 20:07:19 UTC (rev 1160) +++ branches/5.1/Driver/Source/Field.cs 2008-02-06 18:29:53 UTC (rev 1161) @@ -278,7 +278,7 @@ public IMySqlValue GetValueObject() { IMySqlValue v = GetIMySqlValue(Type); - if (v is MySqlByte && ColumnLength == 1 && MaxLength == 1) + if (v is MySqlByte && ColumnLength == 1 && MaxLength == 1 && connection.Settings.TreatTinyAsBoolean) { MySqlByte b = (MySqlByte)v; b.TreatAsBoolean = true; Modified: branches/5.1/Driver/Source/MySqlConnectionStringBuilder.cs =================================================================== --- branches/5.1/Driver/Source/MySqlConnectionStringBuilder.cs 2008-02-05 20:07:19 UTC (rev 1160) +++ branches/5.1/Driver/Source/MySqlConnectionStringBuilder.cs 2008-02-06 18:29:53 UTC (rev 1161) @@ -50,6 +50,7 @@ string blobAsUtf8IncludePattern, blobAsUtf8ExcludePattern; Regex blobAsUtf8ExcludeRegex, blobAsUtf8IncludeRegex; uint defaultCommandTimeout; + bool treatTinyAsBoolean; static MySqlConnectionStringBuilder() { @@ -88,6 +89,7 @@ defaultValues.Add(Keyword.BlobAsUTF8IncludePattern, null); defaultValues.Add(Keyword.TreatBlobsAsUTF8, false); defaultValues.Add(Keyword.DefaultCommandTimeout, 30); + defaultValues.Add(Keyword.TreatTinyAsBoolean, true); } /// @@ -645,6 +647,23 @@ } } +#if !CF && !MONO + [Category("Advanced")] + [DisplayName("Treat Tiny As Boolean")] + [Description("Should the provider treat TINYINT(1) columns as boolean.")] + [DefaultValue(true)] + [RefreshProperties(RefreshProperties.All)] +#endif + public bool TreatTinyAsBoolean + { + get { return treatTinyAsBoolean; } + set + { + SetValue("Treat Tiny As Boolean", value); + treatTinyAsBoolean = value; + } + } + #endregion #region Pooling Properties @@ -1068,6 +1087,8 @@ return Keyword.TreatBlobsAsUTF8; case "default command timeout": return Keyword.DefaultCommandTimeout; + case "treat tiny as boolean": + return Keyword.TreatTinyAsBoolean; } throw new ArgumentException(Resources.KeywordNotSupported, key); } @@ -1146,6 +1167,8 @@ return blobAsUtf8IncludePattern; case Keyword.DefaultCommandTimeout: return defaultCommandTimeout; + case Keyword.TreatTinyAsBoolean: + return treatTinyAsBoolean; default: return null; /* this will never happen */ } @@ -1236,6 +1259,8 @@ blobAsUtf8IncludePattern = (string)value; break; case Keyword.DefaultCommandTimeout: defaultCommandTimeout = ConvertToUInt(value); break; + case Keyword.TreatTinyAsBoolean: + treatTinyAsBoolean = ConvertToBool(value); break; } } @@ -1413,6 +1438,7 @@ TreatBlobsAsUTF8, BlobAsUTF8IncludePattern, BlobAsUTF8ExcludePattern, - DefaultCommandTimeout + DefaultCommandTimeout, + TreatTinyAsBoolean } } Modified: branches/5.1/TestSuite/Source/DataTypeTests.cs =================================================================== --- branches/5.1/TestSuite/Source/DataTypeTests.cs 2008-02-05 20:07:19 UTC (rev 1160) +++ branches/5.1/TestSuite/Source/DataTypeTests.cs 2008-02-06 18:29:53 UTC (rev 1161) @@ -468,45 +468,48 @@ public void BitAndDecimal() { execSQL("DROP TABLE IF EXISTS Test"); - execSQL("CREATE TABLE Test (bt1 BIT, bt4 BIT(4), bt11 BIT(11), bt23 BIT(23), bt32 BIT(32)) engine=myisam"); - execSQL("INSERT INTO Test VALUES (1, 2, 120, 240, 1000)"); + execSQL("CREATE TABLE Test (bt1 BIT(2), bt4 BIT(4), bt11 BIT(11), bt23 BIT(23), bt32 BIT(32)) engine=myisam"); + execSQL("INSERT INTO Test VALUES (2, 3, 120, 240, 1000)"); execSQL("INSERT INTO Test VALUES (NULL, NULL, 100, NULL, NULL)"); - MySqlCommand cmd = new MySqlCommand("SELECT * FROM Test", conn); - MySqlDataReader reader = null; - try + string connStr = GetConnectionString(true) + ";treat tiny as boolean=false"; + using (MySqlConnection c = new MySqlConnection(connStr)) { - reader = cmd.ExecuteReader(); - Assert.IsTrue(reader.Read()); - Assert.AreEqual(1, reader.GetInt32(0)); - Assert.AreEqual(2, reader.GetInt32(1)); - Assert.AreEqual(120, reader.GetInt32(2)); - if (version >= new Version(5,0)) + c.Open(); + + MySqlCommand cmd = new MySqlCommand("SELECT * FROM Test", c); + using (MySqlDataReader reader = cmd.ExecuteReader()) { - Assert.AreEqual(240, reader.GetInt32(3)); - Assert.AreEqual(1000, reader.GetInt32(4)); + try + { + Assert.IsTrue(reader.Read()); + Assert.AreEqual(2, reader.GetInt32(0)); + Assert.AreEqual(3, reader.GetInt32(1)); + Assert.AreEqual(120, reader.GetInt32(2)); + if (version >= new Version(5, 0)) + { + Assert.AreEqual(240, reader.GetInt32(3)); + Assert.AreEqual(1000, reader.GetInt32(4)); + } + else + { + Assert.AreEqual(127, reader.GetInt32(3)); + Assert.AreEqual(127, reader.GetInt32(4)); + } + + Assert.IsTrue(reader.Read()); + Assert.IsTrue(reader.IsDBNull(0)); + Assert.IsTrue(reader.IsDBNull(1)); + Assert.AreEqual(100, reader.GetInt32(2)); + Assert.IsTrue(reader.IsDBNull(3)); + Assert.IsTrue(reader.IsDBNull(4)); + } + catch (Exception ex) + { + Assert.Fail(ex.Message); + } } - else - { - Assert.AreEqual(127, reader.GetInt32(3)); - Assert.AreEqual(127, reader.GetInt32(4)); - } - - Assert.IsTrue(reader.Read()); - Assert.IsTrue(reader.IsDBNull(0)); - Assert.IsTrue(reader.IsDBNull(1)); - Assert.AreEqual(100, reader.GetInt32(2)); - Assert.IsTrue(reader.IsDBNull(3)); - Assert.IsTrue(reader.IsDBNull(4)); } - catch (Exception ex) - { - Assert.Fail(ex.Message); - } - finally - { - if (reader != null) reader.Close(); - } } ///