<?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/"
	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>Pi</title>
	<atom:link href="http://darrylpye.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://darrylpye.wordpress.com</link>
	<description>Hopefully not just navel gazing</description>
	<lastBuildDate>Mon, 22 Mar 2010 04:50:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='darrylpye.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Pi</title>
		<link>http://darrylpye.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://darrylpye.wordpress.com/osd.xml" title="Pi" />
	<atom:link rel='hub' href='http://darrylpye.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Joining Arrays in Postgres Sql</title>
		<link>http://darrylpye.wordpress.com/2010/02/09/joining-arrays-in-postgres-sql/</link>
		<comments>http://darrylpye.wordpress.com/2010/02/09/joining-arrays-in-postgres-sql/#comments</comments>
		<pubDate>Tue, 09 Feb 2010 04:51:08 +0000</pubDate>
		<dc:creator>rqmedes</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://darrylpye.wordpress.com/?p=32</guid>
		<description><![CDATA[Here is a handy way of getting the distinct product of one or more arrays in postgres. SELECT Distinct unnest(array_cat(ARRAY[1,2,3], ARRAY[1,2,4,5])) anyarray: concatenate two arrays unnest: expand an array to a set of rows Results will be 1,2,3,4,5.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=darrylpye.wordpress.com&amp;blog=10010126&amp;post=32&amp;subd=darrylpye&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Here is a handy way of getting the distinct product of one or more arrays in postgres.</p>
<p><strong>SELECT Distinct unnest(array_cat(ARRAY[1,2,3], ARRAY[1,2,4,5]))</strong></p>
<p>anyarray:	concatenate two arrays</p>
<p>unnest:      expand an array to a set of rows</p>
<p>Results will be</p>
<p>1,2,3,4,5.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/darrylpye.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/darrylpye.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/darrylpye.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/darrylpye.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/darrylpye.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/darrylpye.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/darrylpye.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/darrylpye.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/darrylpye.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/darrylpye.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/darrylpye.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/darrylpye.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/darrylpye.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/darrylpye.wordpress.com/32/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=darrylpye.wordpress.com&amp;blog=10010126&amp;post=32&amp;subd=darrylpye&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://darrylpye.wordpress.com/2010/02/09/joining-arrays-in-postgres-sql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fc005cb7ede00ab17dda867b8ba666e8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">rqmedes</media:title>
		</media:content>
	</item>
		<item>
		<title>Upsert, Merge Postgres</title>
		<link>http://darrylpye.wordpress.com/2010/01/15/upsert-merge-postgres/</link>
		<comments>http://darrylpye.wordpress.com/2010/01/15/upsert-merge-postgres/#comments</comments>
		<pubDate>Fri, 15 Jan 2010 02:47:58 +0000</pubDate>
		<dc:creator>rqmedes</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://darrylpye.wordpress.com/?p=48</guid>
		<description><![CDATA[Postgres doesn&#8217;t have  UPSERT or ON DUPLICATE KEY functionality  so if you want to perform an update  if not exists insert in one statement you need to write a merge function. The manual provides a  good example. CREATE TABLE db (a INT PRIMARY KEY, b TEXT); CREATE FUNCTION merge_db(key INT, data TEXT) RETURNS VOID AS [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=darrylpye.wordpress.com&amp;blog=10010126&amp;post=48&amp;subd=darrylpye&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Postgres doesn&#8217;t have  UPSERT or ON DUPLICATE KEY functionality  so if you want to perform an update  if not exists insert in one statement you need to write a merge function.</p>
<p>The manual provides a  good <a href="http://www.postgresql.org/docs/current/static/plpgsql-control-structures.html#PLPGSQL-UPSERT-EXAMPLE">example.</a></p>
<pre class="PROGRAMLISTING">CREATE TABLE db (a INT PRIMARY KEY, b TEXT);

CREATE FUNCTION merge_db(key INT, data TEXT) RETURNS VOID AS
$$
BEGIN
    LOOP
        -- first try to update the key
        UPDATE db SET b = data WHERE a = key;
        IF found THEN
            RETURN;
        END IF;
        -- not there, so try to insert the key
        -- if someone else inserts the same key concurrently,
        -- we could get a unique-key failure
        BEGIN
            INSERT INTO db(a,b) VALUES (key, data);
            RETURN;
        EXCEPTION WHEN unique_violation THEN
            -- do nothing, and loop to try the UPDATE again
        END;
    END LOOP;
END;
$$
LANGUAGE plpgsql;

SELECT merge_db(1, 'david');
SELECT merge_db(1, 'dennis');</pre>
<p>However  this can become time consuming to write on large/many  tables.</p>
<p>Here is a function that will generate a  merge function skeleton for your tables</p>
<p>First create a text aggregate.</p>
<pre>CREATE AGGREGATE textcat_all(
  basetype    = text,
  sfunc       = textcat,
  stype       = text,
  initcond    = ''
);
</pre>
<p>And here is the function.</p>
<pre>CREATE OR REPLACE FUNCTION admin.table_merge(_name text)
RETURNS text AS
$BODY$
Declare sql text;
Declare fsql text;
Declare isql text;
Declare usql text;
Declare psql text;
     BEGIN
	sql = 'Create or replace function admin.merge_'  || _name || '('; 

	SELECT INTO fsql,usql,isql,psql
	        textcat_all(('_'|| column_name || ' ' || data_type) || ', '),
	        textcat_all((column_name || '= _' || column_name) || ', '),
	        textcat_all((column_name) || ', '),
	        textcat_all(('_' || column_name) || ', ')
	FROM information_schema.columns
	WHERE  table_name = _name;

	sql = sql || substring(fsql, 0, length(fsql)-1) || ') RETURNS VOID AS
	$MERGE$
	BEGIN
	   LOOP
	      UPDATE ' || _name || ' SET ' || substring(usql, 0, length(usql)-1) ||  ' Where id = _id; '
	  || ' IF FOUND THEN
	          RETURN;
	      END IF; '
	  || 'BEGIN
	      INSERT INTO ' || _name || '(' || substring(isql, 0, length(isql)-1) || ') Values
	      (' || substring(psql, 0, length(psql)-1) || ');
	      RETURN;
	      EXCEPTION WHEN unique_violation THEN
	      END;
	   END LOOP;
	END;
	$MERGE$
	LANGUAGE ''plpgsql''
        COST 100;';
	return sql;
     END;
$BODY$
  LANGUAGE 'plpgsql'
  COST 100;
</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/darrylpye.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/darrylpye.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/darrylpye.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/darrylpye.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/darrylpye.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/darrylpye.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/darrylpye.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/darrylpye.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/darrylpye.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/darrylpye.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/darrylpye.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/darrylpye.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/darrylpye.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/darrylpye.wordpress.com/48/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=darrylpye.wordpress.com&amp;blog=10010126&amp;post=48&amp;subd=darrylpye&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://darrylpye.wordpress.com/2010/01/15/upsert-merge-postgres/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fc005cb7ede00ab17dda867b8ba666e8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">rqmedes</media:title>
		</media:content>
	</item>
		<item>
		<title>.net C#4   Dynamics,  cool but slow</title>
		<link>http://darrylpye.wordpress.com/2010/01/04/net-c4-dynamic-object-is-slow/</link>
		<comments>http://darrylpye.wordpress.com/2010/01/04/net-c4-dynamic-object-is-slow/#comments</comments>
		<pubDate>Mon, 04 Jan 2010 10:58:13 +0000</pubDate>
		<dc:creator>rqmedes</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://darrylpye.wordpress.com/2010/03/20/net-c4-dynamic-object-is-slow/</guid>
		<description><![CDATA[Recently I have been playing with DynamicObjects one of the new features in C# 4.0. DynamicObjects once extended allows you to specifying dynamic behavior at run time. By overriding the  TryGetMember and TrySetMember method you can dynamically add and remove properties. dynamic person = new DynamicClass; person.Name = &#8220;John Smith&#8221;; person.Phone = &#8220;32345690&#8243;; By overriding [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=darrylpye.wordpress.com&amp;blog=10010126&amp;post=55&amp;subd=darrylpye&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Recently I have been playing with <strong>DynamicObjects</strong> one of the new features in C# 4.0.<br />
DynamicObjects once extended allows you to specifying dynamic behavior at run time.<br /></br><br />
By overriding the  <strong>TryGetMember</strong> and <strong>TrySetMember</strong> method you can dynamically add and remove properties.<br /></br><br />
dynamic person = new DynamicClass;</br><br />
person.Name = &#8220;John Smith&#8221;;</br><br />
person.Phone = &#8220;32345690&#8243;;</br></p>
<p>By overriding the <strong>TrySetIndex</strong> and <strong>TryGetIndex</strong> you can access properties you don&#8217;t know about at compile time.<br />
dynamic person = new DynamicClass;<br />
person["Name"] = &#8220;John Smith&#8221;;</p>
<p>A basic implementation.</p>
<pre style='line-height:19px;color:#3366FF;font:11px "Lucida Sans Unicode";'>
public class DynamicClass : DynamicObject
{
        public Dictionary _dictionary = new Dictionary();

        public override bool TryGetMember(GetMemberBinder binder, out object result)
        {
            return _dictionary.TryGetValue(binder.Name, out result);
        }

        public override bool TrySetMember(SetMemberBinder binder, object value)
        {
            _dictionary[binder.Name] = value;
            return true;
        }

        public override bool TrySetIndex(
            SetIndexBinder binder, object[] indexes, object value)
        {
            if (dictionary.ContainsKey((string)indexes[0]))
                _dictionary[(string)indexes[0]] = value;
            else
                _dictionary.Add((string)indexes[0], value);
            return true;
        }
        public override bool TryGetIndex(
            GetIndexBinder binder, object[] indexes, out object result)
        {
            return _dictionary.TryGetValue((string)indexes[0], out result);
        }
}
</pre>
<p>I found a nice implementation on <a href="http://blogs.msdn.com/davidebb/archive/2009/10/23/using-c-dynamic-to-call-static-members.aspx">David Ebbo&#8217;s blog</a>.<br /> He is using dynamic to simplify data  access by writing a wrapper for SQL queries.</p>
<p>I particularly like the Yield return within the data connection. I was at first concerned about this leaving open connections but used correctly connections area automatically cleaned up for you, <a href="http://stackoverflow.com/questions/47521/using-yield-to-iterate-over-a-datareader-might-not-close-the-connection"> check this out</a>.</p>
<p>It all works well however it runs really slow. I would be wary of using dynamic if  performance is a consideration.<br />
I will post benchmarks soon.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/darrylpye.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/darrylpye.wordpress.com/55/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/darrylpye.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/darrylpye.wordpress.com/55/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/darrylpye.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/darrylpye.wordpress.com/55/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/darrylpye.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/darrylpye.wordpress.com/55/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/darrylpye.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/darrylpye.wordpress.com/55/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/darrylpye.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/darrylpye.wordpress.com/55/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/darrylpye.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/darrylpye.wordpress.com/55/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=darrylpye.wordpress.com&amp;blog=10010126&amp;post=55&amp;subd=darrylpye&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://darrylpye.wordpress.com/2010/01/04/net-c4-dynamic-object-is-slow/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fc005cb7ede00ab17dda867b8ba666e8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">rqmedes</media:title>
		</media:content>
	</item>
		<item>
		<title>Unit Testing Postgres</title>
		<link>http://darrylpye.wordpress.com/2009/11/14/unit-testing-postgres/</link>
		<comments>http://darrylpye.wordpress.com/2009/11/14/unit-testing-postgres/#comments</comments>
		<pubDate>Sat, 14 Nov 2009 11:55:42 +0000</pubDate>
		<dc:creator>rqmedes</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://darrylpye.wordpress.com/?p=36</guid>
		<description><![CDATA[I  have been using  Pg_Unit  to create unit tests for  my  latest postgres database application. You can get PG_Unit from here  http://en.dklab.ru/lib/dklab_pgunit/ Pg_unit is pretty bare bones  allowing you to basically  assert values are the same and as the the  forums are in Russian it is hard to find any further information. I find it [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=darrylpye.wordpress.com&amp;blog=10010126&amp;post=36&amp;subd=darrylpye&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I  have been using  Pg_Unit  to create unit tests for  my  latest postgres database application.<br />
You can get PG_Unit from here  <a href="http://en.dklab.ru/lib/dklab_pgunit/">http://en.dklab.ru/lib/dklab_pgunit/</a></p>
<p>Pg_unit is pretty bare bones  allowing you to basically  assert values are the same and as the the  forums are in Russian it is hard to find any further information.</p>
<p>I find it useful to write tests for all my validation logic, checks and constraints. This is useful when you  have lots of tables and data validation checks.</p>
<p>A basic example:</p>
<p><span style="color:#3366ff;"><em>insert into inventory(code) values (&#8216;a&#8221;);<br />
PERFORM   pgunit.assert_fail(&#8216;insert into inventory(code) values (&#8221;a&#8221;);&#8217;);</em></span></p>
<p>which  inserts a record and then asserts that the same  record cannot be inserted again.</p>
<p>As pg_unit runs all the  tests within a transaction that is rolled back none of your test code will affect your data.</p>
<p>Here is the function to assert failures.</p>
<pre style="padding-left:30px;"><span style="color:#3366ff;">CREATE OR REPLACE FUNCTION pgunit.assert_fail(sql_statement text)
     RETURNS void AS
$BODY$
DECLARE ok boolean;
BEGIN
      BEGIN
            ok := false;
            execute  $1;
       EXCEPTION
       WHEN Others THEN
            ok := true;
       END;
       IF ok is false THEN
             PERFORM pgunit.fail('Should have Failed');
       END IF;
END;
$BODY$
LANGUAGE 'plpgsql' VOLATILE
COST 100;</span></pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/darrylpye.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/darrylpye.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/darrylpye.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/darrylpye.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/darrylpye.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/darrylpye.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/darrylpye.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/darrylpye.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/darrylpye.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/darrylpye.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/darrylpye.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/darrylpye.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/darrylpye.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/darrylpye.wordpress.com/36/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=darrylpye.wordpress.com&amp;blog=10010126&amp;post=36&amp;subd=darrylpye&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://darrylpye.wordpress.com/2009/11/14/unit-testing-postgres/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fc005cb7ede00ab17dda867b8ba666e8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">rqmedes</media:title>
		</media:content>
	</item>
		<item>
		<title>TryParse Shorthand</title>
		<link>http://darrylpye.wordpress.com/2009/11/08/tryparse-shorthand/</link>
		<comments>http://darrylpye.wordpress.com/2009/11/08/tryparse-shorthand/#comments</comments>
		<pubDate>Sun, 08 Nov 2009 04:48:04 +0000</pubDate>
		<dc:creator>rqmedes</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://darrylpye.wordpress.com/?p=71</guid>
		<description><![CDATA[Because A property, indexer or dynamic member access may not be passed as an out or ref parameter TryParse can be annoying. Here is the syntax I use to make it simpler. int i; Id = int.TryParse(&#8220;10&#8243;,out i) ? i : 0;<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=darrylpye.wordpress.com&amp;blog=10010126&amp;post=71&amp;subd=darrylpye&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Because A property, indexer or dynamic member access may not be passed as an out or ref parameter TryParse can be annoying.<br />
Here is the syntax I use to make it simpler.</p>
<p><span style="color:#3366ff;">int</span> i;<br />
Id = <span style="color:#3366ff;">int</span>.TryParse(&#8220;10&#8243;,<span style="color:#3366ff;">out</span> i) ? i : 0;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/darrylpye.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/darrylpye.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/darrylpye.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/darrylpye.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/darrylpye.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/darrylpye.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/darrylpye.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/darrylpye.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/darrylpye.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/darrylpye.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/darrylpye.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/darrylpye.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/darrylpye.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/darrylpye.wordpress.com/71/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=darrylpye.wordpress.com&amp;blog=10010126&amp;post=71&amp;subd=darrylpye&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://darrylpye.wordpress.com/2009/11/08/tryparse-shorthand/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fc005cb7ede00ab17dda867b8ba666e8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">rqmedes</media:title>
		</media:content>
	</item>
		<item>
		<title>Postgres Paginations</title>
		<link>http://darrylpye.wordpress.com/2009/10/29/postgres-paginations/</link>
		<comments>http://darrylpye.wordpress.com/2009/10/29/postgres-paginations/#comments</comments>
		<pubDate>Thu, 29 Oct 2009 06:07:44 +0000</pubDate>
		<dc:creator>rqmedes</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://darrylpye.wordpress.com/2009/11/22/postgres-paginations/</guid>
		<description><![CDATA[As a follow up on pagination in MSSQL the pagination technique also works in postgres. Pagination in MSSQL with total number of records. although it is alot simpler in postgres SELECT * , count(*) OVER()as total from &#8220;Table&#8221; limit 20 OFFSET 10<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=darrylpye.wordpress.com&amp;blog=10010126&amp;post=27&amp;subd=darrylpye&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>As a follow up on pagination in MSSQL   the pagination technique also works in postgres.</p>
<p><a href="http://darrylpye.wordpress.com/2009/10/23/sql-server-pagination-with-total-number-of-records/">Pagination in MSSQL with total number of records.</a></p>
<p>although it is alot simpler in postgres<br />
SELECT * , count(*) OVER()as total from &#8220;Table&#8221;   limit 20 OFFSET 10</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/darrylpye.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/darrylpye.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/darrylpye.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/darrylpye.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/darrylpye.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/darrylpye.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/darrylpye.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/darrylpye.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/darrylpye.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/darrylpye.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/darrylpye.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/darrylpye.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/darrylpye.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/darrylpye.wordpress.com/27/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=darrylpye.wordpress.com&amp;blog=10010126&amp;post=27&amp;subd=darrylpye&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://darrylpye.wordpress.com/2009/10/29/postgres-paginations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fc005cb7ede00ab17dda867b8ba666e8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">rqmedes</media:title>
		</media:content>
	</item>
		<item>
		<title>Sql Server Pagination With Total Number of Records</title>
		<link>http://darrylpye.wordpress.com/2009/10/23/sql-server-pagination-with-total-number-of-records/</link>
		<comments>http://darrylpye.wordpress.com/2009/10/23/sql-server-pagination-with-total-number-of-records/#comments</comments>
		<pubDate>Fri, 23 Oct 2009 01:00:38 +0000</pubDate>
		<dc:creator>rqmedes</dc:creator>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[Pagination]]></category>

		<guid isPermaLink="false">http://darrylpye.wordpress.com/?p=21</guid>
		<description><![CDATA[Pagination is  easy in most scenarios You usually handle it in code letting your favourite  ORM such as NHibernate  take  care of it for you. There are times when you are required to hand-roll your own sql which is as simple as SELECT * FROM &#60;Table&#62;  WHERE &#60;Criteria&#62; LIMIT 0, 10 or for SQL Server [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=darrylpye.wordpress.com&amp;blog=10010126&amp;post=21&amp;subd=darrylpye&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>Pagination</strong> is  easy in most scenarios</p>
<p>You usually handle it in code letting your favourite  ORM such as NHibernate  take  care of it for you.<br />
There are times when you are required to hand-roll your own sql which is as simple as</p>
<p><span style="color:#3366ff;">SELECT * FROM &lt;Table&gt;  WHERE &lt;Criteria&gt;  LIMIT 0, 10 </span></p>
<p><span style="color:#3366ff;"> </span></p>
<p>or for SQL Server</p>
<p><span style="color:#3366ff;">ROW_NUMBER() OVER (ORDER BY &lt;Column&gt;) AS RowNumber</span></p>
<p>But this doesn&#8217;t  return the total number of  records,  important for  presenting   <em>&#8216;Page 1 of 380</em>&#8216;.<br />
I assume  most would  do an additional sql call.</p>
<p><span style="color:#3366ff;">SELECT  COUNT(*)  FROM  &lt;Table&gt;  WHERE &lt;Criteria&gt;<br />
</span></p>
<p>In SQL Server it is easy to get both in one query.</p>
<p><span style="color:#3366ff;">WITH </span>Results <span style="color:#3366ff;">AS</span> (<br />
<span style="color:#3366ff;">SELECT</span> <span style="color:#ff00ff;">ROW_NUMBER()</span> <span style="color:#3366ff;">OVER</span> (<span style="color:#3366ff;">ORDER BY</span> &lt;Column&gt;) <span style="color:#3366ff;">AS</span> RowNumber,<br />
<span style="color:#ff00ff;">ROW_NUMBER()</span> <span style="color:#3366ff;">OVER</span> (<span style="color:#3366ff;">ORDER BY</span> &lt;Column&gt; <span style="color:#3366ff;">DESC</span>)  <span style="color:#3366ff;">AS</span> RowNumberDesc,<br />
* <span style="color:#3366ff;">FROM</span> &lt;Table&gt;<br />
<span style="color:#3366ff;">WHERE</span> &lt;Criteria&gt;)<br />
<span style="color:#3366ff;">SELECT</span> * <span style="color:#3366ff;">FROM </span>Results  <span style="color:#3366ff;">WHERE </span>RowNumber <span style="color:#808080;">BETWEEN </span>&lt;Start&gt; <span style="color:#808080;">AND </span>&lt;End&gt;</p>
<p>This will return the results  between &lt;Start&gt; and  &lt;End&gt;  ordered by &lt;Column&gt;.<br />
You can  get the Total Number of records  by adding the &lt;Start&gt; value to the  RowNumberDesc  value of the first record returned.<br />
Preliminary benchmarking shows that it performs faster than running the two queries method.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/darrylpye.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/darrylpye.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/darrylpye.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/darrylpye.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/darrylpye.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/darrylpye.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/darrylpye.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/darrylpye.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/darrylpye.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/darrylpye.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/darrylpye.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/darrylpye.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/darrylpye.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/darrylpye.wordpress.com/21/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=darrylpye.wordpress.com&amp;blog=10010126&amp;post=21&amp;subd=darrylpye&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://darrylpye.wordpress.com/2009/10/23/sql-server-pagination-with-total-number-of-records/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fc005cb7ede00ab17dda867b8ba666e8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">rqmedes</media:title>
		</media:content>
	</item>
		<item>
		<title>Protecting your MVC Model with anonymous types</title>
		<link>http://darrylpye.wordpress.com/2009/08/14/hello-world/</link>
		<comments>http://darrylpye.wordpress.com/2009/08/14/hello-world/#comments</comments>
		<pubDate>Fri, 14 Aug 2009 12:01:14 +0000</pubDate>
		<dc:creator>rqmedes</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Linq]]></category>
		<category><![CDATA[MVC]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Anonymous classes can be a great way to protect your models from being polluted by any view specific requirements. Lets say you have a Product model that you want to present as a list in a table. You now want to add some extra information to present any pre selected items. By creating an anonymous [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=darrylpye.wordpress.com&amp;blog=10010126&amp;post=1&amp;subd=darrylpye&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Anonymous classes can be a great way to protect your models from being polluted by any view specific requirements.<br />
Lets say you have a Product model that you want to present as a list in a table.</p>
<p><img class="alignnone size-full wp-image-15" title="super1" src="http://darrylpye.files.wordpress.com/2009/10/super1.jpg" alt="super1" width="528" height="220" /></p>
<p>You now want to add some extra information to present any pre selected items.<br />
By creating an anonymous type you can easily extend your product to add the additional information, Selected.</p>
<p style="padding-left:30px;">e.g<br />
var test = new { Product = product, Selected = true};</p>
<p>Combining this with Linq makes it easy to return a list that contains the products and any other information required by the view engine</p>
<p style="padding-left:30px;"><span style="color:#3366ff;">var</span> selectedId = 3;<br />
<span style="color:#3366ff;">var</span> products = (<span style="color:#3366ff;">from</span> p <span style="color:#3366ff;">in</span> _productRepository.GetAll()<br />
<span style="color:#3366ff;">select</span> new { Product = p, Selected = p.Id == selectedId });</p>
<p>This will set selected as  true for the product with the Id of 3.</p>
<p><img class="alignnone size-full wp-image-14" title="Super2" src="http://darrylpye.files.wordpress.com/2009/10/super2.jpg" alt="Super2" width="531" height="217" /></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/darrylpye.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/darrylpye.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/darrylpye.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/darrylpye.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/darrylpye.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/darrylpye.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/darrylpye.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/darrylpye.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/darrylpye.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/darrylpye.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/darrylpye.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/darrylpye.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/darrylpye.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/darrylpye.wordpress.com/1/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=darrylpye.wordpress.com&amp;blog=10010126&amp;post=1&amp;subd=darrylpye&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://darrylpye.wordpress.com/2009/08/14/hello-world/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fc005cb7ede00ab17dda867b8ba666e8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">rqmedes</media:title>
		</media:content>

		<media:content url="http://darrylpye.files.wordpress.com/2009/10/super1.jpg" medium="image">
			<media:title type="html">super1</media:title>
		</media:content>

		<media:content url="http://darrylpye.files.wordpress.com/2009/10/super2.jpg" medium="image">
			<media:title type="html">Super2</media:title>
		</media:content>
	</item>
	</channel>
</rss>
