Is saving blob data concerned with charset?
Posted by: Yao Yao
Date: December 04, 2010 10:34PM

Hi all:

I use .Net Connector to saving blob data to database, and I found that when saving blob data, some data was translated, so the saved data is not what I expected.
And then I found the problem related with the charset. When I use charset latin1 instead of gbk, the data was saved correctly.

Here is my test sample:

    static void Main( string[] args )
    {
        string connectionString = "Server=localhost;Port=3306;Database=test;Uid=root;Pwd=;";

        MySqlConnection connection = null;

        try
        {
            connection = new MySqlConnection( connectionString );
            connection.Open( );

            MySqlCommand cmd = connection.CreateCommand( );

            MySqlCommand updateCmd = connection.CreateCommand( );
            updateCmd.CommandType = CommandType.Text;
            updateCmd.CommandText = string.Format( "INSERT INTO test.t1( xxx ) VALUES( ?xxx )" );

            byte[] blobData = new byte[2];
            blobData[0] = ( byte )131;
            blobData[1] = ( byte )0;

            MySqlParameter param = new MySqlParameter( "?xxx", MySqlDbType.Blob );
            param.Value = blobData;

            updateCmd.Parameters.Add( param );

            updateCmd.ExecuteNonQuery( );
        }
        finally
        {
            if( connection.State != ConnectionState.Closed )
                connection.Close( );
        }
    }


  CREATE TABLE `t1` (
    `Id` int(11) NOT NULL AUTO_INCREMENT,
    `xxx` blob,
    PRIMARY KEY (`Id`)
  ) ENGINE=InnoDB DEFAULT CHARSET=gbk;

MySQL 5.1.53-community ( Windows XP ) / .Net Connector 5.1.7.0

Also I found when the byte data between 129 and 245, a transition will be done. But why it happened on blob column? Is there someone can guide me? Thanks in advance.

Options: ReplyQuote


Subject
Views
Written By
Posted
Is saving blob data concerned with charset?
4308
December 04, 2010 10:34PM


Sorry, you can't reply to this topic. It has been closed.

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.