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();