<?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>Dave Rowe's Blog &#187; Development</title>
	<atom:link href="http://blog.roweware.com/category/development/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.roweware.com</link>
	<description>Ramblings about things I think I know...</description>
	<lastBuildDate>Wed, 14 Jul 2010 17:45:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>MySQL Query Optimizer Tweak</title>
		<link>http://blog.roweware.com/2010/07/14/mysql-query-optimizer-tweak/</link>
		<comments>http://blog.roweware.com/2010/07/14/mysql-query-optimizer-tweak/#comments</comments>
		<pubDate>Wed, 14 Jul 2010 17:40:09 +0000</pubDate>
		<dc:creator>Dave Rowe</dc:creator>
				<category><![CDATA[Database Design]]></category>
		<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://blog.roweware.com/?p=215</guid>
		<description><![CDATA[I recently encountered a situation where I had a query that was built with quite a few joins (~8), and I found that the query was taking a bit longer than I expected, especially for the number of rows to look at / return.  With each join, you add in more complexity for MySQL to [...]]]></description>
			<content:encoded><![CDATA[<p>I recently encountered a situation where I had a query that was built with quite a few joins (~8), and I found that the query was taking a bit longer than I expected, especially for the number of rows to look at / return.  With each join, you add in more complexity for MySQL to handle in how to best utilize indexes, etc.</p>
<p><span id="more-215"></span></p>
<p>I found that tweaking the &#8216;<strong>optimizer_search_depth</strong>&#8216; parameter (in my.cnf) for MySQL significantly sped up the query, as it told MySQL to only go so far in finding the best way to execute the query.</p>
<p>You can read more about it here: <a href="http://dev.mysql.com/doc/refman/5.0/en/controlling-optimizer.html" target="_blank">http://dev.mysql.com/doc/refman/5.0/en/controlling-optimizer.html</a></p>
<p>I&#8217;d recommend tweaking this variable to find the best level for your worst query.  For simple queries, they should be unaffected since MySQL doesn&#8217;t need to do much analysis on the best execution plan.  As an example, I&#8217;ve set the value to &#8217;3&#8242;, and things are just fine.</p>
<p>To determine if you need this tweak, you can login to the MySQL console while a long-running process is executing and execute &#8216;<strong>SHOW PROCESSLIST\G</strong>&#8216;.  If you see a query in &#8216;statistics&#8217; state for more than a few seconds, try tweaking the value, and re-running the process.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.roweware.com/2010/07/14/mysql-query-optimizer-tweak/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ChartDirector with PHP</title>
		<link>http://blog.roweware.com/2010/03/02/chartdirector-with-php/</link>
		<comments>http://blog.roweware.com/2010/03/02/chartdirector-with-php/#comments</comments>
		<pubDate>Tue, 02 Mar 2010 14:30:11 +0000</pubDate>
		<dc:creator>Dave Rowe</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[chartdirector]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[help]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://blog.roweware.com/?p=189</guid>
		<description><![CDATA[For a project, we have the need to create charts dynamically from data.  In another project, we&#8217;ve used ChartDirector for this.  It has worked great there, so we pulled it into this project as well.  Now, the type of charts I was working with in particular is a stacked percentage chart, which is kind of [...]]]></description>
			<content:encoded><![CDATA[<p>For a project, we have the need to create charts dynamically from data.  In another project, we&#8217;ve used <a href="http://www.advsofteng.com/">ChartDirector</a> for this.  It has worked great there, so we pulled it into this project as well.  Now, the type of charts I was working with in particular is a stacked percentage chart, which is kind of like a mash between a pie chart and a traditional bar chart.  An example:</p>
<p><a href="http://blog.roweware.com/wp-content/uploads/2010/03/percentbar.png"><img class="alignnone size-full wp-image-191" title="percentbar" src="http://blog.roweware.com/wp-content/uploads/2010/03/percentbar.png" alt="Percentage Bar" width="510" height="330" /></a></p>
<p>Now, with dynamic data, you can&#8217;t predict what your data will look like, and your code needs to be flexible enough to handle any situation without causing headaches for the user.  With ChartDirector, you pass in datasets via arrays across the chart, so for example the above datasets would be created by:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p189code3'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p1893"><td class="code" id="p189code3"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$data0</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">100</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">125</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">245</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">147</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">67</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$data1</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">85</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">156</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">179</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">211</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">123</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$data2</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">97</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">87</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">56</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">267</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">157</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Such that, the numbers line up in the arrays (vertically) in how they correspond to the resulting chart.  In my situation and test data, I found I had a situation like the following:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p189code4'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p1894"><td class="code" id="p189code4"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$data0</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">100</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">125</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">147</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">67</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$data1</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">85</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">156</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">211</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">123</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$data2</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">97</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">87</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">267</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">157</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>So, the bar for the 3rd item in the chart would be distributed equally as 33.33% when, in fact, there was no data.  I assumed the chart would display a blank spot for that bar.  After searching the less than optimal support forums (to no fault of the creators / maintainers), I found I needed to instead use a constant defined in the ChartDirector code &#8211; &#8216;NoValue&#8217;, where I had&#8230;wait for it&#8230;.no value.  Putting a small check in my code to replace zeros with &#8216;NoValue&#8217; proved to produce the results I was after.</p>
<p>Note to fellow developers: If you&#8217;re posting in a forum for assistance, please be more verbose in your subject line.  It <em>really</em> helps with searching if the subject can provide some bit of context around what the problem is.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.roweware.com/2010/03/02/chartdirector-with-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>External Login to phpBB</title>
		<link>http://blog.roweware.com/2010/01/26/external-login-to-phpbb/</link>
		<comments>http://blog.roweware.com/2010/01/26/external-login-to-phpbb/#comments</comments>
		<pubDate>Tue, 26 Jan 2010 22:29:55 +0000</pubDate>
		<dc:creator>Dave Rowe</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[phpBB]]></category>
		<category><![CDATA[single-sign-on]]></category>
		<category><![CDATA[sso]]></category>

		<guid isPermaLink="false">http://blog.roweware.com/?p=172</guid>
		<description><![CDATA[Recently, I was tasked with creating a single-sign-on solution for phpBB, where the user would login to our application, and when clicking a link to take them to a support forum, they&#8217;d already be logged in. phpBB isn&#8217;t known for having a great API with which to integrate, but the code works, and the product [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, I was tasked with creating a single-sign-on solution for phpBB, where the user would login to our application, and when clicking a link to take them to a support forum, they&#8217;d already be logged in.  phpBB isn&#8217;t known for having a great API with which to integrate, but the code works, and the product works.  The authentication works on the premise of providing credentials, logging in, which creates a session in the phpBB database.  A cookie value is set, which ties the user to the server-side session.  When you have the 2 disparate systems, the domains might be different, but on the same top-level domain.  This means if we could get the session ID and set a cookie on the next domain level up, we could be logged in.</p>
<p>The implementation is fairly simple, upon login, we use cURL or something similar and generate a POST request, using the username and password.  The remote script grabs the session ID and user ID and returns the values to the originating server.  We then, set the cookie values.</p>
<p>Now, the interesting bit.  phpBB has multiple layers by which it validates the session.  Since our remote server is originating the request, we don&#8217;t have the same IP as the user.  Second, it uses the User-Agent string of the browser to validate the session.  Using cURL, we don&#8217;t have a browser.  Now, with cURL, you can set various settings (User-Agent string, X-Forwarded-For header, etc) &#8211; but if you&#8217;d rather not depend on that, you can simply un-check those settings in phpBB.</p>
<p>Of course, I&#8217;d recommend using the cURL settings, but to get you started and ensure the connectivity is working.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.roweware.com/2010/01/26/external-login-to-phpbb/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ZFDataGrid &#8211; Enabling Export</title>
		<link>http://blog.roweware.com/2009/12/29/zfdatagrid-enabling-export/</link>
		<comments>http://blog.roweware.com/2009/12/29/zfdatagrid-enabling-export/#comments</comments>
		<pubDate>Tue, 29 Dec 2009 22:41:33 +0000</pubDate>
		<dc:creator>Dave Rowe</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[zend]]></category>
		<category><![CDATA[zfdatagrid]]></category>

		<guid isPermaLink="false">http://blog.roweware.com/?p=159</guid>
		<description><![CDATA[I&#8217;m evaluating a DataGrid for use in a project which is using the Zend Framework, and I came across the ZFDataGrid project.  Fantastic work, and the grid works wonderfully.  It enables you to filter your data and export it in various formats (PDF, Doc, Docx, OpenOffice, etc).  The sample on the site works exactly like [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m evaluating a DataGrid for use in a project which is using the <a href="http://framework.zend.com/">Zend Framework</a>, and I came across the <a href="http://code.google.com/p/zfdatagrid/">ZFDataGrid</a> project.  Fantastic work, and the grid works wonderfully.  It enables you to filter your data and export it in various formats (PDF, Doc, Docx, <a href="http://www.openoffice.org/">OpenOffice</a>, etc).  The <a href="http://www.petala-azul.com/grid/">sample</a> on the site works exactly like this.  The only issue is the manual doesn&#8217;t exactly explain how to enable the export functionality.  It doesn&#8217;t &#8216;just work&#8217;, but it was reasonably easy to find since the code for the sample site is in <a href="http://code.google.com/">Google Code</a>.  But, it isn&#8217;t in an intuitive place like the manual or on the site itself.  So, to hopefully save someone else some time, I&#8217;ll post the code here &#8211; it is from the sample <a href="http://code.google.com/p/zfdatagrid/source/browse/trunk/application/controllers/SiteController.php">SiteController</a>, and not originally written by me.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p159code6'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p1596"><td class="code" id="p159code6"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$export</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRequest</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getParam</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'export'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">switch</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$export</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'odt'</span> <span style="color: #339933;">:</span>
        <span style="color: #000088;">$grid</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Bvb_Grid_Deploy_Odt&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'ods'</span> <span style="color: #339933;">:</span>
        <span style="color: #000088;">$grid</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Bvb_Grid_Deploy_Ods&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'xml'</span> <span style="color: #339933;">:</span>
        <span style="color: #000088;">$grid</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Bvb_Grid_Deploy_Xml&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'csv'</span> <span style="color: #339933;">:</span>
        <span style="color: #000088;">$grid</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Bvb_Grid_Deploy_Csv&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'excel'</span> <span style="color: #339933;">:</span>
        <span style="color: #000088;">$grid</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Bvb_Grid_Deploy_Excel&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'word'</span> <span style="color: #339933;">:</span>
        <span style="color: #000088;">$grid</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Bvb_Grid_Deploy_Word&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'wordx'</span> <span style="color: #339933;">:</span>
        <span style="color: #000088;">$grid</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Bvb_Grid_Deploy_Wordx&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'pdf'</span> <span style="color: #339933;">:</span>
        <span style="color: #000088;">$grid</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Bvb_Grid_Deploy_Pdf&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'print'</span> <span style="color: #339933;">:</span>
        <span style="color: #000088;">$grid</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Bvb_Grid_Deploy_Print&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">default</span> <span style="color: #339933;">:</span>
        <span style="color: #000088;">$grid</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Bvb_Grid_Deploy_Table&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$grid</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #000088;">$grid</span> <span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'DataGrid Example'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'/tmp'</span><span style="color: #339933;">,</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'download'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$grid</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setDataFromCsv</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/dirname"><span style="color: #990000;">dirname</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/Detail_Limited.csv'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$grid</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">imagesUrl</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'/images/'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">grid</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$grid</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">deploy</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>The code at the end is mine, which basically tells the DataGrid where to render/save the exported file, which is then immediately sent for download.  I also am not using the Zend_Db stuff for the data.  As a proof-of-concept, I&#8217;m using a simple dataset in CSV, which works amazingly well.  The filters, sorting, and pagination still work with CSV.</p>
<p>I&#8217;m thinking about writing an adapter for <a href="http://www.doctrine-project.org/">Doctrine</a>, such that one could construct a Doctrine query object, pass it into the DataGrid, and everything would work, as it does with the Zend_Db counterparts.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.roweware.com/2009/12/29/zfdatagrid-enabling-export/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Surrogates</title>
		<link>http://blog.roweware.com/2009/12/23/surrogates/</link>
		<comments>http://blog.roweware.com/2009/12/23/surrogates/#comments</comments>
		<pubDate>Wed, 23 Dec 2009 20:14:44 +0000</pubDate>
		<dc:creator>Dave Rowe</dc:creator>
				<category><![CDATA[Database Design]]></category>
		<category><![CDATA[keys]]></category>
		<category><![CDATA[linking table]]></category>
		<category><![CDATA[many to many]]></category>
		<category><![CDATA[orm]]></category>

		<guid isPermaLink="false">http://blog.roweware.com/?p=150</guid>
		<description><![CDATA[In my previous post, I used a key style that is open to debate and has been for many years amongst DB folks. The idea of every table having a surrogate key, regardless of the purpose of the table. This says, that for any record in the table I have a single column that acts [...]]]></description>
			<content:encoded><![CDATA[<p>In my previous post, I used a key style that is open to debate and has been for many years amongst DB folks.  The idea of every table having a surrogate key, regardless of the purpose of the table.  This says, that for any record in the table I have a single column that acts as the primary key.  Given a many-to-many relationship, using a surrogate key on the linking table allows me to describe the relationship in terms of objects and how they&#8217;re represented.  As shown in the below diagram &#8211; each user may have many user_role instances, which are tied to a single role instance.  This makes the lives of ORMs much easier since you can create objects for the linking table, which has a simple key to reference.</p>
<p style="text-align: center;"><a href="http://blog.roweware.com/wp-content/uploads/2009/12/Surrogate.png"><img class="size-full wp-image-152 aligncenter" title="Surrogate" src="http://blog.roweware.com/wp-content/uploads/2009/12/Surrogate.png" alt="" width="414" height="124" /></a></p>
<p>The ORM then has a User, UserRole, and Role object to use in accessing these tables and adding / removing relationships with ease, since it only needs to worry about the single surrogate &#8216;id&#8217; key on each table.  In the linking table (as a design concern), one should place a Unique Index on the user_id/role_id column combination.</p>
<p>The other option is using a composite candidate key.  I may have the specific terminology wrong, but the idea is that instead of the single surrogate key to identify a unique record in the linking table, you use a design like the diagram below, which combines the columns that are foreign keys to their respective tables to create the primary key.  The combination of the columns creates a unique identifying key.  The difficulty emerges with ORMs attempting to create objects out this design, and attempting to correctly generate the SQL required to make updates / deletes, etc, using each member of the composite key.</p>
<p style="text-align: center;"><a href="http://blog.roweware.com/wp-content/uploads/2009/12/NoSurrogate.png"><img class="size-full wp-image-151 aligncenter" title="NoSurrogate" src="http://blog.roweware.com/wp-content/uploads/2009/12/NoSurrogate.png" alt="" width="399" height="108" /></a></p>
<p>Personally speaking, I&#8217;m a fan of the surrogate key approach, but I&#8217;ve worked with both.  I won&#8217;t discuss the performance impacts of either design, since I don&#8217;t have nearly the research base to accurately describe it.  But, using simple integer based keys, the difference should be low.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.roweware.com/2009/12/23/surrogates/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>MySQL Multi-Table Delete</title>
		<link>http://blog.roweware.com/2009/12/08/mysql-multi-table-delete/</link>
		<comments>http://blog.roweware.com/2009/12/08/mysql-multi-table-delete/#comments</comments>
		<pubDate>Tue, 08 Dec 2009 19:27:20 +0000</pubDate>
		<dc:creator>Dave Rowe</dc:creator>
				<category><![CDATA[Database Design]]></category>
		<category><![CDATA[joins]]></category>
		<category><![CDATA[multi-delete]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://blog.roweware.com/?p=142</guid>
		<description><![CDATA[MySQL provides cascading updates / deletes with the relationships, but I tend not to use them, specifically because I want to control just how far these updates and deletes cascade!  But, given a situation where I have a design similar to this: I would like to be able to remove a single Foo, without having [...]]]></description>
			<content:encoded><![CDATA[<p>MySQL provides cascading updates / deletes with the relationships, but I tend not to use them, specifically because I want to control just how far these updates and deletes cascade!  But, given a situation where I have a design similar to this:</p>
<p style="text-align: center;"><img class="size-full wp-image-143 aligncenter" title="multi-delete" src="http://blog.roweware.com/wp-content/uploads/2009/12/multi-delete.png" alt="multi-delete" width="270" height="255" /></p>
<p>I would like to be able to remove a single Foo, without having to first remove all the associated data from the other 3 tables.  Or, I know the ID of the Foo I want to remove, so instead of running multiple queries to find the associated rows, lets just knock it out with a single, multi-table delete!</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p142code8'); return false;">View Code</a> SQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p1428"><td class="code" id="p142code8"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">DELETE</span>
  db<span style="color: #66cc66;">.</span>zap <span style="color: #993333; font-weight: bold;">as</span> z<span style="color: #66cc66;">,</span>
  db<span style="color: #66cc66;">.</span>baz <span style="color: #993333; font-weight: bold;">as</span> bz<span style="color: #66cc66;">,</span>
  db<span style="color: #66cc66;">.</span>bar <span style="color: #993333; font-weight: bold;">as</span> z<span style="color: #66cc66;">,</span>
  db<span style="color: #66cc66;">.</span>foo <span style="color: #993333; font-weight: bold;">as</span> f
<span style="color: #993333; font-weight: bold;">FROM</span>
  db<span style="color: #66cc66;">.</span>zap <span style="color: #993333; font-weight: bold;">as</span> b<span style="color: #66cc66;">,</span>
  db<span style="color: #66cc66;">.</span>baz <span style="color: #993333; font-weight: bold;">as</span> bz<span style="color: #66cc66;">,</span>
  db<span style="color: #66cc66;">.</span>bar <span style="color: #993333; font-weight: bold;">as</span> z<span style="color: #66cc66;">,</span>
  db<span style="color: #66cc66;">.</span>foo <span style="color: #993333; font-weight: bold;">as</span> f
<span style="color: #993333; font-weight: bold;">WHERE</span>
  b<span style="color: #66cc66;">.</span>baz_id <span style="color: #66cc66;">=</span> bz<span style="color: #66cc66;">.</span>id <span style="color: #993333; font-weight: bold;">AND</span>
  b<span style="color: #66cc66;">.</span>zap_id <span style="color: #66cc66;">=</span> z<span style="color: #66cc66;">.</span>id <span style="color: #993333; font-weight: bold;">AND</span>
  bz<span style="color: #66cc66;">.</span>foo_id <span style="color: #66cc66;">=</span> f<span style="color: #66cc66;">.</span>id <span style="color: #993333; font-weight: bold;">AND</span>
  z<span style="color: #66cc66;">.</span>foo_id <span style="color: #66cc66;">=</span> f<span style="color: #66cc66;">.</span>id <span style="color: #993333; font-weight: bold;">AND</span>
  f<span style="color: #66cc66;">.</span>id <span style="color: #66cc66;">=</span> ?</pre></td></tr></table></div>

<p>This will then remove the rows associated with the single Foo record I&#8217;ve referenced, in one fell swoop.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.roweware.com/2009/12/08/mysql-multi-table-delete/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>DB Design &#8211; ICD9 Data</title>
		<link>http://blog.roweware.com/2009/12/01/db-design-icd9-data/</link>
		<comments>http://blog.roweware.com/2009/12/01/db-design-icd9-data/#comments</comments>
		<pubDate>Tue, 01 Dec 2009 23:02:48 +0000</pubDate>
		<dc:creator>Dave Rowe</dc:creator>
				<category><![CDATA[Database Design]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[db]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[ICD9]]></category>
		<category><![CDATA[medical]]></category>

		<guid isPermaLink="false">http://blog.roweware.com/?p=140</guid>
		<description><![CDATA[In today's Adventures in Database Design, we'll take a look at a relevant topic, ICD9 data.  ICD9 data is the diagnosis and procedure codes used by insurance companies to categorize, well, diagnoses and procedures to be determined / performed by medical professionals.  The design is simple, but very versatile, given the type of data we're storing.]]></description>
			<content:encoded><![CDATA[<p>ICD9 data are the diagnosis and procedure codes used by insurance companies to categorize, well, diagnoses and procedures to be determined / performed by medical professionals.  Typically, if you visit the doctor for an ailment and file insurance, your provider will list the reason for the visit, any diagnoses, and any procedures performed.  This is then sent to the insurance company for processing.  They can then use codes to indicate if the procedure is covered, as well as, (for example) determine if the diagnosis was a pre-existing condition.  The data is a simple hierarchical structure which is shown in the following diagram.</p>
<div id="attachment_139" class="wp-caption alignnone" style="width: 306px"><img class="size-medium wp-image-139" title="ICD9" src="http://blog.roweware.com/wp-content/uploads/2009/12/ICD9-296x300.png" alt="ERD for storing ICD9 data" width="296" height="300" /><p class="wp-caption-text">ERD for storing ICD9 data</p></div>
<p>We see that diagnoses can have sub-diagnoses, etc.  I used this simple structure, and added a qualifying column of &#8216;record_type&#8217; to indicate if the code listed was an actual diagnosis, or a section header.  Sections of diagnoses are part of the data, and can be used in searching the database.  This diagram offers a simple and quick design to handle the data given.</p>
<p>Comments are welcome.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.roweware.com/2009/12/01/db-design-icd9-data/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Adventures in Database Design</title>
		<link>http://blog.roweware.com/2009/11/23/adventures-in-database-design/</link>
		<comments>http://blog.roweware.com/2009/11/23/adventures-in-database-design/#comments</comments>
		<pubDate>Tue, 24 Nov 2009 03:39:56 +0000</pubDate>
		<dc:creator>Dave Rowe</dc:creator>
				<category><![CDATA[Database Design]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[workbench]]></category>

		<guid isPermaLink="false">http://blog.roweware.com/?p=137</guid>
		<description><![CDATA[I&#8217;ve long neglected this blog, and the power behind it to discuss my feelings toward database design.  Proper database design is the backbone to a solid application.  Failing to correctly normalize tables and enforce business logic with foreign key relationships can cause undue headaches. What I&#8217;ll be doing is going through some simple applications, and [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve long neglected this blog, and the power behind it to discuss my feelings toward database design.  Proper database design is the backbone to a solid application.  Failing to correctly normalize tables and enforce business logic with foreign key relationships can cause undue headaches.</p>
<p>What I&#8217;ll be doing is going through some simple applications, and start modeling the tables and relationships, and intersperse some commentary where useful.  The discussion depends on interaction, and I&#8217;m of the opinion that a &#8216;good&#8217; database designer can a) defend their design articulately and b) know when to concede a good point.</p>
<p>Database design is becoming organic.  Strict adherence to the normal forms isn&#8217;t required any longer.  Let me be clear though, denormalizing a table to make things easier for a developer is not a valid reason to denormalize.</p>
<p>The modeling tool I&#8217;ll be using for generating the images is <a title="MySQL Workbench" href="http://wb.mysql.com/" target="_blank">MySQL Workbench</a>.  Workbench is a very powerful tool, from the source of one of the most powerful (and used) databases today.  I cut my teeth on database design with DBDesigner4, whose creator went on to work for MySQL Workbench.</p>
<p>Stay tuned.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.roweware.com/2009/11/23/adventures-in-database-design/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fast Cars and Winding Roads &#8211; Part 1</title>
		<link>http://blog.roweware.com/2009/07/13/fast-cars-and-winding-roads-part-1/</link>
		<comments>http://blog.roweware.com/2009/07/13/fast-cars-and-winding-roads-part-1/#comments</comments>
		<pubDate>Tue, 14 Jul 2009 02:22:52 +0000</pubDate>
		<dc:creator>Dave Rowe</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Opinion]]></category>
		<category><![CDATA[management thoughts]]></category>
		<category><![CDATA[release cycles]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[team management]]></category>

		<guid isPermaLink="false">http://blog.roweware.com/?p=110</guid>
		<description><![CDATA[My boss used an analogy today, which struck me as quite accurate for the position we&#8217;re currently in.  We&#8217;re moving at a fairly rapid pace, quick releases, and plenty of improvements / changes.  Along with this, there is new business, new ideas, and new potential sources of revenue that we&#8217;re working on. Assuming that the [...]]]></description>
			<content:encoded><![CDATA[<p>My boss used an analogy today, which struck me as quite accurate for the position we&#8217;re currently in.  We&#8217;re moving at a fairly rapid pace, quick releases, and plenty of improvements / changes.  Along with this, there is new business, new ideas, and new potential sources of revenue that we&#8217;re working on.</p>
<p>Assuming that the speed of the vehicle is constant, and the winding is fairly unknown, how do you best prevent hitting the walls?  This part of the analogy is talking about software quality.  While no one is perfect, reducing the amount of churn on bugs and enhancements allows for time better spent on other things, be it additional bugs, new enhancements, or time to re-design the credit card processing module to be more efficient.</p>
<p>In keeping with the analogy, I tried to think of various methods to implement, which prevent hitting the wall.  The first, posed by my direct superior was to &#8216;increase the accuracy of the driver&#8217;.  This is the ideal solution, all things the same.  But, what other factors contribute?</p>
<p>Part 1 &#8211; Size of the car</p>
<p>Reducing the size of the car will generally improve the accuracy of the car.  Now, with this analogy, I&#8217;m thinking in terms of relative extremes, and I won&#8217;t delve into the nit-picks of which 2-door sport coup is the best for suspension.  So, consider 2 vehicles.  1 &#8211; a smaller 4-door sedan, low-profile, but consistent acceleration / braking.  2 &#8211; an eighteen wheeler &#8211; hauls, but reaction time is limited, and said reactions are greatly exaggerated.</p>
<p>A smaller car here represents a focused small unit of developers.  These developers are typically the medium-high to high performers, able to deliver on quality in terms of fixing an issue, and in terms of overall design and architecture.  They work closely together in a nice cohesive environment, with limited distractions.  This allows for quick reactions to change, more rapid context-switches between projects, and good performance.  But, the amount of total &#8216;fixing&#8217; they can do is limited (they&#8217;re in a sedan, for petes sake!).</p>
<p>A big rig here represents a bigger team, with a wider range of skillsets.  You have the higher performers, but also the medium-lows (no lows here, that&#8217;s just not pleasant).  Likewise, the medium-lows can deliver, and the solutions work, but they may not be fully thought out, they may not consider some design flaws in their solution which could impact maintainability down the line, but they _can_ deliver a solution.  This team moves along quickly, making a lot of changes, but with unexpected turns ahead, the reactions and turns cause turmoil and disruption.  But, at the end of the day, there is quite a bit of things being fixed, the worry though is, is it being _really_ fixed?</p>
<p>Is the amount of items being fixed the goal?  Or, can you afford to delay a while, but in the end deliver a more solid product?  Over time, the lines will converge, and the products will more than likely appear similar, and operate fine, but did your reputation suffer along the way?  Are customers willing to wait, if they know the problem will be resolved to their complete satisfaction?  Or, do customers accept a partial solution, and potential headaches, but know that eventually the problem will be fully resolved?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.roweware.com/2009/07/13/fast-cars-and-winding-roads-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C++ Project Layout</title>
		<link>http://blog.roweware.com/2009/07/01/c-project-layout/</link>
		<comments>http://blog.roweware.com/2009/07/01/c-project-layout/#comments</comments>
		<pubDate>Thu, 02 Jul 2009 00:51:01 +0000</pubDate>
		<dc:creator>Dave Rowe</dc:creator>
				<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://blog.roweware.com/?p=67</guid>
		<description><![CDATA[With the recent license change at Nokia/Trolltech for Qt &#8211; I&#8217;ve grown more interested in learning proper GUI development, specifically with C++. I know there are bindings to other languages, but for simplicity of deployment, I think C++ will be easiest to test / depend on, as well as protect in the event that I [...]]]></description>
			<content:encoded><![CDATA[<p>With the recent <a href="http://www.qtsoftware.com/about/news/lgpl-license-option-added-to-qt">license change</a> at Nokia/<a href="http://www.qtsoftware.com/">Trolltech</a> for Qt &#8211; I&#8217;ve grown more interested in learning proper GUI development, specifically with C++.  I know there are bindings to other languages, but for simplicity of deployment, I think C++ will be easiest to test / depend on, as well as protect in the event that I create something of actual value.</p>
<p>So, outside of the context of Qt, specifically, what are the best practices for organizing C++ projects?  I&#8217;m used to packages in Java for code organization, do people follow similar suit with C++?  In looking at a large project like <a href="http://www.kde.org">KDE</a>, it seems that for the bulk of utilities / applications, the code is organized in a single directory, not necessarily split out (as might be the case with a Java project).</p>
<p>Are namespaces worth it?  At what size of a project would they add value.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.roweware.com/2009/07/01/c-project-layout/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
