Description:
The connector is able to connect to the database and execute insert and delete statements on the database but crashes when attempting to run "Select" Sql queries on BigEndian Client machines.
How to repeat:
static void Main(string[] args){
string MyConString = "SERVER=localhost; " +
"Database=TestDB; " +
"Uid=root;" +
"Pwd=;";
MySqlConnection Connection = new MySqlConnection(MyConString);
Connection.Open();
Console.WriteLine("Writing to the Database");
string inQuery = "INSERT INTO Persons VALUES (103, \"ABC\", \"DEF\", \"xyz road\", \"pqr city\")";
MySqlCommand CommandIn = new MySqlCommand(inQuery, Connection);
CommandIn.ExecuteNonQuery();
CommandIn.Dispose();
PrintTable(Connection, "Persons");
string updateQuery = "UPDATE Persons SET LastName='Potato' WHERE PersonID=103";
MySqlCommand CommandUpdate = new MySqlCommand(updateQuery, Connection);
CommandUpdate.ExecuteNonQuery();
CommandUpdate.Dispose();
PrintTable(Connection, "Persons");
string deleteQuery = "DELETE FROM Persons Where PersonID=103";
MySqlCommand CommandDelete = new MySqlCommand(deleteQuery, Connection);
CommandDelete.ExecuteNonQuery();
CommandDelete.Dispose();
PrintTable(Connection, "Persons");
Connection.Close();
}
Expected Output:
Writing to the Database
:PersonID:FirstName:LastName:Street:City:
:103:ABC:DEF:xyz road:pqr city:
:PersonID:FirstName:LastName:Street:City:
:103:ABC:Potato:xyz road:pqr city:
Error seen on the s390x Machine:
Unhandled Exception:
System.Collections.Generic.KeyNotFoundException: The given key '57344' was not present in the dictionary.
at System.Collections.Generic.Dictionary`2[[System.Int32, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.String, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].get_Item(Int32 key)
at MySql.Data.MySqlClient.MySqlField.SetFieldEncoding()
at MySql.Data.MySqlClient.MySqlField.set_CharacterSetIndex(Int32 value)
at MySql.Data.MySqlClient.NativeDriver.GetColumnData(MySqlField field)
at MySql.Data.MySqlClient.NativeDriver.GetColumnsData(MySqlField[] columns)
at MySql.Data.MySqlClient.Driver.GetColumns(Int32 count)
at MySql.Data.MySqlClient.ResultSet.LoadColumns(Int32 numCols)
at MySql.Data.MySqlClient.ResultSet..ctor(Driver d, Int32 statementId, Int32 numCols)
at MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId, Boolean force)
at MySql.Data.MySqlClient.MySqlDataReader.NextResult()
at MySql.Data.MySqlClient.MySqlDataReader.Close()
at MySql.Data.MySqlClient.MySqlCommand.ResetReader()
at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader()
at ConsoleApplication.Program.PrintTable(MySqlConnection Connection, String tableName) in /home/manas/Workspace/MySqlADO/Program.cs:line 15
at ConsoleApplication.Program.Main(String[] args) in /home/manas/Workspace/MySqlADO/Program.cs:line 57
Suggested fix:
The error seems to stem from the use of BitConverters throughout the code, the BitConverter class checks the endianness of the underlying system and does data serialization accordingly which leads to incorrect reads on incoming little endian data from the server.
Description: The connector is able to connect to the database and execute insert and delete statements on the database but crashes when attempting to run "Select" Sql queries on BigEndian Client machines. How to repeat: static void Main(string[] args){ string MyConString = "SERVER=localhost; " + "Database=TestDB; " + "Uid=root;" + "Pwd=;"; MySqlConnection Connection = new MySqlConnection(MyConString); Connection.Open(); Console.WriteLine("Writing to the Database"); string inQuery = "INSERT INTO Persons VALUES (103, \"ABC\", \"DEF\", \"xyz road\", \"pqr city\")"; MySqlCommand CommandIn = new MySqlCommand(inQuery, Connection); CommandIn.ExecuteNonQuery(); CommandIn.Dispose(); PrintTable(Connection, "Persons"); string updateQuery = "UPDATE Persons SET LastName='Potato' WHERE PersonID=103"; MySqlCommand CommandUpdate = new MySqlCommand(updateQuery, Connection); CommandUpdate.ExecuteNonQuery(); CommandUpdate.Dispose(); PrintTable(Connection, "Persons"); string deleteQuery = "DELETE FROM Persons Where PersonID=103"; MySqlCommand CommandDelete = new MySqlCommand(deleteQuery, Connection); CommandDelete.ExecuteNonQuery(); CommandDelete.Dispose(); PrintTable(Connection, "Persons"); Connection.Close(); } Expected Output: Writing to the Database :PersonID:FirstName:LastName:Street:City: :103:ABC:DEF:xyz road:pqr city: :PersonID:FirstName:LastName:Street:City: :103:ABC:Potato:xyz road:pqr city: Error seen on the s390x Machine: Unhandled Exception: System.Collections.Generic.KeyNotFoundException: The given key '57344' was not present in the dictionary. at System.Collections.Generic.Dictionary`2[[System.Int32, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.String, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].get_Item(Int32 key) at MySql.Data.MySqlClient.MySqlField.SetFieldEncoding() at MySql.Data.MySqlClient.MySqlField.set_CharacterSetIndex(Int32 value) at MySql.Data.MySqlClient.NativeDriver.GetColumnData(MySqlField field) at MySql.Data.MySqlClient.NativeDriver.GetColumnsData(MySqlField[] columns) at MySql.Data.MySqlClient.Driver.GetColumns(Int32 count) at MySql.Data.MySqlClient.ResultSet.LoadColumns(Int32 numCols) at MySql.Data.MySqlClient.ResultSet..ctor(Driver d, Int32 statementId, Int32 numCols) at MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId, Boolean force) at MySql.Data.MySqlClient.MySqlDataReader.NextResult() at MySql.Data.MySqlClient.MySqlDataReader.Close() at MySql.Data.MySqlClient.MySqlCommand.ResetReader() at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior) at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader() at ConsoleApplication.Program.PrintTable(MySqlConnection Connection, String tableName) in /home/manas/Workspace/MySqlADO/Program.cs:line 15 at ConsoleApplication.Program.Main(String[] args) in /home/manas/Workspace/MySqlADO/Program.cs:line 57 Suggested fix: The error seems to stem from the use of BitConverters throughout the code, the BitConverter class checks the endianness of the underlying system and does data serialization accordingly which leads to incorrect reads on incoming little endian data from the server.