From: Date: March 27 2008 4:02pm Subject: Connector/NET commit: r1210 - in branches/5.0: . Driver/Source TestSuite/Source List-Archive: http://lists.mysql.com/commits/44518 X-Bug: 35492 Message-Id: <200803271502.m2RF2SfY014179@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/CommandBuilder.cs branches/5.0/TestSuite/Source/CommandBuilderTests.cs Log: - added implementation of MySqlCommandBuilder methods QuoteIdentifier and UnquoteIdentifier (bug #35492) Modified: branches/5.0/CHANGES =================================================================== --- branches/5.0/CHANGES 2008-03-26 17:21:10 UTC (rev 1209) +++ branches/5.0/CHANGES 2008-03-27 15:02:28 UTC (rev 1210) @@ -31,6 +31,8 @@ - fixed problem where changing the connection string of a connection to one that changes the parameter marker after the connection had been assigned to a command but before the connection is opened can cause parameters to not be found (bug #13991) + - added implementation of MySqlCommandBuilder methods QuoteIdentifier and UnquoteIdentifier + (bug #35492) Version 5.0.8 8/16/2007 Modified: branches/5.0/Driver/Source/CommandBuilder.cs =================================================================== --- branches/5.0/Driver/Source/CommandBuilder.cs 2008-03-26 17:21:10 UTC (rev 1209) +++ branches/5.0/Driver/Source/CommandBuilder.cs 2008-03-27 15:02:28 UTC (rev 1210) @@ -180,6 +180,42 @@ base.RefreshSchema(); finalSelect = null; } + + public override string QuoteIdentifier(string unquotedIdentifier) + { + if (unquotedIdentifier == null) throw new + ArgumentNullException("unquotedIdentifier"); + + // don't quote again if it is already quoted + if (unquotedIdentifier.StartsWith(QuotePrefix) && + unquotedIdentifier.EndsWith(QuoteSuffix)) + return unquotedIdentifier; + + unquotedIdentifier = unquotedIdentifier.Replace(QuotePrefix, QuotePrefix + QuotePrefix); + + return String.Format("{0}{1}{2}", QuotePrefix, unquotedIdentifier, QuoteSuffix); + } + + public override string UnquoteIdentifier(string quotedIdentifier) + { + if (quotedIdentifier == null) throw new + ArgumentNullException("quotedIdentifier"); + + // don't unquote again if it is already unquoted + if (!quotedIdentifier.StartsWith(QuotePrefix) || + !quotedIdentifier.EndsWith(QuoteSuffix)) + return quotedIdentifier; + + if (quotedIdentifier.StartsWith(QuotePrefix)) + quotedIdentifier = quotedIdentifier.Substring(1); + if (quotedIdentifier.EndsWith(QuoteSuffix)) + quotedIdentifier = quotedIdentifier.Substring(0, quotedIdentifier.Length - 1); + + quotedIdentifier = quotedIdentifier.Replace(QuotePrefix + QuotePrefix, QuotePrefix); + + return quotedIdentifier; + } + #endregion Modified: branches/5.0/TestSuite/Source/CommandBuilderTests.cs =================================================================== --- branches/5.0/TestSuite/Source/CommandBuilderTests.cs 2008-03-26 17:21:10 UTC (rev 1209) +++ branches/5.0/TestSuite/Source/CommandBuilderTests.cs 2008-03-27 15:02:28 UTC (rev 1210) @@ -373,5 +373,22 @@ Assert.Fail(ex.Message); } } + + /// + /// Bug #35492 Please implement DbCommandBuilder.QuoteIdentifier + /// + [Test] + public void QuoteAndUnquoteIdentifiers() + { + MySqlCommandBuilder cb = new MySqlCommandBuilder(); + Assert.AreEqual("`boo`", cb.QuoteIdentifier("boo")); + Assert.AreEqual("`bo``o`", cb.QuoteIdentifier("bo`o")); + Assert.AreEqual("`boo`", cb.QuoteIdentifier("`boo`")); + + // now do the unquoting + Assert.AreEqual("boo", cb.UnquoteIdentifier("`boo`")); + Assert.AreEqual("`boo", cb.UnquoteIdentifier("`boo")); + Assert.AreEqual("bo`o", cb.UnquoteIdentifier("`bo``o`")); + } } }