Bug #35492 Please implement DbCommandBuilder.QuoteIdentifier
Submitted: 21 Mar 23:55 Modified: 16 May 19:16
Reporter: Max Toro
Status: Closed
Category:Connector/Net Severity:S3 (Non-critical)
Version:all OS:Microsoft Windows
Assigned to: Target Version:
Tags: DbCommandBuilder(string), QuoteIdentifier

[21 Mar 23:55] Max Toro
Description:
Please implement DbCommandBuilder.QuoteIdentifier(string)
It is very easy to implement, and it's useful for dynamic SQL.

Also, everytime you want to use MySqlCommandBuilder you MUST set the DataAdapter property,
and that DbDataAdapter instance must have it's SelectCommand property set.
DbCommandBuilder is useful not only when used with DbDataAdapter.

How to repeat:
DbCommandBuilder builder = new MySqlCommandBuilder();
builder.QuoteIdentifier(new String());

Suggested fix:
public static string QuoteIdentifierString(this DbCommandBuilder commandBuilder, string
unquotedIdentifier) {

         if (commandBuilder == null) throw new ArgumentNullException("commandBuilder");
         if (unquotedIdentifier == null) throw new
ArgumentNullException("unquotedIdentifier");

         string qPrefix = commandBuilder.QuotePrefix, qSuffix =
commandBuilder.QuoteSuffix;

         StringBuilder builder = new StringBuilder();

         if (!string.IsNullOrEmpty(qPrefix)) {
            builder.Append(qPrefix);
            unquotedIdentifier = unquotedIdentifier.Replace(qPrefix, qPrefix + qPrefix);
         }

         if (!string.IsNullOrEmpty(qSuffix)) {
            if (!qPrefix.Equals(qSuffix, StringComparison.OrdinalIgnoreCase))
               unquotedIdentifier = unquotedIdentifier.Replace(qSuffix, qSuffix +
qSuffix);

            builder.Append(unquotedIdentifier);
            builder.Append(qSuffix);
         } else {
            builder.Append(unquotedIdentifier);
         }

         return builder.ToString();
      }
[27 Mar 16:03] 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/44518
[27 Mar 16:03] Reggie Burnett
Fixed in 5.0.9, 5.1.5, 5.2.2, +
[26 Apr 22:48] Max Toro
>>Fixed in 5.0.9, 5.1.5, 5.2.2, +

I downloaded 5.1.5 and it isn't fixed, am I missing something?
5.0.9 its OK.
[27 Apr 4:01] Reggie Burnett
Correction, this is fixed in 5.0.9, *5.1,6*, and 5.2.2+
[16 May 15:12] MC Brown
A note has been added to the 5.0.9, 5.1.6, and 5.2.2 changelogs: 

The DbCommandBuilder.QuoteIdentifer method was not implemented.
[16 May 19:16] Max Toro
what do you mean "was not implemented"? It's there!