<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Raw SQL from Doctrine Query Object &#8211; Revised</title>
	<atom:link href="http://www.chrisshennan.com/2009/12/07/raw-sql-from-doctrine-query-object-revised/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.chrisshennan.com/2009/12/07/raw-sql-from-doctrine-query-object-revised/</link>
	<description>A day in the life of...</description>
	<lastBuildDate>Wed, 11 Aug 2010 18:41:55 +0100</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Christopher Shennan</title>
		<link>http://www.chrisshennan.com/2009/12/07/raw-sql-from-doctrine-query-object-revised/comment-page-1/#comment-1671</link>
		<dc:creator>Christopher Shennan</dc:creator>
		<pubDate>Tue, 16 Feb 2010 14:10:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.chrisshennan.com/?p=232#comment-1671</guid>
		<description>Thanks for the update Stoyan.

I have now used both variations in my projects now as one was symfony based (so the MyQueryClass solution worked perfectly) and one was not (so the initial global function version worked well in this instance).</description>
		<content:encoded><![CDATA[<p>Thanks for the update Stoyan.</p>
<p>I have now used both variations in my projects now as one was symfony based (so the MyQueryClass solution worked perfectly) and one was not (so the initial global function version worked well in this instance).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stoyan</title>
		<link>http://www.chrisshennan.com/2009/12/07/raw-sql-from-doctrine-query-object-revised/comment-page-1/#comment-1633</link>
		<dc:creator>Stoyan</dc:creator>
		<pubDate>Tue, 09 Feb 2010 19:08:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.chrisshennan.com/?p=232#comment-1633</guid>
		<description>Also, for symfony:
1. create /yourproject/lib/MyQueryClass.php:

&lt;pre lang=&quot;php&quot;&gt;
class MyQueryClass extends Doctrine_Query
{
    public function getRawSql()
    {
        $query = $this-&gt;getSqlQuery();

        foreach ($this-&gt;getFlattenedParams() as $param) {
            $query = join(var_export(is_scalar($param) ? $param : (string) $param, true), explode(&#039;?&#039;, $query, 2));
        }

        return $query;
    }
}
&lt;/pre&gt;

Then in yourproject/config/ProjectConfiguration.class.php add the following method:

&lt;pre lang=&quot;php&quot;&gt;
  public function configureDoctrine(Doctrine_Manager $manager)
  {
    $manager-&gt;setAttribute(Doctrine_Core::ATTR_QUERY_CLASS, &#039;MyQueryClass&#039;);
  }
&lt;/pre&gt;

Now you can debug your queries everywhere in the project:

&lt;pre lang=&quot;php&quot;&gt;
    $query-&gt;getRawSql();
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Also, for symfony:<br />
1. create /yourproject/lib/MyQueryClass.php:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> MyQueryClass <span style="color: #000000; font-weight: bold;">extends</span> Doctrine_Query
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getRawSql<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getSqlQuery</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getFlattenedParams</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: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #990000;">join</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">var_export</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">is_scalar</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$param</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$param</span> <span style="color: #339933;">:</span> <span style="color: #009900;">&#40;</span>string<span style="color: #009900;">&#41;</span> <span style="color: #000088;">$param</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #990000;">explode</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;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$query</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Then in yourproject/config/ProjectConfiguration.class.php add the following method:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> configureDoctrine<span style="color: #009900;">&#40;</span>Doctrine_Manager <span style="color: #000088;">$manager</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$manager</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setAttribute</span><span style="color: #009900;">&#40;</span>Doctrine_Core<span style="color: #339933;">::</span><span style="color: #004000;">ATTR_QUERY_CLASS</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'MyQueryClass'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span></pre></div></div>

<p>Now you can debug your queries everywhere in the project:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">    <span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRawSql</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
	</item>
	<item>
		<title>By: Stoyan</title>
		<link>http://www.chrisshennan.com/2009/12/07/raw-sql-from-doctrine-query-object-revised/comment-page-1/#comment-1632</link>
		<dc:creator>Stoyan</dc:creator>
		<pubDate>Tue, 09 Feb 2010 19:03:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.chrisshennan.com/?p=232#comment-1632</guid>
		<description>I&#039;d propose the following solution:
&lt;pre lang=&quot;php&quot;&gt;
function getRawSqlQuery(Doctrine_Query $q)
{
    $queryString = $query-&gt;getSqlQuery();

    foreach ($query-&gt;getFlattenedParams() as $param) {
        $queryString = join(var_export(is_scalar($param) ? $param : (string) $param, true), explode(&#039;?&#039;, $queryString, 2));
    }

    return $queryString;
}
&lt;/pre&gt;

This is more generic solution, as it respects all param sections (having, set,  join, where). Your solutions works only with the &quot;where&quot; part.</description>
		<content:encoded><![CDATA[<p>I&#8217;d propose the following solution:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> getRawSqlQuery<span style="color: #009900;">&#40;</span>Doctrine_Query <span style="color: #000088;">$q</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;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getSqlQuery</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</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;">getFlattenedParams</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: #000088;">$queryString</span> <span style="color: #339933;">=</span> <span style="color: #990000;">join</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">var_export</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">is_scalar</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$param</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$param</span> <span style="color: #339933;">:</span> <span style="color: #009900;">&#40;</span>string<span style="color: #009900;">&#41;</span> <span style="color: #000088;">$param</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'?'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$queryString</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$queryString</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This is more generic solution, as it respects all param sections (having, set,  join, where). Your solutions works only with the &#8220;where&#8221; part.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
