Bug #91753 Unnamed parameter not supported by MySqlCommand.Prepare
Submitted: 22 Jul 2018 4:11 Modified: 22 Jul 2018 14:16
Reporter: Bradley Grainger (OCA) Email Updates:
Status: Verified Impact on me:
None 
Category:Connector / NET Severity:S2 (Serious)
Version:8.0.11 OS:Microsoft Windows (10.0.17134.167)
Assigned to: CPU Architecture:Any (x64)

[22 Jul 2018 4:11] Bradley Grainger
Description:
MySqlCommand supports using unnamed (i.e., positional) parameters by using ? in the query. However, if MySqlCommand.Prepare() is called, using a ? parameter throws a MySqlException "Incorrect arguments to mysqld_stmt_execute".
   at MySql.Data.MySqlClient.MySqlStream.ReadPacket()
   at MySql.Data.MySqlClient.NativeDriver.GetResult(Int32& affectedRow, Int64& insertedId)
   at MySql.Data.MySqlClient.Driver.GetResult(Int32 statementId, Int32& affectedRows, Int64& insertedId)
   at MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId, Boolean force)
   at MySql.Data.MySqlClient.MySqlDataReader.NextResult()
   at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
   at MySql.Data.MySqlClient.MySqlCommand.ExecuteNonQuery()

The command should succeed whether or not MySqlCommand.Prepare() is called.

How to repeat:
Run the following C# code:

// NOTE: MUST have IgnorePrepare=false in connection string
using (var connection = new MySqlConnection("...;IgnorePrepare=false"))
{
	connection.Open();
	using (var command = new MySqlCommand(@"
DROP TABLE IF EXISTS test;
CREATE TABLE test(value INT NOT NULL);
", connection))
		command.ExecuteNonQuery();

	using (var command = new MySqlCommand(@"INSERT INTO test VALUES(?);", connection))
	{
		command.Parameters.Add(new MySqlParameter { Value = 1 });

		// *** this causes the bug ***
		command.Prepare();

		// this throws the exception
		command.ExecuteNonQuery();
	}
}

A simpler example is changing the command to "SELECT ?" and using command.ExecuteScalar();
[22 Jul 2018 14:16] Umesh Shastry
Hello Bradley,

Thank you for the report and feedback.

Thanks,
Umesh