<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: Enabling pagination with raw SQL queries</title>
	<atom:link href="http://arpeggios.wordpress.com/2009/02/02/enabling-pagination-with-raw-sql-queries/feed/" rel="self" type="application/rss+xml" />
	<link>http://arpeggios.wordpress.com/2009/02/02/enabling-pagination-with-raw-sql-queries/</link>
	<description>A symfony development blog by Nicolas Martin</description>
	<lastBuildDate>Mon, 21 Sep 2009 11:47:20 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: niko</title>
		<link>http://arpeggios.wordpress.com/2009/02/02/enabling-pagination-with-raw-sql-queries/#comment-173</link>
		<dc:creator>niko</dc:creator>
		<pubDate>Tue, 25 Aug 2009 08:22:03 +0000</pubDate>
		<guid isPermaLink="false">http://arpeggios.wordpress.com/?p=584#comment-173</guid>
		<description>just stopping to show respect :) thanks!</description>
		<content:encoded><![CDATA[<p>just stopping to show respect <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: michael lueftenegger</title>
		<link>http://arpeggios.wordpress.com/2009/02/02/enabling-pagination-with-raw-sql-queries/#comment-167</link>
		<dc:creator>michael lueftenegger</dc:creator>
		<pubDate>Tue, 21 Jul 2009 14:30:38 +0000</pubDate>
		<guid isPermaLink="false">http://arpeggios.wordpress.com/?p=584#comment-167</guid>
		<description>Hi!

I don&#039;t find a solution. My work around is a union all to get a dummy line as the firt entry, which is not shown.

This is really bad practice!

I think we need help from somebody knowing pdo better than me.

michael</description>
		<content:encoded><![CDATA[<p>Hi!</p>
<p>I don&#8217;t find a solution. My work around is a union all to get a dummy line as the firt entry, which is not shown.</p>
<p>This is really bad practice!</p>
<p>I think we need help from somebody knowing pdo better than me.</p>
<p>michael</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: michael lueftenegger</title>
		<link>http://arpeggios.wordpress.com/2009/02/02/enabling-pagination-with-raw-sql-queries/#comment-166</link>
		<dc:creator>michael lueftenegger</dc:creator>
		<pubDate>Mon, 20 Jul 2009 10:57:24 +0000</pubDate>
		<guid isPermaLink="false">http://arpeggios.wordpress.com/?p=584#comment-166</guid>
		<description>Hi!

I think there is still a bug in the code. if I execute the SQL directly in the db, I get 13 rows. echoing &quot;$this-&gt;statement-&gt;rowCount();&quot; at the beginning of &quot;getResults()&quot; returns 13. But adding this code

while ($resultset = $this-&gt;statement-&gt;fetch(PDO::FETCH_OBJ)){
    echo &quot;[&quot;.$resultset-&gt;title.&quot;]&quot;;	
    ....

just returns 12 titles. My idea is the statement doesn&#039;t stand on the first entry when entering the loop, but I am not sure at the moment.

Michael</description>
		<content:encoded><![CDATA[<p>Hi!</p>
<p>I think there is still a bug in the code. if I execute the SQL directly in the db, I get 13 rows. echoing &#8220;$this-&gt;statement-&gt;rowCount();&#8221; at the beginning of &#8220;getResults()&#8221; returns 13. But adding this code</p>
<p>while ($resultset = $this-&gt;statement-&gt;fetch(PDO::FETCH_OBJ)){<br />
    echo &#8220;[".$resultset-&gt;title."]&#8220;;<br />
    &#8230;.</p>
<p>just returns 12 titles. My idea is the statement doesn&#8217;t stand on the first entry when entering the loop, but I am not sure at the moment.</p>
<p>Michael</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: nicolas.martin</title>
		<link>http://arpeggios.wordpress.com/2009/02/02/enabling-pagination-with-raw-sql-queries/#comment-153</link>
		<dc:creator>nicolas.martin</dc:creator>
		<pubDate>Sun, 28 Jun 2009 12:38:34 +0000</pubDate>
		<guid isPermaLink="false">http://arpeggios.wordpress.com/?p=584#comment-153</guid>
		<description>Thanks for this ! 

Post is now updated with your fix.</description>
		<content:encoded><![CDATA[<p>Thanks for this ! </p>
<p>Post is now updated with your fix.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kyril</title>
		<link>http://arpeggios.wordpress.com/2009/02/02/enabling-pagination-with-raw-sql-queries/#comment-152</link>
		<dc:creator>Kyril</dc:creator>
		<pubDate>Fri, 26 Jun 2009 18:52:54 +0000</pubDate>
		<guid isPermaLink="false">http://arpeggios.wordpress.com/?p=584#comment-152</guid>
		<description>I noticed a subtle bug when using this pager (thanks again, btw)

When retrieving results for the first page it will always skip the first record, since $row_num is set to 0, and will always fail the first conditional test

    // getResults
    $row_num = 0;
    while ($resultset = $this-&gt;statement-&gt;fetch(PDO::FETCH_OBJ))
    {
      if ($row_num &gt; $this-&gt;getMaxPerPage()*($this-&gt;getPage()-1)
      and $row_num getPage()*$this-&gt;getMaxPerPage() ))
      {
        $this-&gt;resultsetArray[] = $resultset;
      }


I worked around this by setting $row_num to 1 instead</description>
		<content:encoded><![CDATA[<p>I noticed a subtle bug when using this pager (thanks again, btw)</p>
<p>When retrieving results for the first page it will always skip the first record, since $row_num is set to 0, and will always fail the first conditional test</p>
<p>    // getResults<br />
    $row_num = 0;<br />
    while ($resultset = $this-&gt;statement-&gt;fetch(PDO::FETCH_OBJ))<br />
    {<br />
      if ($row_num &gt; $this-&gt;getMaxPerPage()*($this-&gt;getPage()-1)<br />
      and $row_num getPage()*$this-&gt;getMaxPerPage() ))<br />
      {<br />
        $this-&gt;resultsetArray[] = $resultset;<br />
      }</p>
<p>I worked around this by setting $row_num to 1 instead</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: deva</title>
		<link>http://arpeggios.wordpress.com/2009/02/02/enabling-pagination-with-raw-sql-queries/#comment-149</link>
		<dc:creator>deva</dc:creator>
		<pubDate>Thu, 18 Jun 2009 13:04:46 +0000</pubDate>
		<guid isPermaLink="false">http://arpeggios.wordpress.com/?p=584#comment-149</guid>
		<description>Really super</description>
		<content:encoded><![CDATA[<p>Really super</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kyril</title>
		<link>http://arpeggios.wordpress.com/2009/02/02/enabling-pagination-with-raw-sql-queries/#comment-148</link>
		<dc:creator>Kyril</dc:creator>
		<pubDate>Mon, 15 Jun 2009 13:46:53 +0000</pubDate>
		<guid isPermaLink="false">http://arpeggios.wordpress.com/?p=584#comment-148</guid>
		<description>Thanks for  this.  I modified your code a little to simulate the behavior of sfPropelPager, and return all results when passing &#039;0&#039; as maxPerPage:

// getResults

 while ($resultset = $this-&gt;statement-&gt;fetch($fetch_type))
    {
    	if($this-&gt;getMaxPerPage() == 0){ // Return all results
    		$this-&gt;resultsetArray[] = $resultset;
    	}
    	else{
      		if ($row_num &gt; $this-&gt;getMaxPerPage()*($this-&gt;getPage()-1)
      		and $row_num getPage()*$this-&gt;getMaxPerPage() ))
      		{
        		$this-&gt;resultsetArray[] = $resultset;
      		}   		
    	}
    	
    	$row_num++;
    }</description>
		<content:encoded><![CDATA[<p>Thanks for  this.  I modified your code a little to simulate the behavior of sfPropelPager, and return all results when passing &#8216;0&#8242; as maxPerPage:</p>
<p>// getResults</p>
<p> while ($resultset = $this-&gt;statement-&gt;fetch($fetch_type))<br />
    {<br />
    	if($this-&gt;getMaxPerPage() == 0){ // Return all results<br />
    		$this-&gt;resultsetArray[] = $resultset;<br />
    	}<br />
    	else{<br />
      		if ($row_num &gt; $this-&gt;getMaxPerPage()*($this-&gt;getPage()-1)<br />
      		and $row_num getPage()*$this-&gt;getMaxPerPage() ))<br />
      		{<br />
        		$this-&gt;resultsetArray[] = $resultset;<br />
      		}<br />
    	}</p>
<p>    	$row_num++;<br />
    }</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: crystal</title>
		<link>http://arpeggios.wordpress.com/2009/02/02/enabling-pagination-with-raw-sql-queries/#comment-100</link>
		<dc:creator>crystal</dc:creator>
		<pubDate>Wed, 29 Apr 2009 15:16:50 +0000</pubDate>
		<guid isPermaLink="false">http://arpeggios.wordpress.com/?p=584#comment-100</guid>
		<description>hihi
i have tried your example. when i try to use my own table, i found that the code cannot work with the group by. 

below code cannot work, nothing is displayed:
$connection = Propel::getConnection(WinLoseResultPeer::DATABASE_NAME, Propel::CONNECTION_READ);
$query = &#039;SELECT COUNT(l.id) AS cnt, c.member_id AS custom_column
FROM tb_winlose_result c
left join tb_winlose_result l ON l.member_id=c.member_id
GROUP BY c.member_id&#039;;

$this-&gt;statement = $connection-&gt;prepare($query);

$this-&gt;pager = new statementPager(null, 10);
$this-&gt;pager-&gt;setStatement($this-&gt;statement);
$this-&gt;pager-&gt;setPage($request-&gt;getParameter(&#039;page&#039;, 1));
$this-&gt;pager-&gt;init();


But if i remove the count and group by, then the page will display the result, any idea why?

The code that can display result:
$connection = Propel::getConnection(WinLoseResultPeer::DATABASE_NAME, Propel::CONNECTION_READ);
$query = &#039;SELECT  c.member_id AS custom_column
FROM tb_winlose_result c
left join tb_winlose_result l ON l.member_id=c.member_id
&#039;;

$this-&gt;statement = $connection-&gt;prepare($query);

$this-&gt;pager = new statementPager(null, 10);
$this-&gt;pager-&gt;setStatement($this-&gt;statement);
$this-&gt;pager-&gt;setPage($request-&gt;getParameter(&#039;page&#039;, 1));
$this-&gt;pager-&gt;init();


The template i use is as below:
getResults() as $resultset): ?&gt;
  custom_column ?&gt;



Any help is really appreciated, thanks.</description>
		<content:encoded><![CDATA[<p>hihi<br />
i have tried your example. when i try to use my own table, i found that the code cannot work with the group by. </p>
<p>below code cannot work, nothing is displayed:<br />
$connection = Propel::getConnection(WinLoseResultPeer::DATABASE_NAME, Propel::CONNECTION_READ);<br />
$query = &#8216;SELECT COUNT(l.id) AS cnt, c.member_id AS custom_column<br />
FROM tb_winlose_result c<br />
left join tb_winlose_result l ON l.member_id=c.member_id<br />
GROUP BY c.member_id&#8217;;</p>
<p>$this-&gt;statement = $connection-&gt;prepare($query);</p>
<p>$this-&gt;pager = new statementPager(null, 10);<br />
$this-&gt;pager-&gt;setStatement($this-&gt;statement);<br />
$this-&gt;pager-&gt;setPage($request-&gt;getParameter(&#8216;page&#8217;, 1));<br />
$this-&gt;pager-&gt;init();</p>
<p>But if i remove the count and group by, then the page will display the result, any idea why?</p>
<p>The code that can display result:<br />
$connection = Propel::getConnection(WinLoseResultPeer::DATABASE_NAME, Propel::CONNECTION_READ);<br />
$query = &#8216;SELECT  c.member_id AS custom_column<br />
FROM tb_winlose_result c<br />
left join tb_winlose_result l ON l.member_id=c.member_id<br />
&#8216;;</p>
<p>$this-&gt;statement = $connection-&gt;prepare($query);</p>
<p>$this-&gt;pager = new statementPager(null, 10);<br />
$this-&gt;pager-&gt;setStatement($this-&gt;statement);<br />
$this-&gt;pager-&gt;setPage($request-&gt;getParameter(&#8216;page&#8217;, 1));<br />
$this-&gt;pager-&gt;init();</p>
<p>The template i use is as below:<br />
getResults() as $resultset): ?&gt;<br />
  custom_column ?&gt;</p>
<p>Any help is really appreciated, thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Closer To The Ideal &#187; Blog Archive &#187; Pagination for results when you've written a raw SQL query in Symfony</title>
		<link>http://arpeggios.wordpress.com/2009/02/02/enabling-pagination-with-raw-sql-queries/#comment-70</link>
		<dc:creator>Closer To The Ideal &#187; Blog Archive &#187; Pagination for results when you've written a raw SQL query in Symfony</dc:creator>
		<pubDate>Mon, 02 Mar 2009 08:01:25 +0000</pubDate>
		<guid isPermaLink="false">http://arpeggios.wordpress.com/?p=584#comment-70</guid>
		<description>[...] This would have been very handy, had I known it then: Whatever you use, Propel or Doctrine, it is sometimes needed to write raw SQL queries. [...]</description>
		<content:encoded><![CDATA[<p>[...] This would have been very handy, had I known it then: Whatever you use, Propel or Doctrine, it is sometimes needed to write raw SQL queries. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kevin McGlynn</title>
		<link>http://arpeggios.wordpress.com/2009/02/02/enabling-pagination-with-raw-sql-queries/#comment-61</link>
		<dc:creator>Kevin McGlynn</dc:creator>
		<pubDate>Sun, 08 Feb 2009 01:12:22 +0000</pubDate>
		<guid isPermaLink="false">http://arpeggios.wordpress.com/?p=584#comment-61</guid>
		<description>brilliant... am taking this and running with it.  This will help me get around Doctrine&#039;s missing offset() implementation in SQL Server.</description>
		<content:encoded><![CDATA[<p>brilliant&#8230; am taking this and running with it.  This will help me get around Doctrine&#8217;s missing offset() implementation in SQL Server.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
