<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.2.2" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: Why you should not use BIT columns in MySQL</title>
	<link>http://www.xaprb.com/blog/2006/04/11/bit-values-in-mysql/</link>
	<description>Stay curious!</description>
	<pubDate>Sat, 30 Aug 2008 04:21:42 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.2.2</generator>

	<item>
		<title>By: Tyrone</title>
		<link>http://www.xaprb.com/blog/2006/04/11/bit-values-in-mysql/#comment-14495</link>
		<author>Tyrone</author>
		<pubDate>Wed, 30 Apr 2008 11:47:02 +0000</pubDate>
		<guid>http://www.xaprb.com/blog/2006/04/11/bit-values-in-mysql/#comment-14495</guid>
		<description>Found your blog entry when I started getting inexplicable problems with BIT...

I found a problem using NET connector 5.0.8.1 and version MySQL version 5.1.22 (so it persists).  My problem was that data in a column defined as BIT was appearing as '1' when I selected the table with a simple select statement, but appeared as '0' when I added a LEFT JOIN to another table !!!  I have moved this column to TINYINT.  And now I need to fix a load of other columns previously defined as BIT.</description>
		<content:encoded><![CDATA[<p>Found your blog entry when I started getting inexplicable problems with BIT&#8230;</p>
<p>I found a problem using NET connector 5.0.8.1 and version MySQL version 5.1.22 (so it persists).  My problem was that data in a column defined as BIT was appearing as &#8216;1&#8242; when I selected the table with a simple select statement, but appeared as &#8216;0&#8242; when I added a LEFT JOIN to another table !!!  I have moved this column to TINYINT.  And now I need to fix a load of other columns previously defined as BIT.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: rebump</title>
		<link>http://www.xaprb.com/blog/2006/04/11/bit-values-in-mysql/#comment-14199</link>
		<author>rebump</author>
		<pubDate>Tue, 29 Jan 2008 21:41:41 +0000</pubDate>
		<guid>http://www.xaprb.com/blog/2006/04/11/bit-values-in-mysql/#comment-14199</guid>
		<description>How about using bit fields to solve search "within" search queries on the magnatude of web search engine data stores?</description>
		<content:encoded><![CDATA[<p>How about using bit fields to solve search &#8220;within&#8221; search queries on the magnatude of web search engine data stores?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Craig</title>
		<link>http://www.xaprb.com/blog/2006/04/11/bit-values-in-mysql/#comment-14130</link>
		<author>Craig</author>
		<pubDate>Mon, 07 Jan 2008 05:08:37 +0000</pubDate>
		<guid>http://www.xaprb.com/blog/2006/04/11/bit-values-in-mysql/#comment-14130</guid>
		<description>Here's another reason not to use this type in your tables:

Using the MySQL .NET connector (5.1.4), and running a SELECT query that returns a column of BIT type, I could find no valid cast to retrieve the value of the column into a variable in my C# code. I tried bool, Byte, and Int16, and it always threw the exception "The specified cast is not valid." I didn't try the larger integers, assuming they wouldn't work either.

In fact, I ran across this blog while searching for a solution to this problem.

For instance:

MySqlCommand cmd = MySqlConn.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "SELECT bitField FROM myTable";

MySqlDataReader dr = cmd.ExecuteReader();
Object ob;
while (dr.Read())
{
	if ((ob = dr[0]) != DBNull.Value)
		bool BitField = (bool)ob;
}

gave me this exception, as did making BitField a Byte and Int16 type and trying those casts. I also tried simply doing BitField = (bool)(dr["bitField"]); Same result.

Once I changed the column type to TINYINT and my code variable type to Byte, it worked fine. So thanks!

(I would submit this as a bug to MySQL, but they would just say "That's the way it was designed, therefore it's not a bug." Uh huh...)

(Consulting Webster to find out whether "cat" is synonymous with "feline"... or is this a trick question?)</description>
		<content:encoded><![CDATA[<p>Here&#8217;s another reason not to use this type in your tables:</p>
<p>Using the MySQL .NET connector (5.1.4), and running a SELECT query that returns a column of BIT type, I could find no valid cast to retrieve the value of the column into a variable in my C# code. I tried bool, Byte, and Int16, and it always threw the exception &#8220;The specified cast is not valid.&#8221; I didn&#8217;t try the larger integers, assuming they wouldn&#8217;t work either.</p>
<p>In fact, I ran across this blog while searching for a solution to this problem.</p>
<p>For instance:</p>
<p>MySqlCommand cmd = MySqlConn.CreateCommand();<br />
cmd.CommandType = CommandType.Text;<br />
cmd.CommandText = &#8220;SELECT bitField FROM myTable&#8221;;</p>
<p>MySqlDataReader dr = cmd.ExecuteReader();<br />
Object ob;<br />
while (dr.Read())<br />
{<br />
	if ((ob = dr[0]) != DBNull.Value)<br />
		bool BitField = (bool)ob;<br />
}</p>
<p>gave me this exception, as did making BitField a Byte and Int16 type and trying those casts. I also tried simply doing BitField = (bool)(dr[&#8221;bitField&#8221;]); Same result.</p>
<p>Once I changed the column type to TINYINT and my code variable type to Byte, it worked fine. So thanks!</p>
<p>(I would submit this as a bug to MySQL, but they would just say &#8220;That&#8217;s the way it was designed, therefore it&#8217;s not a bug.&#8221; Uh huh&#8230;)</p>
<p>(Consulting Webster to find out whether &#8220;cat&#8221; is synonymous with &#8220;feline&#8221;&#8230; or is this a trick question?)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dream blog &#187; Blog Archive &#187; Roaming the RDBMS world</title>
		<link>http://www.xaprb.com/blog/2006/04/11/bit-values-in-mysql/#comment-11786</link>
		<author>Dream blog &#187; Blog Archive &#187; Roaming the RDBMS world</author>
		<pubDate>Thu, 21 Jun 2007 15:04:49 +0000</pubDate>
		<guid>http://www.xaprb.com/blog/2006/04/11/bit-values-in-mysql/#comment-11786</guid>
		<description>[...] Yet another difference between MySQL and SQL Server concerning small details, as described in here. [...]</description>
		<content:encoded><![CDATA[<p>[&#8230;] Yet another difference between MySQL and SQL Server concerning small details, as described in here. [&#8230;]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ioannis cherouvim &#187; Blog Archive &#187; Overcoming the MySQL BIT datatype problems with hibernate</title>
		<link>http://www.xaprb.com/blog/2006/04/11/bit-values-in-mysql/#comment-11623</link>
		<author>ioannis cherouvim &#187; Blog Archive &#187; Overcoming the MySQL BIT datatype problems with hibernate</author>
		<pubDate>Fri, 15 Jun 2007 18:38:49 +0000</pubDate>
		<guid>http://www.xaprb.com/blog/2006/04/11/bit-values-in-mysql/#comment-11623</guid>
		<description>[...] far so good&#8230; &#8230;until you read the blog post called &#8220;Why you should not use BIT columns in MySQL&#8221; by Xaprb. Another serious deficiency is the fact that a database dump will not export bit data as [...]</description>
		<content:encoded><![CDATA[<p>[&#8230;] far so good&#8230; &#8230;until you read the blog post called &#8220;Why you should not use BIT columns in MySQL&#8221; by Xaprb. Another serious deficiency is the fact that a database dump will not export bit data as [&#8230;]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ole V. Villumsen</title>
		<link>http://www.xaprb.com/blog/2006/04/11/bit-values-in-mysql/#comment-4937</link>
		<author>Ole V. Villumsen</author>
		<pubDate>Mon, 12 Mar 2007 13:46:17 +0000</pubDate>
		<guid>http://www.xaprb.com/blog/2006/04/11/bit-values-in-mysql/#comment-4937</guid>
		<description>&lt;p&gt;MySQL Administrator 1.1.9 for Windows exports my bit(1) fields as strings when executing a backup, for example '\0' (our server version is Server version 5.0.24a-max and the table in question has ENGINE=ndbcluster).&lt;/p&gt;</description>
		<content:encoded><![CDATA[<p>MySQL Administrator 1.1.9 for Windows exports my bit(1) fields as strings when executing a backup, for example &#8216;\0&#8242; (our server version is Server version 5.0.24a-max and the table in question has ENGINE=ndbcluster).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Someone who generally doesn't comment on blogs</title>
		<link>http://www.xaprb.com/blog/2006/04/11/bit-values-in-mysql/#comment-2360</link>
		<author>Someone who generally doesn't comment on blogs</author>
		<pubDate>Fri, 03 Nov 2006 18:34:02 +0000</pubDate>
		<guid>http://www.xaprb.com/blog/2006/04/11/bit-values-in-mysql/#comment-2360</guid>
		<description>&lt;p&gt;Your previous employer is probably the one who should read this...&lt;/p&gt;

&lt;p&gt;I hope he/she loves bitmasks because they truly provide a necessary performance or storage advantage.&lt;/p&gt;

&lt;p&gt;...As opposed to bad reasons for loving them, e.g.:&lt;/p&gt;

&lt;ul&gt;
	&lt;li&gt;They are nifty (which they are, no doubt!)&lt;/li&gt;
	&lt;li&gt;They are a vestige of an old architecture from the days when storage and CPU cycles were not so cheap.&lt;/li&gt;
	&lt;li&gt;They are a vestige of an old mentality from the days when storage and CPU cycles were not so cheap.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In a general sense, here in "modern times", I think individually named columns/variables are a superior solution.  I think in the vast majority of cases, the potential performance and storage gains of bitmasks are at least negated, if not outweighed, by the readability -- and thus maintainability -- difficulties they pose.  (I mean ... if simple magic numbers are bad, then these, which are essentially compound magic numbers, must be compound bad!)&lt;/p&gt;

&lt;p&gt;Just one man's considered opinion...&lt;/p&gt;

&lt;p&gt;Now off to convert all my BIT columns to TINYINTs!&lt;/p&gt;</description>
		<content:encoded><![CDATA[<p>Your previous employer is probably the one who should read this&#8230;</p>
<p>I hope he/she loves bitmasks because they truly provide a necessary performance or storage advantage.</p>
<p>&#8230;As opposed to bad reasons for loving them, e.g.:</p>
<ul>
<li>They are nifty (which they are, no doubt!)</li>
<li>They are a vestige of an old architecture from the days when storage and CPU cycles were not so cheap.</li>
<li>They are a vestige of an old mentality from the days when storage and CPU cycles were not so cheap.</li>
</ul>
<p>In a general sense, here in &#8220;modern times&#8221;, I think individually named columns/variables are a superior solution.  I think in the vast majority of cases, the potential performance and storage gains of bitmasks are at least negated, if not outweighed, by the readability &#8212; and thus maintainability &#8212; difficulties they pose.  (I mean &#8230; if simple magic numbers are bad, then these, which are essentially compound magic numbers, must be compound bad!)</p>
<p>Just one man&#8217;s considered opinion&#8230;</p>
<p>Now off to convert all my BIT columns to TINYINTs!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: One Geeks Opinion &#187; Why you should not use BIT columns in MySQL - Xaprb</title>
		<link>http://www.xaprb.com/blog/2006/04/11/bit-values-in-mysql/#comment-2084</link>
		<author>One Geeks Opinion &#187; Why you should not use BIT columns in MySQL - Xaprb</author>
		<pubDate>Wed, 04 Oct 2006 02:21:52 +0000</pubDate>
		<guid>http://www.xaprb.com/blog/2006/04/11/bit-values-in-mysql/#comment-2084</guid>
		<description>&lt;p&gt;[...] I found this article that explains how it works, and that you should avoid it. Why you should not use BIT columns in MySQL - Xaprb Why you should not use BIT columns in MySQL [...]&lt;/p&gt;</description>
		<content:encoded><![CDATA[<p>[&#8230;] I found this article that explains how it works, and that you should avoid it. Why you should not use BIT columns in MySQL - Xaprb Why you should not use BIT columns in MySQL [&#8230;]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Marek</title>
		<link>http://www.xaprb.com/blog/2006/04/11/bit-values-in-mysql/#comment-416</link>
		<author>Marek</author>
		<pubDate>Fri, 12 May 2006 18:36:54 +0000</pubDate>
		<guid>http://www.xaprb.com/blog/2006/04/11/bit-values-in-mysql/#comment-416</guid>
		<description>&lt;p&gt;Good article, thanks.  Saved me time.&lt;/p&gt;

&lt;p&gt;For ColdFusion Users: an updated MySQL Connector/J allows ColdFusion to connect to MySQL 5, but does not seem to play well with these new MySQL BIT fields (at least as of now).  Using TINYINT instead of BIT seems to be the best work-around.&lt;/p&gt;</description>
		<content:encoded><![CDATA[<p>Good article, thanks.  Saved me time.</p>
<p>For ColdFusion Users: an updated MySQL Connector/J allows ColdFusion to connect to MySQL 5, but does not seem to play well with these new MySQL BIT fields (at least as of now).  Using TINYINT instead of BIT seems to be the best work-around.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
