List:MySQL and .NET« Previous MessageNext Message »
From:Reggie Burnett Date:October 28 2004 7:08pm
Subject:RE: Only byte arrays can be serialized by MySqlBinary
View as plain text  
I have pushed a fix for this issue.  The problem is that I want MySqlString
to handle text fields of all sizes (varchar, tiny-, medium-, and longtext)
but I don't define any enum values for those types.  What I would like to do
is define a "fake" datatype named Text that would represent all extended
text types.  However, keeping MySqlBinary only handling binary values and
forcing new code to use MySqlDbType.Text for CLOB values would break a great
deal of code, so instead I have modified MySqlBinary to handle any byte[][
and string values like this.

		internal override void Serialize(PacketWriter writer, bool
binary, object ourValue, int length)
		{
			byte[] buffToWrite = null;

			if (ourValue is System.Byte[])
				buffToWrite = (byte[])ourValue;
			else if (ourValue is String) 
			{
				string s = (ourValue as string).Substring(0,
length);
				buffToWrite = writer.Encoding.GetBytes(s);
				length = buffToWrite.Length;
			}

			if ( buffToWrite == null )
				throw new MySqlException( "Only byte arrays
and strings can be serialized by MySqlBinary" );

			if (binary) 
			{
				writer.WriteLength( length );
				writer.Write( buffToWrite, 0, length );
			}
			else 
			{
				if ( writer.Version.isAtLeast(4,1,0))
					writer.WriteStringNoNull( "_binary "
);

				writer.WriteByte( (byte)'\'');
				EscapeByteArray( buffToWrite, length, writer
);
				writer.WriteByte((byte)'\'');
			}
		}


> -----Original Message-----
> From: Barry Zubel [mailto:barry@stripped]
> Sent: Thursday, October 28, 2004 9:53 AM
> To: dotnet@stripped
> Subject: RE: Only byte arrays can be serialized by MySqlBinary
> 
> Ok, appears to be the conversion of the mediumtext field (NOTES in our
> database) from a string value.
> 
> In MySqlBinary.cs, around line 61:
> 
> 		byte[] buff = (ourValue as System.Byte[]);
> 
> Looks like casting ourValue to a System.Byte[] isn't working as (I)
> expected.
> 
> Delving further.....
> 
> B.
> 
> 
> --
> MySQL on .NET Mailing List
> For list archives: http://lists.mysql.com/dotnet
> To unsubscribe:    http://lists.mysql.com/dotnet?unsub=1

Thread
DataAdapter Update and ConnectionFrank23 Nov
  • RE: MySQL Connector/Net 1.0.1 beta 2 has been released.Barry Zubel28 Oct
    • Only byte arrays can be serialized by MySqlBinaryBarry Zubel28 Oct
      • Broken CodeJoshua Mouch28 Oct
        • RE: Broken CodeBarry Zubel28 Oct
          • RE: Broken CodeDarren Hill28 Oct
            • RE: Broken CodeDarren Hill28 Oct
              • RE: Broken CodeBarry Zubel28 Oct
                • RE: Broken CodeDarren Hill28 Oct
                  • RE: Broken CodeBarry Zubel28 Oct
                    • RE: Broken CodeDarren Hill28 Oct
                    • RE: Broken CodeJoshua Mouch28 Oct
                  • RE: Broken CodeReggie Burnett28 Oct
                • RE: Broken CodeJoshua Mouch28 Oct
                  • RE: Broken CodeJoshua Mouch28 Oct
                    • RE: Broken CodeJoshua Mouch28 Oct
                      • RE: Broken CodeReggie Burnett28 Oct
      • RE: Only byte arrays can be serialized by MySqlBinaryReggie Burnett28 Oct
        • An established connection was aborted by the software in your host machineDarren Hill3 Nov
      • RE: Only byte arrays can be serialized by MySqlBinaryBarry Zubel28 Oct
        • RE: Only byte arrays can be serialized by MySqlBinaryReggie Burnett28 Oct
        • RE: Only byte arrays can be serialized by MySqlBinaryReggie Burnett28 Oct