Bug #43222 Exception in C/NET when calling stored procedure with BINARY(16) parameter

Submitted: 26 Feb 2009 11:00 Modified: 24 Mar 2009 5:25
Reporter: Bogdan Degtyariov Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / NET Severity:S2 (Serious)
Version:5.3 OS:Any
Assigned to: Bogdan Degtyariov CPU Architecture:Any
Tags: BINARY, Guid, stored procedure

[26 Feb 2009 11:00] Bogdan Degtyariov
Description:
Connector/NET 5.3 throws an exception when trying to parse BINARY(16) parameters names and types from CREATE PROCEDURE results.

Setting "Use Procedure Bodies=False" fixes the situation, but querying Information_Schema database has negative impact on the performance.

How to repeat:
private void button2_Click(object sender, EventArgs e)
{
    MySqlConnection con = new MySqlConnection();
    try
    {
        con.ConnectionString = "server=localhost;database=test;user id=root;pwd=;";
        con.Open();

        MySqlCommand cmd = new MySqlCommand();
        cmd.Connection = con;

        cmd.CommandType = CommandType.Text;

#region create statements
        cmd.CommandText = "DROP TABLE IF EXISTS project_details;";
        cmd.ExecuteNonQuery();

        cmd.CommandText = "CREATE TABLE IF NOT EXISTS `project_details`" +
                          "(" +
                          "`identity_guid` BINARY(16) NOT NULL Default " +
                          "0x00000000000000000000000000000000," +
                          "PRIMARY KEY (`identity_guid`)" +
                          ")" +
                          "ENGINE=InnoDB;";
        cmd.ExecuteNonQuery();

        cmd.CommandText = "DROP PROCEDURE IF EXISTS sp_insert_project_details;" ;
        cmd.ExecuteNonQuery();

        cmd.CommandText = "CREATE PROCEDURE sp_insert_project_details" +
                          "(" +
                          "IN identity_guid BINARY(16)" +
                          ")" +
                          "BEGIN\n" +
                          "INSERT INTO `project_details`" +
                          "(" +
                          "identity_guid" +
                          ")" +
                          "VALUES" +
                          "(" +
                          "identity_guid" +
                          ");\n" +
                          "END";
        cmd.ExecuteNonQuery();
#endregion

        cmd.CommandType = CommandType.StoredProcedure;
        cmd.CommandText = "sp_insert_project_details";
        Guid identity_guid = new Guid("11223344-5566-7788-99AA-BBCCDDEEFF00");

        cmd.Parameters.Add("?identity_guid", MySqlDbType.Guid);
        cmd.Parameters[0].Value = identity_guid;

        cmd.ExecuteNonQuery();
        MessageBox.Show("DONE!");

    }
    catch (Exception ex)
    {
        string error = ex.Message.ToString();
        error+= ex.StackTrace;
        MessageBox.Show(error);
    }
    finally
    {
        if (con != null)
            con.Close();
    }
}

Suggested fix:
Index: MySql.Data/Provider/Source/ISSchemaProvider.cs
===================================================================
--- MySql.Data/Provider/Source/ISSchemaProvider.cs	(revision 1503)
+++ MySql.Data/Provider/Source/ISSchemaProvider.cs	(working copy)
@@ -606,7 +606,8 @@
                     row["CHARACTER_SET_NAME"].ToString(), connection);
 
             // now set the octet length
-            if (row["CHARACTER_MAXIMUM_LENGTH"] != DBNull.Value)
+            if (row["CHARACTER_MAXIMUM_LENGTH"] != DBNull.Value &&
+                row["CHARACTER_SET_NAME"].ToString().Length > 0)
                 row["CHARACTER_OCTET_LENGTH"] =
                     CharSetMap.GetMaxLength(row["CHARACTER_SET_NAME"].ToString(), connection) *
                     (int)row["CHARACTER_MAXIMUM_LENGTH"];
[24 Mar 2009 5:25] Bogdan Degtyariov
This issue has been fixed in Connector/NET version 6.0

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.050 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.