<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Intelligrape  Groovy &#38; Grails Blogs &#187; Enum in mysql</title>
	<atom:link href="http://www.intelligrape.com/blog/tag/enum-in-mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.intelligrape.com/blog</link>
	<description></description>
	<lastBuildDate>Thu, 02 Feb 2012 07:48:06 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<image>
			<title>Intelligrape  Groovy &amp; Grails Blogs</title>
			<url>http://www.intelligrape.com/blog/wp-content/uploads/2011/05/favicon2.ico</url>
			<link>http://www.intelligrape.com/blog</link>
			<width></width>
			<height></height>
			<description></description>
		</image>		<item>
		<title>Enum datatype in mysql</title>
		<link>http://www.intelligrape.com/blog/2010/07/23/enum-datatype-in-mysql/</link>
		<comments>http://www.intelligrape.com/blog/2010/07/23/enum-datatype-in-mysql/#comments</comments>
		<pubDate>Fri, 23 Jul 2010 07:14:10 +0000</pubDate>
		<dc:creator>Uday Pratap Singh</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Enum in mysql]]></category>
		<category><![CDATA[Java enums with sql]]></category>
		<category><![CDATA[sql modes]]></category>
		<category><![CDATA[strict values in sql]]></category>

		<guid isPermaLink="false">http://www.intelligrape.com/blog/?p=1383</guid>
		<description><![CDATA[Recently in a Grails project that I am currently working on, the client wanted to have few functionalities of our web application on iPhone as well. We are using Enums heavily in our project and the iPhone development cannot recognize from looking at the tables that few fields are Enums so those need to be [...]]]></description>
			<content:encoded><![CDATA[<p>Recently in a Grails project that I am currently working on, the client wanted to have few functionalities of our web application on iPhone as well. We are using Enums heavily in our project and the iPhone development cannot recognize from looking at the tables that few fields are Enums so those need to be one of value of Enum. So they use to store some different value in it as the datatype of Enums in table is varchar the sql doesn&#8217;t mind storing the different values.</p>
<p>So after looking at here and there for Enum datatypes for sql we found a very easy solution to do that. We altered few tables like this</p>

<div class="wp_syntax"><div class="code"><pre class="groovy">alter table documents change document_priority document_priority <span style="color: #000000; font-weight: bold;">enum</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Critical'</span>,<span style="color: #ff0000;">'Major'</span>,<span style="color: #ff0000;">'Blocker'</span>,<span style="color: #ff0000;">'Backlog'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #000000; font-weight: bold;">default</span> <span style="color: #ff0000;">'Major'</span><span style="color: #66cc66;">;</span></pre></div></div>

<p>For adding an Enum column you just need to do something like</p>

<div class="wp_syntax"><div class="code"><pre class="groovy">alter table documents add column <span style="color: #000000; font-weight: bold;">enum</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Critical'</span>,<span style="color: #ff0000;">'Major'</span>,<span style="color: #ff0000;">'Blocker'</span>,<span style="color: #ff0000;">'Backlog'</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>after doing this the user can see that which values the field expect so iPhone development team also get to know what should they do. But it does not restrict user to other values in it though if user tries to add some other value in it the sql will set it to blank(&#8221; &#8220;). It still doesn&#8217;t serves our purpose because in application there is no blank Enum. The solution for this is in the sql_mode. So we set the sql_mode</p>

<div class="wp_syntax"><div class="code"><pre class="groovy">SET sql_mode <span style="color: #66cc66;">=</span> STRICT_TRANS_TABLES</pre></div></div>

<p>So can see the sql_mode of your database like this</p>

<div class="wp_syntax"><div class="code"><pre class="groovy">SELECT @@global.<span style="color: #006600;">sql_mode</span>, @@session.<span style="color: #006600;">sql_mode</span><span style="color: #66cc66;">;</span></pre></div></div>

<p>I hope this helped for some people the only thing I miss in this. I dont get the solution for this in Hibernate. May be there is a solution for this either in Hibernate or in Grails. Looking for the better solution that can be done in the application itself.<br />
Hope it helps<br />
## Uday Pratap Singh ##<br />
uday@intelligrape.com</p>
<p><a href="http://www.IntelliGrape.com/">http://www.IntelliGrape.com/</a><br />
<a href="http://in.linkedin.com/in/meudaypratap">http://in.linkedin.com/in/meudaypratap</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.intelligrape.com/blog/2010/07/23/enum-datatype-in-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

