<?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>Digital Base - Blog &#187; snippet</title>
	<atom:link href="http://www.digitalbase.eu/blog/tag/snippet/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.digitalbase.eu/blog</link>
	<description>A blog about webdesign, PHP, development and IT</description>
	<lastBuildDate>Mon, 10 May 2010 16:16:55 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Symfony / Propel &#8211; Subquerys</title>
		<link>http://www.digitalbase.eu/blog/symfony-propel-subquerys/</link>
		<comments>http://www.digitalbase.eu/blog/symfony-propel-subquerys/#comments</comments>
		<pubDate>Mon, 04 Feb 2008 17:47:12 +0000</pubDate>
		<dc:creator>Bart Vanderstukken</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[propel]]></category>
		<category><![CDATA[snippet]]></category>
		<category><![CDATA[symfony]]></category>

		<guid isPermaLink="false">http://dibav3.gnelisse.desktop01/blog/?p=30</guid>
		<description><![CDATA[To reduce the query count in your web application, you might consider using subqueries. Propel has a way to do that.]]></description>
			<content:encoded><![CDATA[<p>
To reduce the query count in your web application, you might consider using subqueries. I&#39;ll show you howto do that in propel/symfony :
</p>
<p>[code]propel - subqueries[/code]</p>
<p>
It&#39;s that easy <img src='http://www.digitalbase.eu/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.digitalbase.eu/blog/symfony-propel-subquerys/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Simplifying Queries: Using sum, count, etc in Propel</title>
		<link>http://www.digitalbase.eu/blog/simplifying-queries-using-sum-count-etc-in-propel/</link>
		<comments>http://www.digitalbase.eu/blog/simplifying-queries-using-sum-count-etc-in-propel/#comments</comments>
		<pubDate>Sat, 02 Feb 2008 17:43:59 +0000</pubDate>
		<dc:creator>Bart Vanderstukken</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[propel]]></category>
		<category><![CDATA[snippet]]></category>

		<guid isPermaLink="false">http://dibav3.gnelisse.desktop01/blog/?p=21</guid>
		<description><![CDATA[Using database functions like sum, count, etc in propel. A small explanation.]]></description>
			<content:encoded><![CDATA[<p>Simplifying Queries: Using sum, count, etc in Propel</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$c</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>addSelectColumn<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'sum('</span><span style="color: #339933;">.</span>dbTimeBlockPeer<span style="color: #339933;">::</span><span style="color: #004000;">TOTAL</span><span style="color: #339933;">.</span><span style="color: #0000ff;">') as total'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$rs</span> <span style="color: #339933;">=</span> dbTimeBlockPeer<span style="color: #339933;">::</span><span style="color: #004000;">doSelectRS</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$c</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$rs</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>next<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000088;">$total</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$rs</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>getInt<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span></pre></div></div>

<p>So, simply use addSelectColumn. You have to work with the ResultSet offcourse, since you won&#8217;t be able to populateObjects.</p>
<p>In this case you can simply use &#8216;1&#8242; in getInt(column index), since we&#8217;re sure only one column is being fetched. Note that the index starts at 1 and not at 0.</p>
<p>Now, imagine a case where you are not sure what the index is (it could also change in the project&#8217;s life cycle). Then you can use, dbTimeBlockPeer::translateFieldName(dbTimeBlockPeer::TOTAL, BasePeer::TYPE_COLNAME, BasePeer::TYPE_NUM)), which will return the position of column &#8216;total&#8217;.</p>
<p>This needs no explanation, but I&#8217;ll give it anyway: translateFieldName accepts as first argument a string (source), the source type name and the destination type name. You can go and look in the basePeer which type you need.</p>
<p>basedbTimeBlockPeer (generated by Propel)</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">private</span> <span style="color: #990000;">static</span> <span style="color: #000088;">$fieldNames</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span> <span style="color: #009900;">&#40;</span> BasePeer<span style="color: #339933;">::</span><span style="color: #004000;">TYPE_PHPNAME</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Id'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'UserId'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'ProjectId'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Ticketnr'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Changeset'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Description'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'TimeIn'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'TimeOut'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Total'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> BasePeer<span style="color: #339933;">::</span><span style="color: #004000;">TYPE_COLNAME</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span> <span style="color: #009900;">&#40;</span>dbTimeBlockPeer<span style="color: #339933;">::</span><span style="color: #004000;">ID</span><span style="color: #339933;">,</span> dbTimeBlockPeer<span style="color: #339933;">::</span><span style="color: #004000;">USER_ID</span><span style="color: #339933;">,</span> dbTimeBlockPeer<span style="color: #339933;">::</span><span style="color: #004000;">PROJECT_ID</span><span style="color: #339933;">,</span> dbTimeBlockPeer<span style="color: #339933;">::</span><span style="color: #004000;">TICKETNR</span><span style="color: #339933;">,</span> dbTimeBlockPeer<span style="color: #339933;">::</span><span style="color: #004000;">CHANGESET</span><span style="color: #339933;">,</span> dbTimeBlockPeer<span style="color: #339933;">::</span><span style="color: #004000;">DESCRIPTION</span><span style="color: #339933;">,</span> dbTimeBlockPeer<span style="color: #339933;">::</span><span style="color: #004000;">TIME_IN</span><span style="color: #339933;">,</span> dbTimeBlockPeer<span style="color: #339933;">::</span><span style="color: #004000;">TIME_OUT</span><span style="color: #339933;">,</span> dbTimeBlockPeer<span style="color: #339933;">::</span><span style="color: #004000;">TOTAL</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> BasePeer<span style="color: #339933;">::</span><span style="color: #004000;">TYPE_FIELDNAME</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'id'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'user_id'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'project_id'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'ticketnr'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'changeset'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'description'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'time_in'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'time_out'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'total'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> BasePeer<span style="color: #339933;">::</span><span style="color: #004000;">TYPE_NUM</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">6</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">7</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">8</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.digitalbase.eu/blog/simplifying-queries-using-sum-count-etc-in-propel/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
