Bug #105728 Parameter name overrides query attributes
Submitted: 27 Nov 2021 21:19 Modified: 30 Nov 2021 9:55
Reporter: Bradley Grainger (OCA) Email Updates:
Status: Verified Impact on me:
Category:Connector / NET Severity:S2 (Serious)
Version:8.0.27 OS:Windows (10)
Assigned to: CPU Architecture:Any

[27 Nov 2021 21:19] Bradley Grainger
When a query attribute and a command parameter have the exact same name, Connector/NET overwrites the value for the attribute with the value from the parameter of the same name. This prevents the value of the attribute being retrieved successfully using mysql_query_attribute_string.

It occurs whether the command is prepared or not.

How to repeat:
Use MySQL Server 8.0.26 or later, and install the query_attributes component as per https://dev.mysql.com/doc/refman/8.0/en/query-attributes.html#query-attributes-prerequisit...

Run the following C# code:

using var cmd = new MySqlCommand("select mysql_query_attribute_string('name') as attribute, @name as parameter;", connection);
cmd.Attributes.SetAttribute("name", "attribute");

cmd.Parameters.AddWithValue("name", "parameter");
// workaround: prefix the parameter name with "@"
// cmd.Parameters.AddWithValue("@name", "parameter");

// also happens when preparing the command
// cmd.Prepare();

using var reader = cmd.ExecuteReader();
while (reader.Read())
	// prints "parameter"; expect "attribute"
	// prints "parameter"

Suggested fix:
Connector/NET shouldn't send the names for parameters, but only attributes; it's not expected that adding parameters will also add attributes with the same name.
[30 Nov 2021 9:55] MySQL Verification Team
Hello Bradley Grainger,

Thank you for the bug report.
Verified as described.

Ashwini Patil