Description:
I get the following exception when running a MySqlScripts on Linux with Delimiter:
Error Message:
MySql.Data.MySqlClient.MySqlException : You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '§' at line 1
Stack Trace:
at MySql.Data.MySqlClient.MySqlStream.ReadPacket() in /opt/buildagent/temp/buildTmp/TXS.Analytics/MySQL.Data/src/MySqlStream.cs:line 161
at MySql.Data.MySqlClient.NativeDriver.GetResult(Int32& affectedRow, Int64& insertedId) in /opt/buildagent/temp/buildTmp/TXS.Analytics/MySQL.Data/src/NativeDriver.cs:line 482
at MySql.Data.MySqlClient.Driver.GetResult(Int32 statementId, Int32& affectedRows, Int64& insertedId) in /opt/buildagent/temp/buildTmp/TXS.Analytics/MySQL.Data/src/Driver.cs:line 400
at MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId, Boolean force) in /opt/buildagent/temp/buildTmp/TXS.Analytics/MySQL.Data/src/Driver.cs:line 389
at MySql.Data.MySqlClient.MySqlDataReader.NextResult() in /opt/buildagent/temp/buildTmp/TXS.Analytics/MySQL.Data/src/datareader.cs:line 849
at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior) in /opt/buildagent/temp/buildTmp/TXS.Analytics/MySQL.Data/src/command.cs:line 486
at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader() in /opt/buildagent/temp/buildTmp/TXS.Analytics/MySQL.Data/src/command.cs:line 378
at MySql.Data.MySqlClient.MySqlCommand.ExecuteNonQuery() in /opt/buildagent/temp/buildTmp/TXS.Analytics/MySQL.Data/src/command.cs:line 320
at MySql.Data.MySqlClient.MySqlScript.Execute() in /opt/buildagent/temp/buildTmp/TXS.Analytics/MySQL.Data/src/MySqlScript.cs:line 180
at TXS.Analytics.BackupRestore.Test.BackupRestoreTest.SqlTest() in /opt/buildagent/temp/buildTmp/TXS.Analytics/TXS.Analytics.BackupRestore.Test/BackupRestoreTest.cs:line 62
The problem is that the delimiter is not correctly removed from the query before it is executed on the server.
The following query is sent to the Mysql server:
"CREATE OR REPLACE FUNCTION 'Test'() RETURNS int(11)
DETERMINISTIC
RETURN 8081; §" <--The last character is too much
The problem seems to be the calculation of the endPos in line 299 in MySqlScript.cs.
endPos++; <-- on Linux makes sure that the last character is included in the query.
This may be due to line breaks. Under Windows \r\n and under Linux only \n.
Translated with www.DeepL.com/Translator (free version)
How to repeat:
The following test throws an exception on Linux systems.
[Fact]
public void SqlTest()
{
MySqlConnection con = new MySqlConnection("Server=XXX;Port=3306;Database=XXX;Uid=XXX;Pwd=XXX; ");
StringBuilder sb = new StringBuilder();
sb.AppendLine("CREATE OR REPLACE FUNCTION `Test`() RETURNS int(11)");
sb.AppendLine("DETERMINISTIC");
sb.AppendLine("RETURN 8081; §§§");
MySqlScript script = new MySqlScript(con);
script.Delimiter = "§§§";
script.Query = sb.ToString();
script.Execute();
}