[Mono-list] MySqlDataAdapter.Fill uses strings for binary columns - any help? Are Binary Guids doable?

Pxtl martin.zarate at gmail.com
Tue Nov 11 22:45:10 EST 2008

Found a partial fix - the latest version of MySql.Data is sufficiently
compatible with Mono 1.9.1

However, it does have one problem - without converting to byte array (that
is, changing Guid.NewGuid().ToByteArray() to Guid.NewGuid() results in the
guid being stored incorrectly.  If you run a unit test to check of the data
coming back matches the data sent in, it will fail.

So I have a solution, but with the current framework it could produce a
horrifying hidden failure for those who don't know about this flaw.

Caveat emptor.

Pxtl wrote:
> I'm just getting started with Mono/MySQL and I'm hitting a wall with using
> Guids.
> The following code demonstrates the problem:
> 		MySqlConnection conn = new
> MySqlConnection(@"Server=localhost;Database=qa;uid=asp_net;pwd=password;");
> 		conn.Open();
> 		using(MySqlCommand cmd = new MySqlCommand(@"
> delete from service_types;
> insert into service_types(id, name) values(?id, 'test');", conn))
> 		{
> 			cmd.Parameters.AddWithValue("?id", Guid.NewGuid().ToByteArray());
> 			cmd.ExecuteNonQuery();
> 		}
> 		using(MySqlCommand cmd = new MySqlCommand(@"
> select * from service_types", conn))
> 		{
> 			MySqlDataAdapter ad = new MySqlDataAdapter(cmd);
> 			DataTable res = new DataTable();
> 			ad.Fill(res);
> 			entryPopulate.Text = res.Rows[0]["id"].GetType().ToString();
> 		}
> "id" is a Binary(16) column, as is recommended for storing Guids.
> The problem: while the Guid goes into the database just fine, it comes
> back as a "System.String".  This makes it impossible to fetch any binary
> data - particularly guids - out of the database.  I've tried it with the
> InnoDB and MyISAM storage engines, and it's always a String.
> I'm using 1.9.1, with Connector/NET 5.0.8, which is what is available in
> the Ubuntu package managers.  Is there a download for newer Connector/NET
> Mono-compatible DLLs that I could be using for my project?  So far I've
> been finding this version of Connector/NET to be barely functional - no
> MySqlDataAdapter.Update(), it doesn't work with SqlDataSource, and it
> doesn't seem to work with binary data.
> Help!

View this message in context: http://www.nabble.com/MySqlDataAdapter.Fill-uses-strings-for-binary-columns---any-help---Are-Binary-Guids-doable--tp20408334p20453641.html
Sent from the Mono - General mailing list archive at Nabble.com.

More information about the Mono-list mailing list