Bug #81323 select statement separaterd by newlines cause syntax error
Submitted: 5 May 2016 11:36 Modified: 5 May 2016 12:15
Reporter: Jiří Novák Email Updates:
Status: Duplicate Impact on me:
None 
Category:Connector / NET Severity:S3 (Non-critical)
Version:6.9.8.0 OS:Windows
Assigned to: CPU Architecture:Any

[5 May 2016 11:36] Jiří Novák
Description:
If I have a multiline select statement where each word is on a new line, ExecuteReader() on MySqlCommand throws MySqlException with syntax error:

An unhandled exception of type 'MySql.Data.MySqlClient.MySqlException' occurred in MySql.Data.dll

Additional information: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT

count(*)

FROM

TestDB.MyTab' at line 1

Stack Trace:
   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.ExecuteReader()
   at MySQLConnect.Program.Main(String[] args) in C:\Users\jnovak\Documents\ProgrammingTasks\MySQLConnect\MySQLConnect\Program.cs:line 20
   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()

Example of wrong CommandText:
"SELECT\ncount(*)\nFROM\nTestDB.MyTab"

If I put space character between random two words the exception disappears.

Some examples of select statement without error:
"SELECT\n count(*)\nFROM\nTestDB.MyTab" or
"SELECT\ncount(*)\nFROM\n TestDB.MyTab" or
"SELECT\ncount(*) \nFROM\nTestDB.MyTab"

How to repeat:
Example of simple C# code which always throws exception:
static void Main(string[] args)
    {
      MySqlConnection conn = new MySqlConnection("user id=root;connectiontimeout=15;pooling=False;interactivesession=True;treattinyasboolean=False;allowuservariables=True;functionsreturnstring=True;oldguids=False;server=127.0.0.1;port=15360;protocol=Socket");
      try
      {
        MySqlCommand cmd = conn.CreateCommand();
        cmd.CommandText = "SELECT\ncount(*)\nFROM\nTestDB.MyTab";
        conn.Open();
        cmd.ExecuteReader();
      }
      catch (Exception ex)
      {
        Console.WriteLine(ex.Message);
      }
      finally
      {
        if (conn != null && conn.State == System.Data.ConnectionState.Open)
          conn.Close();
      }
    }
[5 May 2016 12:14] Chiranjeevi Battula
Hello Jiří Novák,

Thank you for the bug report.
This is most likely duplicate of Bug #78760, please see Bug #78760.

Thanks,
Chiranjeevi.