Menu

#1 Support for Guid

closed
nobody
None
1
2014-08-22
2003-02-13
No

If MySQLParameter.Value has a Typecode equal to
TypeCode.Object but if its type is not System.Byte[],
an empty string is inserted into the SQL statement sent
to MySQL, resulting in an error. Fair enough in the
general case, but it is not the only such type which
could be handle in a special manner. System.Guid is one
of the most obvious one in a database context. May I
propose the following change in
MySQLParameter.SerializeToBytes

case MySQLDbType.Blob:
if (m_value.GetType() == Type.GetType("System.Byte[]"))
{
s.WriteByte((byte)'\'');
EscapeByteArray( (byte[])m_value, s);
s.WriteByte((byte)'\'');
return;
}
else if(m_value.GetType() == typeof(System.Guid))
{
parm_string = "0x" + ((System.Guid)m_value).ToString("N");
}
break;

Discussion

  • Reggie Burnett

    Reggie Burnett - 2003-02-17

    Logged In: YES
    user_id=523261

    I'll see about this in a day or two. Thanks for the feature
    request

     
  • Reggie Burnett

    Reggie Burnett - 2003-02-28

    Logged In: YES
    user_id=523261

    I have implemented this as a feature. The suggested way of
    inserting a Guid into the database is to use the
    MySQLParameter where you can specify the MySQLDbType
    of VarChar. If you use the MySQLParameter ctor where you
    just specify a parm name and object, you run the risk that
    the value type doesn't match the underlying column type.

    To aid in this, I have added an additional parameter ctor that
    accepts a param name, type, and value without requiring you
    to specify parm direction, etc.

    Let me know if these changes work for you.

    Thanks for the feedback. Keep it up!

    Reggie

     
  • Reggie Burnett

    Reggie Burnett - 2003-02-28
    • priority: 5 --> 1
    • status: open --> closed
     

Log in to post a comment.

MongoDB Logo MongoDB