I created a program in C# to copy a MySql database structure and procedures to a newly created database. Then upload the new data to it. The problem it fails to upload procedures that include the '@' symbol in them, example:
SET @SEARCH := CONCAT( _SEARCH , '%');
The code I use to retrieve the procedures is:
cmd = new MySqlCommand("SELECT CONCAT( 'CREATE PROCEDURE ', ISR.ROUTINE_NAME, '(', CASE WHEN ISP.PARAMETER_NAME IS NOT NULL THEN GROUP_CONCAT(CONCAT(ISP.PARAMETER_MODE, ' ', ISP.PARAMETER_NAME, ' ', ISP.DTD_IDENTIFIER)) ELSE '' END, ')\n', ISR.ROUTINE_DEFINITION) AS Create_Procedure FROM INFORMATION_SCHEMA.ROUTINES ISR LEFT JOIN INFORMATION_SCHEMA.PARAMETERS ISP ON ISR.ROUTINE_SCHEMA = ISP.SPECIFIC_SCHEMA AND ISR.ROUTINE_NAME = ISP.SPECIFIC_NAME AND ISR.ROUTINE_TYPE = ISP.ROUTINE_TYPE WHERE ROUTINE_SCHEMA = '" + Program.RemoteSource + "' GROUP BY ISR.ROUTINE_NAME;", remote);
using (MySqlDataReader dataReader = cmd.ExecuteReader())
{
while (dataReader.Read())
{
createProcedures.Add(dataReader.GetString(0));
}
};
and the following uploads the new create procedure statements to the new database:
counter = 0;
foreach (string procedure in createProcedures)
{
try
{
cmd = new MySqlCommand(@procedure, remote);
cmd.ExecuteNonQuery();
counter++;
Console.Write("\rProcedures Created: " + counter + " of " + createProcedures.Count);
}
catch (MySqlException ex)
{
Console.WriteLine("Error: {0}", ex.ToString());
}
}
and the error:
Error: MySql.Data.MySqlClient.MySqlException (0x800040005):
Fatal error encountered during command execution. --->
MySql.Data.MySqlClient.MySqlException (0x800040005):
Parameter '@SEARCH' must be defined.
How would I go about so that MySql.Data ignores the @ symbol?