<?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>Christopher Shennan&#039;s Blog &#187; SQL</title>
	<atom:link href="http://www.chrisshennan.com/category/sql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.chrisshennan.com</link>
	<description>A day in the life of...</description>
	<lastBuildDate>Thu, 15 Sep 2011 15:13:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.1</generator>
		<item>
		<title>Backticks, Apostrophes and Quotation Marks</title>
		<link>http://www.chrisshennan.com/2010/12/08/backticks-apostrophes-and-quotation-marks/</link>
		<comments>http://www.chrisshennan.com/2010/12/08/backticks-apostrophes-and-quotation-marks/#comments</comments>
		<pubDate>Wed, 08 Dec 2010 20:47:55 +0000</pubDate>
		<dc:creator>Christopher Shennan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[apostrophes]]></category>
		<category><![CDATA[backticks]]></category>
		<category><![CDATA[backtics]]></category>
		<category><![CDATA[quotation marks]]></category>
		<category><![CDATA[quotes]]></category>

		<guid isPermaLink="false">http://www.chrisshennan.com/?p=462</guid>
		<description><![CDATA[I was trying to assist someone with the difference between backtics, apostrophes and quotation marks. The three are used in different circumstances and the the basic rules I use with &#8216;, ` and &#34; are:- I only use ` in MySQL and only where the field or table name is a reserved word i.e. you [...]]]></description>
			<content:encoded><![CDATA[<p>I was trying to assist someone with the difference between backtics, apostrophes and quotation marks.  The three are used in different circumstances and the the basic rules I use with &#8216;, ` and &quot; are:-</p>
<p>I only use ` in MySQL and only where the field or table name is a reserved word i.e. you have a field called date so the query ends up like</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> title<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">`date`</span> <span style="color: #993333; font-weight: bold;">FROM</span> sometable</pre></div></div>

<p><span id="more-462"></span><br />
I use &#8216; and &quot; within PHP for different things:</p>
<p>if we have a variable called $test with a value of &#8220;this is my sample data&#8221;;</p>
<p>&#8216; spits out exactly what&#8217;s within the apostrophes (variable aren&#8217;t evaluated) so</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'My text is: $test'</span><span style="color: #339933;">;</span></pre></div></div>

<p>will output</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">My text is: $test</pre></div></div>

<p>&quot; allows the variables to be evaluated so</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;My text is: <span style="color: #006699; font-weight: bold;">$test</span>&quot;</span><span style="color: #339933;">;</span></pre></div></div>

<p>will output</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">My text is: this is my sample data</pre></div></div>

<div class="addthis_toolbox addthis_default_style " addthis:url='http://www.chrisshennan.com/2010/12/08/backticks-apostrophes-and-quotation-marks/' addthis:title='Backticks, Apostrophes and Quotation Marks ' ><a href="//addthis.com/bookmark.php?v=250&amp;username=xa-4d2b47597ad291fb" class="addthis_button_compact">Share</a><span class="addthis_separator">|</span><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a></div>]]></content:encoded>
			<wfw:commentRss>http://www.chrisshennan.com/2010/12/08/backticks-apostrophes-and-quotation-marks/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>mysqldump on Windows gives &#8220;Access is Denied&#8221;</title>
		<link>http://www.chrisshennan.com/2010/03/24/mysqldump-on-windows-gives-access-is-denied/</link>
		<comments>http://www.chrisshennan.com/2010/03/24/mysqldump-on-windows-gives-access-is-denied/#comments</comments>
		<pubDate>Wed, 24 Mar 2010 22:17:26 +0000</pubDate>
		<dc:creator>Christopher Shennan</dc:creator>
				<category><![CDATA[MSSQL]]></category>
		<category><![CDATA[database migration]]></category>
		<category><![CDATA[migration]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://www.chrisshennan.com/?p=294</guid>
		<description><![CDATA[I recently had to back up a MySQL database on a windows server so I could restore it to my local MySQL server for analysing the structure of an existing site which we are going to be rebuilding. I have done this hundreds of times on linux server but the usual command did not appear [...]]]></description>
			<content:encoded><![CDATA[<p>I recently had to back up a MySQL database on a windows server so I could restore it to my local MySQL server for analysing the structure of an existing site which we are going to be rebuilding.  I have done this hundreds of times on linux server but the usual command did not appear to work on this windows server.  I was using:-</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">mysqldump <span style="color: #660033;">-uroot</span> <span style="color: #660033;">-pPASSWORD</span> database <span style="color: #000000; font-weight: bold;">&gt;</span> c:\database.sql</pre></div></div>

<p>but when I ran this I was presented with an &#8220;Access Denied&#8221; message.<br />
<span id="more-294"></span><br />
My first thought was that the MySQL database username and password that I was using was incorrect, however this message refers to not having permissions to create the file c:\database.sql.</p>
<p>Once I realised this was a file permissions problem and not a database permissions problem I changed the path to one I knew I had write access on and the database exported without any problems.</p>
<div class="addthis_toolbox addthis_default_style " addthis:url='http://www.chrisshennan.com/2010/03/24/mysqldump-on-windows-gives-access-is-denied/' addthis:title='mysqldump on Windows gives &#8220;Access is Denied&#8221; ' ><a href="//addthis.com/bookmark.php?v=250&amp;username=xa-4d2b47597ad291fb" class="addthis_button_compact">Share</a><span class="addthis_separator">|</span><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a></div>]]></content:encoded>
			<wfw:commentRss>http://www.chrisshennan.com/2010/03/24/mysqldump-on-windows-gives-access-is-denied/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Raw SQL from a Doctrine Query Object</title>
		<link>http://www.chrisshennan.com/2009/09/22/raw-sql-from-a-doctrine-query-object/</link>
		<comments>http://www.chrisshennan.com/2009/09/22/raw-sql-from-a-doctrine-query-object/#comments</comments>
		<pubDate>Tue, 22 Sep 2009 19:01:49 +0000</pubDate>
		<dc:creator>Christopher Shennan</dc:creator>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[doctrine]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.chrisshennan.com/?p=138</guid>
		<description><![CDATA[This has been updated to work with Symfony 1.3/1.4 &#8211; Please go to the updated article: Raw SQL from Doctrine Query Object – Revised As my use of Symfony is increasing I find myself frustrated that there doesn&#8217;t appear to be an easy way to get the raw SQL from a doctrine query object so [...]]]></description>
			<content:encoded><![CDATA[<p><strong>This has been updated to work with Symfony 1.3/1.4 &#8211; Please go to the updated article:  <a href="/2009/12/07/raw-sql-from-doctrine-query-object-revised/">Raw SQL from Doctrine Query Object – Revised</a></strong></p>
<p>As my use of Symfony is increasing I find myself frustrated that there doesn&#8217;t appear to be an easy way to get the raw SQL from a doctrine query object so I can simply output it and paste it into phpMyAdmin to debug problems with the SQL.  I may be wrong about this but as yet I have not found a built in function to perform this operation.</p>
<p>Sure I am able to output the query with the &#8220;?&#8221; indicating where the necessary values are to go and I can also easily output the array of query parameters so I can substitute these manually but this takes time and it would be much much simpler and quicker to just output the whole query with the substitution already done so it&#8217;s a simply copy and paste of the raw SQL from the doctrine query object straight into phpMyAdmin.</p>
<p>I have wrote a quick function to do this and I had meant to post this for a while but I just have not had the chance to get round to it until now.<br />
<span id="more-138"></span><br />
The code for this is can be found below:-</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> get_raw_sql<span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">limit</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$queryStringParts</span> <span style="color: #339933;">=</span> <span style="color: #990000;">split</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'\?'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getSQL</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$iQC</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$queryString</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getParams</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$param</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">is_numeric</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$param</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$queryString</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$queryStringParts</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$iQC</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$param</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">is_bool</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$param</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$queryString</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$queryStringParts</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$iQC</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$param</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$queryString</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$queryStringParts</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$iQC</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'\''</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$param</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'\''</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000088;">$iQC</span><span style="color: #339933;">++;</span>
   <span style="color: #009900;">&#125;</span>
&nbsp;
   <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$iQC</span><span style="color: #339933;">;</span><span style="color: #000088;">$iQC</span> <span style="color: #339933;">&lt;</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$queryStringParts</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000088;">$iQC</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
       <span style="color: #000088;">$queryString</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$queryStringParts</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$iQC</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
   <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$queryString</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>In my case this is a global function but it could very well be written as a static function in a debug class.</p>
<p>$query is a Doctrine Query object and this function iterates round the parameters for the query string and replaces each instance of a &#8220;?&#8221; with the corresponding variable.  It has a crude (but fairly effective so far) method of determine whether it&#8217;s a string, number or boolean when performing this substitution and so far this works well in all the cases I&#8217;ve used it.</p>
<p>The $query->limit(0); is very important as the $query->getSQL() function does not work properly in this context if a limit is specified on the query so as we are wanting to debug the SQL and a majority of the time we are not concerned with the limit I have opted to remove this from this routine.</p>
<p>Hopefully this will allow you to save some time and effort trying to get the raw SQL from your doctrine query objects and I would appreciated any comments, thoughts or ideas you may have for improvement.</p>
<div class="addthis_toolbox addthis_default_style " addthis:url='http://www.chrisshennan.com/2009/09/22/raw-sql-from-a-doctrine-query-object/' addthis:title='Raw SQL from a Doctrine Query Object ' ><a href="//addthis.com/bookmark.php?v=250&amp;username=xa-4d2b47597ad291fb" class="addthis_button_compact">Share</a><span class="addthis_separator">|</span><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a></div>]]></content:encoded>
			<wfw:commentRss>http://www.chrisshennan.com/2009/09/22/raw-sql-from-a-doctrine-query-object/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>eSense Visualisers &#8211; Friend or Foe?</title>
		<link>http://www.chrisshennan.com/2009/03/22/esense-visualisers-friend-or-foe/</link>
		<comments>http://www.chrisshennan.com/2009/03/22/esense-visualisers-friend-or-foe/#comments</comments>
		<pubDate>Sun, 22 Mar 2009 16:52:44 +0000</pubDate>
		<dc:creator>Christopher Shennan</dc:creator>
				<category><![CDATA[MSSQL]]></category>
		<category><![CDATA[Sharepoint]]></category>

		<guid isPermaLink="false">http://www.chrisshennan.com/?p=18</guid>
		<description><![CDATA[For several months now I&#8217;ve been using eSense Visualizers for Microsoft Sharepoint to output the contents of a database in a meaningful and easy to understand view that is suitable for the client, although lately I&#8217;ve not been using it as much.  Just this morning I&#8217;ve had to use it for a few hours again and [...]]]></description>
			<content:encoded><![CDATA[<p>For several months now I&#8217;ve been using <a title="eSense Visualizers for Microsoft Sharepoint" href="http://www.nse.com/Pages/eSENSEVisualizers.aspx" target="_blank">eSense Visualizers for Microsoft Sharepoint</a> to output the contents of a database in a meaningful and easy to understand view that is suitable for the client, although lately I&#8217;ve not been using it as much.  Just this morning I&#8217;ve had to use it for a few hours again and I&#8217;m quickly remembering why I don&#8217;t like it and I have several issues that bug me (and I&#8217;m hoping it&#8217;s not just me).  These include:-</p>
<p><span id="more-18"></span></p>
<ul>
<li>When copying a query into eSense Visualizers (from notepad or Microsoft SQL Server Management Studio) it puts strange characters into the editor window which do not seem to cause any problems with the query running but does result in error message dialog boxes each time you go to the query editor.  The only way I&#8217;ve solved this so far is to save the query as a view or stored procedure and call that from eSense Visualizers.</li>
<li>Formatting can take ages to apply and can be lost if the query changes even slightly and although it is a little more stable when you use stored procedures but it can still be a royal pain.  As the project progressed some of the stored procedure names are not accurate now but I&#8217;m extremely hesistant to rename then as I&#8217;m pretty sure I&#8217;ll have to re-do the formatting for a large proportion of the entities I have created.</li>
<li>There doesn&#8217;t seem to be an easy way to copy a entity and I&#8217;ve spend hours creating entities and formatting them when I could have been done in around 30 minutes if I could simply have copied the entity and changed a parameter value.</li>
<li>When updating a query the data on the screen does not always refresh right away and I have to edit the web part and click &#8220;Apply&#8221; before it will show the updated results.  I can understand that the caching is to try and avoid too many of the same queries being sent to the database, however, I can loose a good bit of time because I have to go through this process each time I update the query for entity and on a server that has decided it&#8217;s time for a go-slow&#8230; it&#8217;s not too good!</li>
</ul>
<p>I don&#8217;t know if these are in to be addressed in future releases (or if there is currently configuration option I don&#8217;t know about) but I hope so as it would certainly make my life a good bit easier.</p>
<div class="addthis_toolbox addthis_default_style " addthis:url='http://www.chrisshennan.com/2009/03/22/esense-visualisers-friend-or-foe/' addthis:title='eSense Visualisers &#8211; Friend or Foe? ' ><a href="//addthis.com/bookmark.php?v=250&amp;username=xa-4d2b47597ad291fb" class="addthis_button_compact">Share</a><span class="addthis_separator">|</span><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a></div>]]></content:encoded>
			<wfw:commentRss>http://www.chrisshennan.com/2009/03/22/esense-visualisers-friend-or-foe/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

