<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<link rel="self" href="/Atom/" />
	<id>http://billmill.org/</id>
	<title>My Name Rhymes</title>
	<subtitle>Bill Mill blogs irregularly</subtitle>
	<updated>2008-02-16T17:45:47Z</updated>
	<author>
		<name>Bill Mill</name>
		<email>bill.mill@gmail.com</email>
		<uri>http://billmill.org/</uri>
	</author>
	<link href="http://billmill.org/" />
	<entry>
		<title>DNA on Programming</title>
		<link href="http://billmill.org/dna.html" />	
		<id>http://billmill.org/dna.html</id>
		<updated>2008-02-16T17:45:47Z</updated>
		<summary type="html">&lt;blockquote&gt;"Well, what we called a computer in 1977 was really a kind of electric abacus, but..."&lt;p&gt;
"Oh, now, don't underestimate the abacus," said Reg. "In skilled hands it's a very sophisticated calculating device. Furthermore it requires no power, can be made with any materials you have to hand, and never goes bing in the middle of an important piece of work."&lt;p&gt;
"So an electric one would be particularly pointless," said Richard.&lt;p&gt;
"True enough," conceded Reg.&lt;p&gt;
"There really wasn't a lot this machine could do that you couldn't do yourself in half the time with a lot less trouble," said Richard, "but it was, on the other hand, very good at being a slow and dim-witted pupil."&lt;p&gt;
Reg looked at him quizzically.&lt;p&gt;
"I had no idea they were in such short supply," he said. "I could hit a dozen of them with a bread roll from where I'm sitting."&lt;p&gt;
"I'm sure. But look at it this way. What really is the point of trying to teach anything to anybody?"&lt;p&gt;
This question seemed to provoke a murmur of sympathetic approval from up and down the table. &lt;p&gt;
    Richard continued, "What I mean is that if you really want to understand something, the best way is to try and explain it to someone else. That forces you to sort it out in your own mind. And the more slow and dim-witted your pupil, the more you have to break things down into more and more simple ideas. And that's really the essence of programming. By the time you've sorted out a complicated idea into little steps that even a stupid machine can deal with, you've certainly learned something about it yourself. The teacher usually learns more than the pupil. Isn't that true?"&lt;p&gt;
    "It would be hard to learn much less than my pupils," came a low growl from somewhere on the table, "without undergoing a pre-frontal lobotomy."&lt;p&gt;
    "So I used to spend days struggling to write essays on this 16K machine that would have taken a couple of hours on a typewriter, but what was fascinating to me was the process of trying to explain to the machine what it was I wanted it to do. I virtually wrote my own word processor in BASIC. A simple search and replace routine would take about three hours."&lt;p&gt;
    "I forget, did you ever get any essays done at all?"&lt;p&gt;
    "Well, not as such. No actual essays, but the reasons why not were absolutely fascinating. For instance, I discovered that..."&lt;p&gt;
    He broke off, laughing at himself.&lt;/blockquote&gt;
-&lt;a href="http://www.amazon.com/Dirk-Gentlys-Holistic-Detective-Agency/dp/0671746723"&gt;DNA&lt;/a&gt;
</summary>
		<content type="html">&lt;blockquote&gt;"Well, what we called a computer in 1977 was really a kind of electric abacus, but..."&lt;p&gt;
"Oh, now, don't underestimate the abacus," said Reg. "In skilled hands it's a very sophisticated calculating device. Furthermore it requires no power, can be made with any materials you have to hand, and never goes bing in the middle of an important piece of work."&lt;p&gt;
"So an electric one would be particularly pointless," said Richard.&lt;p&gt;
"True enough," conceded Reg.&lt;p&gt;
"There really wasn't a lot this machine could do that you couldn't do yourself in half the time with a lot less trouble," said Richard, "but it was, on the other hand, very good at being a slow and dim-witted pupil."&lt;p&gt;
Reg looked at him quizzically.&lt;p&gt;
"I had no idea they were in such short supply," he said. "I could hit a dozen of them with a bread roll from where I'm sitting."&lt;p&gt;
"I'm sure. But look at it this way. What really is the point of trying to teach anything to anybody?"&lt;p&gt;
This question seemed to provoke a murmur of sympathetic approval from up and down the table. &lt;p&gt;
    Richard continued, "What I mean is that if you really want to understand something, the best way is to try and explain it to someone else. That forces you to sort it out in your own mind. And the more slow and dim-witted your pupil, the more you have to break things down into more and more simple ideas. And that's really the essence of programming. By the time you've sorted out a complicated idea into little steps that even a stupid machine can deal with, you've certainly learned something about it yourself. The teacher usually learns more than the pupil. Isn't that true?"&lt;p&gt;
    "It would be hard to learn much less than my pupils," came a low growl from somewhere on the table, "without undergoing a pre-frontal lobotomy."&lt;p&gt;
    "So I used to spend days struggling to write essays on this 16K machine that would have taken a couple of hours on a typewriter, but what was fascinating to me was the process of trying to explain to the machine what it was I wanted it to do. I virtually wrote my own word processor in BASIC. A simple search and replace routine would take about three hours."&lt;p&gt;
    "I forget, did you ever get any essays done at all?"&lt;p&gt;
    "Well, not as such. No actual essays, but the reasons why not were absolutely fascinating. For instance, I discovered that..."&lt;p&gt;
    He broke off, laughing at himself.&lt;/blockquote&gt;
-&lt;a href="http://www.amazon.com/Dirk-Gentlys-Holistic-Detective-Agency/dp/0671746723"&gt;DNA&lt;/a&gt;
</content>
	</entry>
	<entry>
		<title>Iterating Over Database Results in C#</title>
		<link href="http://billmill.org/iterate_over_database.html" />	
		<id>http://billmill.org/iterate_over_database.html</id>
		<updated>2007-12-17T01:13:00Z</updated>
		<summary type="html">&lt;p&gt;At my job, we use what is essentially a custom C# ORM. Soon after I arrived, 
we adopted this idiom to pull a DB connection from the pool and run a query:
&lt;div class="highlight"&gt;&lt;pre&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Something&lt;/span&gt;
&lt;span class="k"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;ourIdiom&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;long&lt;/span&gt; &lt;span class="n"&gt;identifier&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;DBConnection&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;DBConnection&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
        &lt;span class="k"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;IDataReader&lt;/span&gt; &lt;span class="n"&gt;rec&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;execQuery&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;@&amp;quot;&lt;/span&gt;
&lt;span class="s"&gt;                SELECT some, rows&lt;/span&gt;
&lt;span class="s"&gt;                FROM  Table1 t1, Table2 t2&lt;/span&gt;
&lt;span class="s"&gt;                WHERE t1.t2id = t2.id&lt;/span&gt;
&lt;span class="s"&gt;                AND   t1.id = ?&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="n"&gt;identifier&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
            &lt;span class="k"&gt;{&lt;/span&gt;
                &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rec&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Read&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
                    &lt;span class="n"&gt;doSomething&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
                &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="k"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Which is nice because it disposes of both the connection and the dataReader 
properly on failure, but ugly because it uses a whole bunch of boilerplate.  
Unfortunately, because doSomething() needs to execute inside both 
&lt;code&gt;using&lt;/code&gt; statements, and we weren't using C# 2.0 until a few months 
ago, the only way to avoid the boilerplate would have been to pass in 
delegates.
&lt;p&gt;This would have been just as ugly as keeping the boilerplate in the code, so 
we stuck with the using&lt;sup&gt;2&lt;/sup&gt; idiom.
&lt;p&gt;Since our switchover to 2.0 a few months ago, I've had an idea that I could 
make this idiom more concise and remove some boilerplate that I didn't get a 
chance to try until this week. Using 2.0's iterators, which seem awfully 
familiar from my python work, that can be reduced to:
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Something&lt;/span&gt;
&lt;span class="k"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;ourIdiom&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;long&lt;/span&gt; &lt;span class="n"&gt;identifier&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;IDataReader&lt;/span&gt; &lt;span class="n"&gt;rec&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;SQL&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;Query&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;@&amp;quot;&lt;/span&gt;
&lt;span class="s"&gt;            SELECT some, rows&lt;/span&gt;
&lt;span class="s"&gt;            FROM  Table1 t1, Table2 t2&lt;/span&gt;
&lt;span class="s"&gt;            WHERE t1.t2id = t2.id&lt;/span&gt;
&lt;span class="s"&gt;            AND   t1.id = ?&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;identifier&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
        &lt;span class="k"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;doSomething&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="k"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;With some fairly simple code:
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;SQL&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; 
    &lt;span class="n"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Collections&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Generic&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;IEnumerable&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;IDataReader&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="k"&gt;{&lt;/span&gt;
        &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;m_sql&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;ArrayList&lt;/span&gt; &lt;span class="n"&gt;m_sqlparams&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;SQL&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="k"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;}&lt;/span&gt;

        &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="n"&gt;SQL&lt;/span&gt; &lt;span class="nf"&gt;query&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;sql&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;params&lt;/span&gt; &lt;span class="kt"&gt;object&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;sqlparams&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;m_sql&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;sql&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="n"&gt;m_sqlparams&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;ArrayList&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sqlparams&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;}&lt;/span&gt;

        &lt;span class="n"&gt;IEnumerator&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;IDataReader&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;IEnumerable&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;IDataReader&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;.&lt;/span&gt;&lt;span class="n"&gt;GetEnumerator&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="k"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;clsDBConnection&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;clsDBConnection&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;m_dbname&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
            &lt;span class="k"&gt;{&lt;/span&gt;
                &lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;IDataReader&lt;/span&gt; &lt;span class="n"&gt;rec&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;execQuery&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;m_sql&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;m_sqlparams&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
                &lt;span class="k"&gt;{&lt;/span&gt;
                    &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rec&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Read&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
                        &lt;span class="n"&gt;yield&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;rec&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                &lt;span class="k"&gt;}&lt;/span&gt;
            &lt;span class="k"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;}&lt;/span&gt;

        &lt;span class="c"&gt;//this is required because IEnumerable&amp;lt;&amp;gt; inherits IEnumerable. bleh.&lt;/span&gt;
        &lt;span class="n"&gt;IEnumerator&lt;/span&gt; &lt;span class="n"&gt;IEnumerable&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;GetEnumerator&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;{&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;GetEnumerator&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;This code should come in handy for more reasons than just its cleanliness.  
First off, if you ever need to change the idiom for accessing the DB, it's 
stored conveniently in one place.
&lt;p&gt;Second, It makes a prepared SQL call into something like a &lt;a 
href="http://en.wikipedia.org/wiki/Thunk"&gt;thunk&lt;/a&gt;: a bit of code representing 
a future computation that can then be passed around to be performed later. An 
example:
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;setUpQueries&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;nameId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;addressId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;custId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;List&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;SQL&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;stringsWeNeed&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;List&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="kt"&gt;object&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="k"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;SQL&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;query&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;SELECT name FROM names WHERE id=?&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;nameId&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;SQL&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;query&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;SELECT addy FROM addresses WHERE id=?&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;addressId&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;SQL&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;query&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;SELECT zip FROM customers WHERE id=?&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;custId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="n"&gt;List&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;strings&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;getOurStrings&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;stringsWeNeed&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="n"&gt;mangleStrings&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;strings&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;List&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;getOurStrings&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;List&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;SQL&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;queries&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;List&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;strings&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;List&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;();&lt;/span&gt;
    &lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;SQL&lt;/span&gt; &lt;span class="n"&gt;query&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;queries&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;IDataReader&lt;/span&gt; &lt;span class="n"&gt;rec&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;query&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;strings&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rec&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;GetString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
    &lt;span class="k"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;strings&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;While the example is silly, this property can be exploited to seperate 
declaration from execution, which I often find to be a useful pattern.
&lt;p&gt;Though I am far from the &lt;a 
href="http://www.base4.net/blog.aspx?ID=409"&gt;first person&lt;/a&gt; to discover this 
simplification, I did figure it out on my own and I thought it was neat enough 
to share.
&lt;p&gt;A quick disclaimer: the code here is modified from the original to remove 
some details, and is completely untested, and probably doesn't compile.  You 
may, however, use it or distribute it as you see fit; it's licensed under the 
&lt;a href="http://sam.zoy.org/wtfpl/"&gt;wtfpl&lt;/a&gt;.
&lt;p&gt;UPDATE: added the while(rec.Read()), which I'd forgotten
</summary>
		<content type="html">&lt;p&gt;At my job, we use what is essentially a custom C# ORM. Soon after I arrived, 
we adopted this idiom to pull a DB connection from the pool and run a query:
&lt;div class="highlight"&gt;&lt;pre&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Something&lt;/span&gt;
&lt;span class="k"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;ourIdiom&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;long&lt;/span&gt; &lt;span class="n"&gt;identifier&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;DBConnection&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;DBConnection&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
        &lt;span class="k"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;IDataReader&lt;/span&gt; &lt;span class="n"&gt;rec&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;execQuery&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;@&amp;quot;&lt;/span&gt;
&lt;span class="s"&gt;                SELECT some, rows&lt;/span&gt;
&lt;span class="s"&gt;                FROM  Table1 t1, Table2 t2&lt;/span&gt;
&lt;span class="s"&gt;                WHERE t1.t2id = t2.id&lt;/span&gt;
&lt;span class="s"&gt;                AND   t1.id = ?&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="n"&gt;identifier&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
            &lt;span class="k"&gt;{&lt;/span&gt;
                &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rec&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Read&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
                    &lt;span class="n"&gt;doSomething&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
                &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="k"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Which is nice because it disposes of both the connection and the dataReader 
properly on failure, but ugly because it uses a whole bunch of boilerplate.  
Unfortunately, because doSomething() needs to execute inside both 
&lt;code&gt;using&lt;/code&gt; statements, and we weren't using C# 2.0 until a few months 
ago, the only way to avoid the boilerplate would have been to pass in 
delegates.
&lt;p&gt;This would have been just as ugly as keeping the boilerplate in the code, so 
we stuck with the using&lt;sup&gt;2&lt;/sup&gt; idiom.
&lt;p&gt;Since our switchover to 2.0 a few months ago, I've had an idea that I could 
make this idiom more concise and remove some boilerplate that I didn't get a 
chance to try until this week. Using 2.0's iterators, which seem awfully 
familiar from my python work, that can be reduced to:
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Something&lt;/span&gt;
&lt;span class="k"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;ourIdiom&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;long&lt;/span&gt; &lt;span class="n"&gt;identifier&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;IDataReader&lt;/span&gt; &lt;span class="n"&gt;rec&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;SQL&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;Query&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;@&amp;quot;&lt;/span&gt;
&lt;span class="s"&gt;            SELECT some, rows&lt;/span&gt;
&lt;span class="s"&gt;            FROM  Table1 t1, Table2 t2&lt;/span&gt;
&lt;span class="s"&gt;            WHERE t1.t2id = t2.id&lt;/span&gt;
&lt;span class="s"&gt;            AND   t1.id = ?&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;identifier&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
        &lt;span class="k"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;doSomething&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="k"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;With some fairly simple code:
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;SQL&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; 
    &lt;span class="n"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Collections&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Generic&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;IEnumerable&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;IDataReader&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="k"&gt;{&lt;/span&gt;
        &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;m_sql&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;ArrayList&lt;/span&gt; &lt;span class="n"&gt;m_sqlparams&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;SQL&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="k"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;}&lt;/span&gt;

        &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="n"&gt;SQL&lt;/span&gt; &lt;span class="nf"&gt;query&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;sql&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;params&lt;/span&gt; &lt;span class="kt"&gt;object&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;sqlparams&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;m_sql&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;sql&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="n"&gt;m_sqlparams&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;ArrayList&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sqlparams&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;}&lt;/span&gt;

        &lt;span class="n"&gt;IEnumerator&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;IDataReader&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;IEnumerable&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;IDataReader&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;.&lt;/span&gt;&lt;span class="n"&gt;GetEnumerator&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="k"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;clsDBConnection&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;clsDBConnection&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;m_dbname&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
            &lt;span class="k"&gt;{&lt;/span&gt;
                &lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;IDataReader&lt;/span&gt; &lt;span class="n"&gt;rec&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;execQuery&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;m_sql&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;m_sqlparams&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
                &lt;span class="k"&gt;{&lt;/span&gt;
                    &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rec&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Read&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
                        &lt;span class="n"&gt;yield&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;rec&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                &lt;span class="k"&gt;}&lt;/span&gt;
            &lt;span class="k"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;}&lt;/span&gt;

        &lt;span class="c"&gt;//this is required because IEnumerable&amp;lt;&amp;gt; inherits IEnumerable. bleh.&lt;/span&gt;
        &lt;span class="n"&gt;IEnumerator&lt;/span&gt; &lt;span class="n"&gt;IEnumerable&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;GetEnumerator&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;{&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;GetEnumerator&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;This code should come in handy for more reasons than just its cleanliness.  
First off, if you ever need to change the idiom for accessing the DB, it's 
stored conveniently in one place.
&lt;p&gt;Second, It makes a prepared SQL call into something like a &lt;a 
href="http://en.wikipedia.org/wiki/Thunk"&gt;thunk&lt;/a&gt;: a bit of code representing 
a future computation that can then be passed around to be performed later. An 
example:
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;setUpQueries&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;nameId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;addressId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;custId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;List&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;SQL&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;stringsWeNeed&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;List&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="kt"&gt;object&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="k"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;SQL&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;query&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;SELECT name FROM names WHERE id=?&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;nameId&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;SQL&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;query&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;SELECT addy FROM addresses WHERE id=?&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;addressId&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;SQL&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;query&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;SELECT zip FROM customers WHERE id=?&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;custId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="n"&gt;List&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;strings&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;getOurStrings&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;stringsWeNeed&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="n"&gt;mangleStrings&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;strings&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;List&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;getOurStrings&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;List&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;SQL&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;queries&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;List&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;strings&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;List&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;();&lt;/span&gt;
    &lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;SQL&lt;/span&gt; &lt;span class="n"&gt;query&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;queries&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;IDataReader&lt;/span&gt; &lt;span class="n"&gt;rec&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;query&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;strings&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rec&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;GetString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
    &lt;span class="k"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;strings&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;While the example is silly, this property can be exploited to seperate 
declaration from execution, which I often find to be a useful pattern.
&lt;p&gt;Though I am far from the &lt;a 
href="http://www.base4.net/blog.aspx?ID=409"&gt;first person&lt;/a&gt; to discover this 
simplification, I did figure it out on my own and I thought it was neat enough 
to share.
&lt;p&gt;A quick disclaimer: the code here is modified from the original to remove 
some details, and is completely untested, and probably doesn't compile.  You 
may, however, use it or distribute it as you see fit; it's licensed under the 
&lt;a href="http://sam.zoy.org/wtfpl/"&gt;wtfpl&lt;/a&gt;.
&lt;p&gt;UPDATE: added the while(rec.Read()), which I'd forgotten
</content>
	</entry>
	<entry>
		<title>Why Applications Suck (Part 1)</title>
		<link href="http://billmill.org/why_apps_suck.html" />	
		<id>http://billmill.org/why_apps_suck.html</id>
		<updated>2007-08-24T01:50:00Z</updated>
		<summary type="html">Why do people outside of corporations overwhelmingly use webmail instead of 
email clients? Long before rich email clients like gmail were available, people 
have flocked to the internet email client - messaging has been the killer 
feature of the web for a long time now.&lt;p&gt;
But why?&lt;p&gt;
The answer is simple: Overwhelmingly, users do not want to install programs, 
and users do not want their data stored on their computer. In that order of 
importance.&lt;p&gt;
&lt;h2&gt;Users Don't Want to Install Programs&lt;/h2&gt;&lt;p&gt;
Let's examine the process of getting a popular, free, email client like &lt;a 
href="http://www.mozilla.com/en-US/thunderbird/"&gt;Thunderbird&lt;/a&gt; installed. To 
do so, imagine that we're instructing our kindly aunt Tilly how to install 
it.&lt;p&gt;
Now Tilly is no old fogie, she's been using Microsoft Word at work for over a 
decade now, and she knows her way around msn.com. However, she just decided to 
strike out looking for a new job, and wants to finally use that personal email 
address that came with her cable internet. She's got us trapped on the phone, 
and "we know computers", so here's roughly what we'll tell her to do:&lt;p&gt;
&lt;ol&gt;&lt;li&gt;type google.com in the address bar
&lt;li&gt;type in "thunderbird"; press enter
&lt;li&gt;click on the first result
&lt;li&gt;click on "Download Thunderbird"
&lt;li&gt;click "OK"
&lt;li&gt;choose a place to save it (Just use the desktop, Tilly!)
&lt;li&gt;minimize the browser
&lt;li&gt;hunt for the file named "Thunderbird"
&lt;/ol&gt;&lt;p&gt;

And, ohmigod, we're not even close to done. She's still got to run the 
installer (3-4 clicks minimum), which involves selecting an installation 
directory (a what?), then open the program, open the tools -&gt; accounts menu 
option, find the documentation for her service provider's email tools, copy 
them into the "add new account" wizard (another 3-4 clicks) where appropriate, 
remember her user name and password, and then download all the email she's had 
sitting there since she hasn't checked it ever.&lt;p&gt;
Now, finally, she's ready to use her email client. It's just that easy!&lt;p&gt;
Let's compare the process for getting her up and running with gmail:&lt;p&gt;
&lt;ol&gt;&lt;li&gt;type "gmail.com" in the address bar
&lt;li&gt;click on "sign up for gmail"
&lt;li&gt;fill out a form (a task she probably knows how to do)
&lt;li&gt;click on "I accept. Create my account."
&lt;/ol&gt;&lt;p&gt;
Now, Tilly may not be the most technological mind around, but she's also no 
dummy. I know which one I'd rather direct her to do.&lt;p&gt;
Desktop application install is a problem.&lt;p&gt;
&lt;h2&gt;Do We Even Want to Fix This?&lt;/h2&gt;
Many web 2.0-savvy types will tell us that this isn't a big deal. In the 
future, all of our applications should be inside our browser, and to speak 
otherwise is heresy!  The desktop is dead! Sure, Javascript + Json + the 
browser has limitations, but those restrictions are liberating! Get used to it, 
or perish!&lt;/p&gt;
Well, bah humbug. Here's what's good about the web: The easy posting, viewing, 
and navigating of documents described by URIs.&lt;p&gt;
That's it.&lt;p&gt;
Let me repeat it for clarity: The web, in your browser, is &lt;em&gt;only really good 
at&lt;/em&gt; sending discrete data, displaying discrete documents and navigating in between 
them.&lt;p&gt;
Phew.&lt;p&gt;
The whole paradigm is absolutely superb at getting this job done. The system of 
hyperlinks, URIs, DNS, and HTTP over TCP/IP is the greatest achievement that 
computer programmers have achieved, a massive global effort that has managed to  
stay amazingly open and coherent. It "Just Works" enough to change the way 
information is distributed, businesses are run and even how society is 
structured.&lt;p&gt;
Anything amenable to being represented as discrete visual documents has taken 
to the internet like a duck to water. Chief among them is email; check out the 
&lt;a href="http://www.alexa.com/site/ds/top_sites?ts_mode=global&amp;lang=none"&gt;top 
100 global&lt;/a&gt; Alexa websites and see how many "social networks" in how many 
languages are in the top 100. Sites displaying news (documents), photographs 
(documents), videos (strictly as documents), and information about software 
(documents) make up most of the rest.&lt;p&gt;
What's left among those 100 is the elephant in the room; the Killer Internet 
Application: search. Even Microsoft's lame search engine finds its way into the 
top 100 because people will do whatever they need to in order to search the 
web; it's the only way to get an effective handle on the information in the 
Great Hyperlinked Mass. I believe it's the exception to my "web is only good at 
documents" theory that proves the rule.&lt;p&gt;
&lt;h2&gt;Search Works, so Let's Put All our Apps On the Web&lt;/h2&gt;
Since the web gained massive worldwide popularity in the mid-1990s, an enormous 
amount of effort has been spent on making the browser into an application 
development platform.  The Great Mozilla Rewrite basically shut that browser 
down between 1998 and 2002 in order to make it an application platform.  
Microsoft developed activeX, Sun pushed Java applets as the solution, Adobe 
developed SVG, and Macromedia developed its Flash player.&lt;p&gt;
Nowadays, Firefox is pushing &amp;lt;canvas&amp;gt;, Microsoft has released 
Silverlight, Macromedia has become Adobe, and Flash is the only one of the 
first generation technologies still breathing oxygen as a development 
platform.&lt;p&gt;
Furthermore, with the invention of Google Gears, &lt;a 
href="http://joyeur.com/2007/03/22/joyent-slingshot"&gt;Joyent Slingshot&lt;/a&gt;, the 
aforementioned Silverlight, or Adobe Air, you might soon be able to (gasp) save 
files to the host computer! That's right, in 10 years we've almost gotten to 
the point where a program running in a browser can save a file on your hard 
drive and read it when you're offline.&lt;p&gt;
The problem is that, fundamentally, a browser is &lt;em&gt;still&lt;/em&gt; only good at 
one thing: documents. Its whole paradigm is set up that way. What does the 
"back button" mean when you're playing a game of asteroids? What does "home" 
mean while you're editing a photo? Does an address bar on an mp3 player need to 
be so &lt;em&gt;in your face&lt;/em&gt;?&lt;p&gt;
&lt;h2&gt;We Can Fix This&lt;/h2&gt;
So, instead of shoehorning our applications inside of the browser window 
because it's convenient, let's do something radical: bring our "real software" 
applications into the modern age of the internet.&lt;p&gt;
In the &lt;a href="why_apps_suck2.html"&gt;next article&lt;/a&gt;, we'll talk about how 
software installation came to suck so 
badly, with an eye towards how to go about bringing it up to the web era.&lt;p&gt;
</summary>
		<content type="html">Why do people outside of corporations overwhelmingly use webmail instead of 
email clients? Long before rich email clients like gmail were available, people 
have flocked to the internet email client - messaging has been the killer 
feature of the web for a long time now.&lt;p&gt;
But why?&lt;p&gt;
The answer is simple: Overwhelmingly, users do not want to install programs, 
and users do not want their data stored on their computer. In that order of 
importance.&lt;p&gt;
&lt;h2&gt;Users Don't Want to Install Programs&lt;/h2&gt;&lt;p&gt;
Let's examine the process of getting a popular, free, email client like &lt;a 
href="http://www.mozilla.com/en-US/thunderbird/"&gt;Thunderbird&lt;/a&gt; installed. To 
do so, imagine that we're instructing our kindly aunt Tilly how to install 
it.&lt;p&gt;
Now Tilly is no old fogie, she's been using Microsoft Word at work for over a 
decade now, and she knows her way around msn.com. However, she just decided to 
strike out looking for a new job, and wants to finally use that personal email 
address that came with her cable internet. She's got us trapped on the phone, 
and "we know computers", so here's roughly what we'll tell her to do:&lt;p&gt;
&lt;ol&gt;&lt;li&gt;type google.com in the address bar
&lt;li&gt;type in "thunderbird"; press enter
&lt;li&gt;click on the first result
&lt;li&gt;click on "Download Thunderbird"
&lt;li&gt;click "OK"
&lt;li&gt;choose a place to save it (Just use the desktop, Tilly!)
&lt;li&gt;minimize the browser
&lt;li&gt;hunt for the file named "Thunderbird"
&lt;/ol&gt;&lt;p&gt;

And, ohmigod, we're not even close to done. She's still got to run the 
installer (3-4 clicks minimum), which involves selecting an installation 
directory (a what?), then open the program, open the tools -&gt; accounts menu 
option, find the documentation for her service provider's email tools, copy 
them into the "add new account" wizard (another 3-4 clicks) where appropriate, 
remember her user name and password, and then download all the email she's had 
sitting there since she hasn't checked it ever.&lt;p&gt;
Now, finally, she's ready to use her email client. It's just that easy!&lt;p&gt;
Let's compare the process for getting her up and running with gmail:&lt;p&gt;
&lt;ol&gt;&lt;li&gt;type "gmail.com" in the address bar
&lt;li&gt;click on "sign up for gmail"
&lt;li&gt;fill out a form (a task she probably knows how to do)
&lt;li&gt;click on "I accept. Create my account."
&lt;/ol&gt;&lt;p&gt;
Now, Tilly may not be the most technological mind around, but she's also no 
dummy. I know which one I'd rather direct her to do.&lt;p&gt;
Desktop application install is a problem.&lt;p&gt;
&lt;h2&gt;Do We Even Want to Fix This?&lt;/h2&gt;
Many web 2.0-savvy types will tell us that this isn't a big deal. In the 
future, all of our applications should be inside our browser, and to speak 
otherwise is heresy!  The desktop is dead! Sure, Javascript + Json + the 
browser has limitations, but those restrictions are liberating! Get used to it, 
or perish!&lt;/p&gt;
Well, bah humbug. Here's what's good about the web: The easy posting, viewing, 
and navigating of documents described by URIs.&lt;p&gt;
That's it.&lt;p&gt;
Let me repeat it for clarity: The web, in your browser, is &lt;em&gt;only really good 
at&lt;/em&gt; sending discrete data, displaying discrete documents and navigating in between 
them.&lt;p&gt;
Phew.&lt;p&gt;
The whole paradigm is absolutely superb at getting this job done. The system of 
hyperlinks, URIs, DNS, and HTTP over TCP/IP is the greatest achievement that 
computer programmers have achieved, a massive global effort that has managed to  
stay amazingly open and coherent. It "Just Works" enough to change the way 
information is distributed, businesses are run and even how society is 
structured.&lt;p&gt;
Anything amenable to being represented as discrete visual documents has taken 
to the internet like a duck to water. Chief among them is email; check out the 
&lt;a href="http://www.alexa.com/site/ds/top_sites?ts_mode=global&amp;lang=none"&gt;top 
100 global&lt;/a&gt; Alexa websites and see how many "social networks" in how many 
languages are in the top 100. Sites displaying news (documents), photographs 
(documents), videos (strictly as documents), and information about software 
(documents) make up most of the rest.&lt;p&gt;
What's left among those 100 is the elephant in the room; the Killer Internet 
Application: search. Even Microsoft's lame search engine finds its way into the 
top 100 because people will do whatever they need to in order to search the 
web; it's the only way to get an effective handle on the information in the 
Great Hyperlinked Mass. I believe it's the exception to my "web is only good at 
documents" theory that proves the rule.&lt;p&gt;
&lt;h2&gt;Search Works, so Let's Put All our Apps On the Web&lt;/h2&gt;
Since the web gained massive worldwide popularity in the mid-1990s, an enormous 
amount of effort has been spent on making the browser into an application 
development platform.  The Great Mozilla Rewrite basically shut that browser 
down between 1998 and 2002 in order to make it an application platform.  
Microsoft developed activeX, Sun pushed Java applets as the solution, Adobe 
developed SVG, and Macromedia developed its Flash player.&lt;p&gt;
Nowadays, Firefox is pushing &amp;lt;canvas&amp;gt;, Microsoft has released 
Silverlight, Macromedia has become Adobe, and Flash is the only one of the 
first generation technologies still breathing oxygen as a development 
platform.&lt;p&gt;
Furthermore, with the invention of Google Gears, &lt;a 
href="http://joyeur.com/2007/03/22/joyent-slingshot"&gt;Joyent Slingshot&lt;/a&gt;, the 
aforementioned Silverlight, or Adobe Air, you might soon be able to (gasp) save 
files to the host computer! That's right, in 10 years we've almost gotten to 
the point where a program running in a browser can save a file on your hard 
drive and read it when you're offline.&lt;p&gt;
The problem is that, fundamentally, a browser is &lt;em&gt;still&lt;/em&gt; only good at 
one thing: documents. Its whole paradigm is set up that way. What does the 
"back button" mean when you're playing a game of asteroids? What does "home" 
mean while you're editing a photo? Does an address bar on an mp3 player need to 
be so &lt;em&gt;in your face&lt;/em&gt;?&lt;p&gt;
&lt;h2&gt;We Can Fix This&lt;/h2&gt;
So, instead of shoehorning our applications inside of the browser window 
because it's convenient, let's do something radical: bring our "real software" 
applications into the modern age of the internet.&lt;p&gt;
In the &lt;a href="why_apps_suck2.html"&gt;next article&lt;/a&gt;, we'll talk about how 
software installation came to suck so 
badly, with an eye towards how to go about bringing it up to the web era.&lt;p&gt;
</content>
	</entry>
	<entry>
		<title>MySQL Partial Dump</title>
		<link href="http://billmill.org/mysqldump_n.html" />	
		<id>http://billmill.org/mysqldump_n.html</id>
		<updated>2007-08-17T00:05:00Z</updated>
		<summary type="html">At work, I'm trying to bring our testing from its current ad-hoc state into 
something more useful. Priority #1 at the moment is making what limited 
test suite we have into a practical, repeatable test of our main code 
library.&lt;p&gt;
To do so, however, I need to create script to import a useful subset of the 
data from our nine gigabyte MySQL production database into a local 
database.  Unfortunately, mysqldump seems not to support the export of only 
N rows from a database table, and neither does there seem to be a standard 
way to do so. In fact, there seems to be no standard way to &lt;a 
href="http://forums.mysql.com/read.php?20,159999,159999"&gt;automatically 
generate  insert queries&lt;/a&gt;, so it's not even possible to hack it with 
OUTFILE tricks.&lt;p&gt;
Indeed, a quick look look at the mysqldump &lt;a 
href="http://mysql.bkbits.net:8080/mysql-5.2/client/mysqldump.c?PAGE=anno&amp;REV=%2b"&gt;source 
code&lt;/a&gt; shows that it just constructs a query of the form: "SELECT * FROM 
&lt;em&gt;table&lt;/em&gt; [WHERE &lt;em&gt;condition&lt;/em&gt;] [ORDER BY &lt;em&gt;field&lt;/em&gt;]":&lt;p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;dynstr_append_checked(&lt;span style="font-weight: bold"&gt;&amp;amp;&lt;/span&gt;query_string, 
    &lt;span style="color: #bb8844"&gt;&amp;quot;SELECT /*!40001 SQL_NO_CACHE */ * FROM &amp;quot;&lt;/span&gt;);
dynstr_append_checked(&lt;span style="font-weight: bold"&gt;&amp;amp;&lt;/span&gt;query_string, result_table);

&lt;span style="font-weight: bold"&gt;if&lt;/span&gt; (where)
{
  &lt;span style="color: #999988; font-style: italic"&gt;/* snip */&lt;/span&gt;
  dynstr_append_checked(&lt;span style="font-weight: bold"&gt;&amp;amp;&lt;/span&gt;query_string, &lt;span style="color: #bb8844"&gt;&amp;quot; WHERE &amp;quot;&lt;/span&gt;);
  dynstr_append_checked(&lt;span style="font-weight: bold"&gt;&amp;amp;&lt;/span&gt;query_string, where);
}
&lt;span style="font-weight: bold"&gt;if&lt;/span&gt; (order_by)
{
  &lt;span style="color: #999988; font-style: italic"&gt;/* snip */&lt;/span&gt;
  dynstr_append_checked(&lt;span style="font-weight: bold"&gt;&amp;amp;&lt;/span&gt;query_string, &lt;span style="color: #bb8844"&gt;&amp;quot; ORDER BY &amp;quot;&lt;/span&gt;);
  dynstr_append_checked(&lt;span style="font-weight: bold"&gt;&amp;amp;&lt;/span&gt;query_string, order_by);
}
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;
And then pieces together an insert string manually:&lt;p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span style="font-weight: bold"&gt;while&lt;/span&gt; ((row&lt;span style="font-weight: bold"&gt;=&lt;/span&gt; mysql_fetch_row(res)))
{
&lt;span style="color: #999988; font-style: italic"&gt;/* snip */&lt;/span&gt;
  &lt;span style="font-weight: bold"&gt;for&lt;/span&gt; (i&lt;span style="font-weight: bold"&gt;=&lt;/span&gt; &lt;span style="color: #009999"&gt;0&lt;/span&gt;; i &lt;span style="font-weight: bold"&gt;&amp;lt;&lt;/span&gt; mysql_num_fields(res); i&lt;span style="font-weight: bold"&gt;++&lt;/span&gt;)
  {
    &lt;span style="color: #999988; font-style: italic"&gt;/* snip */&lt;/span&gt;
    &lt;span style="font-weight: bold"&gt;if&lt;/span&gt; (row[i])
    {
      &lt;span style="font-weight: bold"&gt;if&lt;/span&gt; (&lt;span style="font-weight: bold"&gt;!&lt;/span&gt;IS_NUM_FIELD(field))
      {
        &lt;span style="color: #999988; font-style: italic"&gt;/* snip */&lt;/span&gt;
        unescape(md_result_file, row[i], length);
        &lt;span style="color: #999988; font-style: italic"&gt;/* snip */&lt;/span&gt;
      }
      &lt;span style="font-weight: bold"&gt;else&lt;/span&gt;
      {
        &lt;span style="color: #999988; font-style: italic"&gt;/* change any strings (&amp;quot;inf&amp;quot;, &amp;quot;-inf&amp;quot;, &amp;quot;nan&amp;quot;) into NULL */&lt;/span&gt;
        &lt;span style="color: #445588; font-weight: bold"&gt;char&lt;/span&gt; &lt;span style="font-weight: bold"&gt;*&lt;/span&gt;ptr&lt;span style="font-weight: bold"&gt;=&lt;/span&gt; row[i];
        &lt;span style="color: #999988; font-style: italic"&gt;/* snip */&lt;/span&gt;
        &lt;span style="font-weight: bold"&gt;else&lt;/span&gt; &lt;span style="font-weight: bold"&gt;if&lt;/span&gt; (my_isalpha(charset_info, &lt;span style="font-weight: bold"&gt;*&lt;/span&gt;ptr) &lt;span style="font-weight: bold"&gt;||&lt;/span&gt;
                 (&lt;span style="font-weight: bold"&gt;*&lt;/span&gt;ptr &lt;span style="font-weight: bold"&gt;==&lt;/span&gt; &lt;span style="color: #bb8844"&gt;&amp;#39;-&amp;#39;&lt;/span&gt; &lt;span style="font-weight: bold"&gt;&amp;amp;&amp;amp;&lt;/span&gt; my_isalpha(charset_info, ptr[&lt;span style="color: #009999"&gt;1&lt;/span&gt;])))
          fputs(&lt;span style="color: #bb8844"&gt;&amp;quot;NULL&amp;quot;&lt;/span&gt;, md_result_file);
        &lt;span style="font-weight: bold"&gt;else&lt;/span&gt; &lt;span style="color: #990000; font-weight: bold"&gt;if&lt;/span&gt; (field&lt;span style="font-weight: bold"&gt;-&amp;gt;&lt;/span&gt;type &lt;span style="font-weight: bold"&gt;==&lt;/span&gt; MYSQL_TYPE_DECIMAL)
        {
          &lt;span style="color: #999988; font-style: italic"&gt;/* add &amp;quot; signs around */&lt;/span&gt;
          fputc(&lt;span style="color: #bb8844"&gt;&amp;#39;\&amp;#39;&amp;#39;&lt;/span&gt;, md_result_file);
          fputs(ptr, md_result_file);
          fputc(&lt;span style="color: #bb8844"&gt;&amp;#39;\&amp;#39;&amp;#39;&lt;/span&gt;, md_result_file);
        }
        &lt;span style="font-weight: bold"&gt;else&lt;/span&gt;
          fputs(ptr, md_result_file);
      }
    }
  }
}
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;
So, rather than deal with hacking the rather baroque C (in a proprietary 
source control that I've never used, no less) to add another option to 
limit output rows, I threw together a little python function that uses &lt;a 
href="http://sourceforge.net/projects/mysql-python"&gt;MySQLdb&lt;/a&gt; to do what 
I want:
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span style="color: #bb8844"&gt;&amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
&lt;span style="color: #bb8844"&gt;get_n_rows retrieves n rows from a given table on MySQLdb connection conn&lt;/span&gt;

&lt;span style="color: #bb8844"&gt;conn:  open MySQLdb connection object&lt;/span&gt;
&lt;span style="color: #bb8844"&gt;table: string; name of the table which we are generating queries for&lt;/span&gt;
&lt;span style="color: #bb8844"&gt;n:     int; number of rows to output from table&lt;/span&gt;

&lt;span style="color: #bb8844"&gt;Legal kwargs:&lt;/span&gt;
&lt;span style="color: #bb8844"&gt;    reverse: bool; whether to return rows in reverse order (requires idCol)&lt;/span&gt;
&lt;span style="color: #bb8844"&gt;    idCol:   string; results will be sorted on this column if reverse is &lt;/span&gt;
&lt;span style="color: #bb8844"&gt;             True&lt;/span&gt;
&lt;span style="color: #bb8844"&gt;    where:   string; provides the &amp;quot;where&amp;quot; clause of the select query&lt;/span&gt;
&lt;span style="color: #bb8844"&gt;             NOTE: escape this text yourself! use connection.escape() .&lt;/span&gt;

&lt;span style="color: #bb8844"&gt;Released under WTFPL (http://sam.zoy.org/wtfpl/) - use this code as you &lt;/span&gt;
&lt;span style="color: #bb8844"&gt;wish. Note that it&amp;#39;s not tested at all, and certainly won&amp;#39;t handle blob &lt;/span&gt;
&lt;span style="color: #bb8844"&gt;fields. That said, it worked for my purposes today.&lt;/span&gt;

&lt;span style="color: #bb8844"&gt;bill.mill@gmail.com 8/17/07&lt;/span&gt;
&lt;span style="color: #bb8844"&gt;&amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
&lt;span style="font-weight: bold"&gt;def&lt;/span&gt; &lt;span style="color: #990000; font-weight: bold"&gt;get_n_rows&lt;/span&gt;(conn, table, n, &lt;span style="font-weight: bold"&gt;**&lt;/span&gt;kwargs):
    cur &lt;span style="font-weight: bold"&gt;=&lt;/span&gt; conn&lt;span style="font-weight: bold"&gt;.&lt;/span&gt;cursor()

    &lt;span style="color: #999988; font-style: italic"&gt;#TODO: copy mysqldump&amp;#39;s table escaping function&lt;/span&gt;
    sql &lt;span style="font-weight: bold"&gt;=&lt;/span&gt; &lt;span style="color: #bb8844"&gt;&amp;quot;select * from `%s` &amp;quot;&lt;/span&gt; &lt;span style="font-weight: bold"&gt;%&lt;/span&gt; (table)
    &lt;span style="font-weight: bold"&gt;if&lt;/span&gt; &lt;span style="color: #bb8844"&gt;&amp;quot;where&amp;quot;&lt;/span&gt; &lt;span style="font-weight: bold"&gt;in&lt;/span&gt; kwargs:
        sql &lt;span style="font-weight: bold"&gt;+=&lt;/span&gt; &lt;span style="color: #bb8844"&gt;&amp;quot;where %s &amp;quot;&lt;/span&gt; &lt;span style="font-weight: bold"&gt;%&lt;/span&gt; (kwargs[&lt;span style="color: #bb8844"&gt;&amp;quot;where&amp;quot;&lt;/span&gt;])
    &lt;span style="font-weight: bold"&gt;if&lt;/span&gt; &lt;span style="color: #bb8844"&gt;&amp;quot;reverse&amp;quot;&lt;/span&gt; &lt;span style="font-weight: bold"&gt;in&lt;/span&gt; kwargs &lt;span style="font-weight: bold"&gt;and&lt;/span&gt; kwargs[&lt;span style="color: #bb8844"&gt;&amp;quot;reverse&amp;quot;&lt;/span&gt;]:
        sql &lt;span style="font-weight: bold"&gt;+=&lt;/span&gt; &lt;span style="color: #bb8844"&gt;&amp;quot;order by `%s` desc &amp;quot;&lt;/span&gt; &lt;span style="font-weight: bold"&gt;%&lt;/span&gt; (kwargs[&lt;span style="color: #bb8844"&gt;&amp;quot;idCol&amp;quot;&lt;/span&gt;])
    sql &lt;span style="font-weight: bold"&gt;+=&lt;/span&gt; &lt;span style="color: #bb8844"&gt;&amp;quot;limit %s;&amp;quot;&lt;/span&gt;
    cur&lt;span style="font-weight: bold"&gt;.&lt;/span&gt;execute(sql, (n, ))

    i &lt;span style="font-weight: bold"&gt;=&lt;/span&gt; &lt;span style="color: #009999"&gt;0&lt;/span&gt;
    row &lt;span style="font-weight: bold"&gt;=&lt;/span&gt; cur&lt;span style="font-weight: bold"&gt;.&lt;/span&gt;fetchone()
    insert_stmts &lt;span style="font-weight: bold"&gt;=&lt;/span&gt; [] 
    &lt;span style="font-weight: bold"&gt;while&lt;/span&gt; row &lt;span style="font-weight: bold"&gt;and&lt;/span&gt; i &lt;span style="font-weight: bold"&gt;&amp;lt;&lt;/span&gt; n:
        i &lt;span style="font-weight: bold"&gt;+=&lt;/span&gt; &lt;span style="color: #009999"&gt;1&lt;/span&gt;
        &lt;span style="color: #999988; font-style: italic"&gt;#note that the MySQLdb source suggests that conn.literal is &lt;/span&gt;
        &lt;span style="color: #999988; font-style: italic"&gt;# private; I see no problem with using it, as it just loads the &lt;/span&gt;
        &lt;span style="color: #999988; font-style: italic"&gt;# default escaping functions. Caveat Emptor.&lt;/span&gt;
        strow &lt;span style="font-weight: bold"&gt;=&lt;/span&gt; &lt;span style="color: #bb8844"&gt;&amp;quot;, &amp;quot;&lt;/span&gt;&lt;span style="font-weight: bold"&gt;.&lt;/span&gt;join([conn&lt;span style="font-weight: bold"&gt;.&lt;/span&gt;literal(o) &lt;span style="font-weight: bold"&gt;for&lt;/span&gt; o &lt;span style="font-weight: bold"&gt;in&lt;/span&gt; row])
        insert_stmts&lt;span style="font-weight: bold"&gt;.&lt;/span&gt;append(&lt;span style="color: #bb8844"&gt;&amp;quot;(%s)&amp;quot;&lt;/span&gt; &lt;span style="font-weight: bold"&gt;%&lt;/span&gt; (strow))
        row &lt;span style="font-weight: bold"&gt;=&lt;/span&gt; cur&lt;span style="font-weight: bold"&gt;.&lt;/span&gt;fetchone()

    cur&lt;span style="font-weight: bold"&gt;.&lt;/span&gt;close()
    
    &lt;span style="font-weight: bold"&gt;return&lt;/span&gt; &lt;span style="color: #bb8844"&gt;&amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
&lt;span style="color: #bb8844"&gt;-------- INSERT DATA FOR TABLE %(table)s -----------&lt;/span&gt;
&lt;span style="color: #bb8844"&gt;    &lt;/span&gt;
&lt;span style="color: #bb8844"&gt;    LOCK TABLES `%(table)s` WRITE;&lt;/span&gt;
&lt;span style="color: #bb8844"&gt;    DELETE FROM `%(table)s`;&lt;/span&gt;
&lt;span style="color: #bb8844"&gt;    INSERT INTO `%(table)s` VALUES %(sql)s;&lt;/span&gt;
&lt;span style="color: #bb8844"&gt;    UNLOCK TABLES;&lt;/span&gt;

&lt;span style="color: #bb8844"&gt;-------- END INSERT DATA FOR TABLE %(table)s -----------&lt;/span&gt;
&lt;span style="color: #bb8844"&gt;&amp;quot;&amp;quot;&amp;quot;&lt;/span&gt; &lt;span style="font-weight: bold"&gt;%&lt;/span&gt; {&lt;span style="color: #bb8844"&gt;&amp;quot;table&amp;quot;&lt;/span&gt;: table, &lt;span style="color: #bb8844"&gt;&amp;quot;sql&amp;quot;&lt;/span&gt;: &lt;span style="color: #bb8844"&gt;&amp;quot;,&amp;quot;&lt;/span&gt;&lt;span style="font-weight: bold"&gt;.&lt;/span&gt;join(insert_stmts)}
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;
On a side note, the MySQLdb docs are somewhat hard to track down; I found 
them after some effort &lt;a 
href="http://mysql-python.sourceforge.net/MySQLdb.html"&gt;here&lt;/a&gt;.
</summary>
		<content type="html">At work, I'm trying to bring our testing from its current ad-hoc state into 
something more useful. Priority #1 at the moment is making what limited 
test suite we have into a practical, repeatable test of our main code 
library.&lt;p&gt;
To do so, however, I need to create script to import a useful subset of the 
data from our nine gigabyte MySQL production database into a local 
database.  Unfortunately, mysqldump seems not to support the export of only 
N rows from a database table, and neither does there seem to be a standard 
way to do so. In fact, there seems to be no standard way to &lt;a 
href="http://forums.mysql.com/read.php?20,159999,159999"&gt;automatically 
generate  insert queries&lt;/a&gt;, so it's not even possible to hack it with 
OUTFILE tricks.&lt;p&gt;
Indeed, a quick look look at the mysqldump &lt;a 
href="http://mysql.bkbits.net:8080/mysql-5.2/client/mysqldump.c?PAGE=anno&amp;REV=%2b"&gt;source 
code&lt;/a&gt; shows that it just constructs a query of the form: "SELECT * FROM 
&lt;em&gt;table&lt;/em&gt; [WHERE &lt;em&gt;condition&lt;/em&gt;] [ORDER BY &lt;em&gt;field&lt;/em&gt;]":&lt;p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;dynstr_append_checked(&lt;span style="font-weight: bold"&gt;&amp;amp;&lt;/span&gt;query_string, 
    &lt;span style="color: #bb8844"&gt;&amp;quot;SELECT /*!40001 SQL_NO_CACHE */ * FROM &amp;quot;&lt;/span&gt;);
dynstr_append_checked(&lt;span style="font-weight: bold"&gt;&amp;amp;&lt;/span&gt;query_string, result_table);

&lt;span style="font-weight: bold"&gt;if&lt;/span&gt; (where)
{
  &lt;span style="color: #999988; font-style: italic"&gt;/* snip */&lt;/span&gt;
  dynstr_append_checked(&lt;span style="font-weight: bold"&gt;&amp;amp;&lt;/span&gt;query_string, &lt;span style="color: #bb8844"&gt;&amp;quot; WHERE &amp;quot;&lt;/span&gt;);
  dynstr_append_checked(&lt;span style="font-weight: bold"&gt;&amp;amp;&lt;/span&gt;query_string, where);
}
&lt;span style="font-weight: bold"&gt;if&lt;/span&gt; (order_by)
{
  &lt;span style="color: #999988; font-style: italic"&gt;/* snip */&lt;/span&gt;
  dynstr_append_checked(&lt;span style="font-weight: bold"&gt;&amp;amp;&lt;/span&gt;query_string, &lt;span style="color: #bb8844"&gt;&amp;quot; ORDER BY &amp;quot;&lt;/span&gt;);
  dynstr_append_checked(&lt;span style="font-weight: bold"&gt;&amp;amp;&lt;/span&gt;query_string, order_by);
}
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;
And then pieces together an insert string manually:&lt;p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span style="font-weight: bold"&gt;while&lt;/span&gt; ((row&lt;span style="font-weight: bold"&gt;=&lt;/span&gt; mysql_fetch_row(res)))
{
&lt;span style="color: #999988; font-style: italic"&gt;/* snip */&lt;/span&gt;
  &lt;span style="font-weight: bold"&gt;for&lt;/span&gt; (i&lt;span style="font-weight: bold"&gt;=&lt;/span&gt; &lt;span style="color: #009999"&gt;0&lt;/span&gt;; i &lt;span style="font-weight: bold"&gt;&amp;lt;&lt;/span&gt; mysql_num_fields(res); i&lt;span style="font-weight: bold"&gt;++&lt;/span&gt;)
  {
    &lt;span style="color: #999988; font-style: italic"&gt;/* snip */&lt;/span&gt;
    &lt;span style="font-weight: bold"&gt;if&lt;/span&gt; (row[i])
    {
      &lt;span style="font-weight: bold"&gt;if&lt;/span&gt; (&lt;span style="font-weight: bold"&gt;!&lt;/span&gt;IS_NUM_FIELD(field))
      {
        &lt;span style="color: #999988; font-style: italic"&gt;/* snip */&lt;/span&gt;
        unescape(md_result_file, row[i], length);
        &lt;span style="color: #999988; font-style: italic"&gt;/* snip */&lt;/span&gt;
      }
      &lt;span style="font-weight: bold"&gt;else&lt;/span&gt;
      {
        &lt;span style="color: #999988; font-style: italic"&gt;/* change any strings (&amp;quot;inf&amp;quot;, &amp;quot;-inf&amp;quot;, &amp;quot;nan&amp;quot;) into NULL */&lt;/span&gt;
        &lt;span style="color: #445588; font-weight: bold"&gt;char&lt;/span&gt; &lt;span style="font-weight: bold"&gt;*&lt;/span&gt;ptr&lt;span style="font-weight: bold"&gt;=&lt;/span&gt; row[i];
        &lt;span style="color: #999988; font-style: italic"&gt;/* snip */&lt;/span&gt;
        &lt;span style="font-weight: bold"&gt;else&lt;/span&gt; &lt;span style="font-weight: bold"&gt;if&lt;/span&gt; (my_isalpha(charset_info, &lt;span style="font-weight: bold"&gt;*&lt;/span&gt;ptr) &lt;span style="font-weight: bold"&gt;||&lt;/span&gt;
                 (&lt;span style="font-weight: bold"&gt;*&lt;/span&gt;ptr &lt;span style="font-weight: bold"&gt;==&lt;/span&gt; &lt;span style="color: #bb8844"&gt;&amp;#39;-&amp;#39;&lt;/span&gt; &lt;span style="font-weight: bold"&gt;&amp;amp;&amp;amp;&lt;/span&gt; my_isalpha(charset_info, ptr[&lt;span style="color: #009999"&gt;1&lt;/span&gt;])))
          fputs(&lt;span style="color: #bb8844"&gt;&amp;quot;NULL&amp;quot;&lt;/span&gt;, md_result_file);
        &lt;span style="font-weight: bold"&gt;else&lt;/span&gt; &lt;span style="color: #990000; font-weight: bold"&gt;if&lt;/span&gt; (field&lt;span style="font-weight: bold"&gt;-&amp;gt;&lt;/span&gt;type &lt;span style="font-weight: bold"&gt;==&lt;/span&gt; MYSQL_TYPE_DECIMAL)
        {
          &lt;span style="color: #999988; font-style: italic"&gt;/* add &amp;quot; signs around */&lt;/span&gt;
          fputc(&lt;span style="color: #bb8844"&gt;&amp;#39;\&amp;#39;&amp;#39;&lt;/span&gt;, md_result_file);
          fputs(ptr, md_result_file);
          fputc(&lt;span style="color: #bb8844"&gt;&amp;#39;\&amp;#39;&amp;#39;&lt;/span&gt;, md_result_file);
        }
        &lt;span style="font-weight: bold"&gt;else&lt;/span&gt;
          fputs(ptr, md_result_file);
      }
    }
  }
}
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;
So, rather than deal with hacking the rather baroque C (in a proprietary 
source control that I've never used, no less) to add another option to 
limit output rows, I threw together a little python function that uses &lt;a 
href="http://sourceforge.net/projects/mysql-python"&gt;MySQLdb&lt;/a&gt; to do what 
I want:
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span style="color: #bb8844"&gt;&amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
&lt;span style="color: #bb8844"&gt;get_n_rows retrieves n rows from a given table on MySQLdb connection conn&lt;/span&gt;

&lt;span style="color: #bb8844"&gt;conn:  open MySQLdb connection object&lt;/span&gt;
&lt;span style="color: #bb8844"&gt;table: string; name of the table which we are generating queries for&lt;/span&gt;
&lt;span style="color: #bb8844"&gt;n:     int; number of rows to output from table&lt;/span&gt;

&lt;span style="color: #bb8844"&gt;Legal kwargs:&lt;/span&gt;
&lt;span style="color: #bb8844"&gt;    reverse: bool; whether to return rows in reverse order (requires idCol)&lt;/span&gt;
&lt;span style="color: #bb8844"&gt;    idCol:   string; results will be sorted on this column if reverse is &lt;/span&gt;
&lt;span style="color: #bb8844"&gt;             True&lt;/span&gt;
&lt;span style="color: #bb8844"&gt;    where:   string; provides the &amp;quot;where&amp;quot; clause of the select query&lt;/span&gt;
&lt;span style="color: #bb8844"&gt;             NOTE: escape this text yourself! use connection.escape() .&lt;/span&gt;

&lt;span style="color: #bb8844"&gt;Released under WTFPL (http://sam.zoy.org/wtfpl/) - use this code as you &lt;/span&gt;
&lt;span style="color: #bb8844"&gt;wish. Note that it&amp;#39;s not tested at all, and certainly won&amp;#39;t handle blob &lt;/span&gt;
&lt;span style="color: #bb8844"&gt;fields. That said, it worked for my purposes today.&lt;/span&gt;

&lt;span style="color: #bb8844"&gt;bill.mill@gmail.com 8/17/07&lt;/span&gt;
&lt;span style="color: #bb8844"&gt;&amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
&lt;span style="font-weight: bold"&gt;def&lt;/span&gt; &lt;span style="color: #990000; font-weight: bold"&gt;get_n_rows&lt;/span&gt;(conn, table, n, &lt;span style="font-weight: bold"&gt;**&lt;/span&gt;kwargs):
    cur &lt;span style="font-weight: bold"&gt;=&lt;/span&gt; conn&lt;span style="font-weight: bold"&gt;.&lt;/span&gt;cursor()

    &lt;span style="color: #999988; font-style: italic"&gt;#TODO: copy mysqldump&amp;#39;s table escaping function&lt;/span&gt;
    sql &lt;span style="font-weight: bold"&gt;=&lt;/span&gt; &lt;span style="color: #bb8844"&gt;&amp;quot;select * from `%s` &amp;quot;&lt;/span&gt; &lt;span style="font-weight: bold"&gt;%&lt;/span&gt; (table)
    &lt;span style="font-weight: bold"&gt;if&lt;/span&gt; &lt;span style="color: #bb8844"&gt;&amp;quot;where&amp;quot;&lt;/span&gt; &lt;span style="font-weight: bold"&gt;in&lt;/span&gt; kwargs:
        sql &lt;span style="font-weight: bold"&gt;+=&lt;/span&gt; &lt;span style="color: #bb8844"&gt;&amp;quot;where %s &amp;quot;&lt;/span&gt; &lt;span style="font-weight: bold"&gt;%&lt;/span&gt; (kwargs[&lt;span style="color: #bb8844"&gt;&amp;quot;where&amp;quot;&lt;/span&gt;])
    &lt;span style="font-weight: bold"&gt;if&lt;/span&gt; &lt;span style="color: #bb8844"&gt;&amp;quot;reverse&amp;quot;&lt;/span&gt; &lt;span style="font-weight: bold"&gt;in&lt;/span&gt; kwargs &lt;span style="font-weight: bold"&gt;and&lt;/span&gt; kwargs[&lt;span style="color: #bb8844"&gt;&amp;quot;reverse&amp;quot;&lt;/span&gt;]:
        sql &lt;span style="font-weight: bold"&gt;+=&lt;/span&gt; &lt;span style="color: #bb8844"&gt;&amp;quot;order by `%s` desc &amp;quot;&lt;/span&gt; &lt;span style="font-weight: bold"&gt;%&lt;/span&gt; (kwargs[&lt;span style="color: #bb8844"&gt;&amp;quot;idCol&amp;quot;&lt;/span&gt;])
    sql &lt;span style="font-weight: bold"&gt;+=&lt;/span&gt; &lt;span style="color: #bb8844"&gt;&amp;quot;limit %s;&amp;quot;&lt;/span&gt;
    cur&lt;span style="font-weight: bold"&gt;.&lt;/span&gt;execute(sql, (n, ))

    i &lt;span style="font-weight: bold"&gt;=&lt;/span&gt; &lt;span style="color: #009999"&gt;0&lt;/span&gt;
    row &lt;span style="font-weight: bold"&gt;=&lt;/span&gt; cur&lt;span style="font-weight: bold"&gt;.&lt;/span&gt;fetchone()
    insert_stmts &lt;span style="font-weight: bold"&gt;=&lt;/span&gt; [] 
    &lt;span style="font-weight: bold"&gt;while&lt;/span&gt; row &lt;span style="font-weight: bold"&gt;and&lt;/span&gt; i &lt;span style="font-weight: bold"&gt;&amp;lt;&lt;/span&gt; n:
        i &lt;span style="font-weight: bold"&gt;+=&lt;/span&gt; &lt;span style="color: #009999"&gt;1&lt;/span&gt;
        &lt;span style="color: #999988; font-style: italic"&gt;#note that the MySQLdb source suggests that conn.literal is &lt;/span&gt;
        &lt;span style="color: #999988; font-style: italic"&gt;# private; I see no problem with using it, as it just loads the &lt;/span&gt;
        &lt;span style="color: #999988; font-style: italic"&gt;# default escaping functions. Caveat Emptor.&lt;/span&gt;
        strow &lt;span style="font-weight: bold"&gt;=&lt;/span&gt; &lt;span style="color: #bb8844"&gt;&amp;quot;, &amp;quot;&lt;/span&gt;&lt;span style="font-weight: bold"&gt;.&lt;/span&gt;join([conn&lt;span style="font-weight: bold"&gt;.&lt;/span&gt;literal(o) &lt;span style="font-weight: bold"&gt;for&lt;/span&gt; o &lt;span style="font-weight: bold"&gt;in&lt;/span&gt; row])
        insert_stmts&lt;span style="font-weight: bold"&gt;.&lt;/span&gt;append(&lt;span style="color: #bb8844"&gt;&amp;quot;(%s)&amp;quot;&lt;/span&gt; &lt;span style="font-weight: bold"&gt;%&lt;/span&gt; (strow))
        row &lt;span style="font-weight: bold"&gt;=&lt;/span&gt; cur&lt;span style="font-weight: bold"&gt;.&lt;/span&gt;fetchone()

    cur&lt;span style="font-weight: bold"&gt;.&lt;/span&gt;close()
    
    &lt;span style="font-weight: bold"&gt;return&lt;/span&gt; &lt;span style="color: #bb8844"&gt;&amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
&lt;span style="color: #bb8844"&gt;-------- INSERT DATA FOR TABLE %(table)s -----------&lt;/span&gt;
&lt;span style="color: #bb8844"&gt;    &lt;/span&gt;
&lt;span style="color: #bb8844"&gt;    LOCK TABLES `%(table)s` WRITE;&lt;/span&gt;
&lt;span style="color: #bb8844"&gt;    DELETE FROM `%(table)s`;&lt;/span&gt;
&lt;span style="color: #bb8844"&gt;    INSERT INTO `%(table)s` VALUES %(sql)s;&lt;/span&gt;
&lt;span style="color: #bb8844"&gt;    UNLOCK TABLES;&lt;/span&gt;

&lt;span style="color: #bb8844"&gt;-------- END INSERT DATA FOR TABLE %(table)s -----------&lt;/span&gt;
&lt;span style="color: #bb8844"&gt;&amp;quot;&amp;quot;&amp;quot;&lt;/span&gt; &lt;span style="font-weight: bold"&gt;%&lt;/span&gt; {&lt;span style="color: #bb8844"&gt;&amp;quot;table&amp;quot;&lt;/span&gt;: table, &lt;span style="color: #bb8844"&gt;&amp;quot;sql&amp;quot;&lt;/span&gt;: &lt;span style="color: #bb8844"&gt;&amp;quot;,&amp;quot;&lt;/span&gt;&lt;span style="font-weight: bold"&gt;.&lt;/span&gt;join(insert_stmts)}
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;
On a side note, the MySQLdb docs are somewhat hard to track down; I found 
them after some effort &lt;a 
href="http://mysql-python.sourceforge.net/MySQLdb.html"&gt;here&lt;/a&gt;.
</content>
	</entry>
	<entry>
		<title>Why I Like My Macbook Pro</title>
		<link href="http://billmill.org/macbook.html" />	
		<id>http://billmill.org/macbook.html</id>
		<updated>2007-05-13T13:12:00Z</updated>
		<summary type="html">Summed up very succinctly:&lt;br&gt;
&lt;textarea rows=2 cols=65&gt;09:38 AM ~/code/personal_code/python$ uptime
9:50  up 49 days, 22 hrs, 2 users, load averages: 2.28 2.33 2.28&lt;/textarea&gt;&lt;p&gt; 
This means that my Macbook Pro, which I received on December 26, 2006, has been 
up and running, without a reboot, for 36% of its active life.&lt;p&gt;
This is despite the fact that it's been my alarm clock every morning during 
that span, so it's gone to sleep and woken up at least once every single day, 
and usually more than once. Furthermore, it's been used for development in C, 
Python, erlang, C#, IronPython, Pypy, and probably a few others. I've installed 
many programs during this time, viewed many PDFs, probably opened 10,000 tabs 
in Firefox, Safari, Opera, and Camino, and run quite a few Windows sessions 
with Visual Studio in Parallels.&lt;p&gt;
This laptop stability is a wholly new experience for me; Windows and Linux both 
have required fairly frequent reboots on the laptops I've had, and I've had 
several between 2000 and now. It's awesome to be able to trust the sleep and 
hibernate modes of the computer; certainly it's foreign to this Linux 
convert.&lt;p&gt;
Now, that doesn't mean I've turned into a raving Mac fanboy. I think much of 
their software sucks, the dock still annoys me, and their computer is nigh on 
unusable without &lt;a href="http://quicksilver.blacktree.com/"&gt;Quicksilver&lt;/a&gt;.  
However, their laptop hardware and its integration into the OS has been all 
that I hoped for and more.&lt;p&gt;
UPDATE: A few hours after posting this entry, a security update forced a reboot :)
</summary>
		<content type="html">Summed up very succinctly:&lt;br&gt;
&lt;textarea rows=2 cols=65&gt;09:38 AM ~/code/personal_code/python$ uptime
9:50  up 49 days, 22 hrs, 2 users, load averages: 2.28 2.33 2.28&lt;/textarea&gt;&lt;p&gt; 
This means that my Macbook Pro, which I received on December 26, 2006, has been 
up and running, without a reboot, for 36% of its active life.&lt;p&gt;
This is despite the fact that it's been my alarm clock every morning during 
that span, so it's gone to sleep and woken up at least once every single day, 
and usually more than once. Furthermore, it's been used for development in C, 
Python, erlang, C#, IronPython, Pypy, and probably a few others. I've installed 
many programs during this time, viewed many PDFs, probably opened 10,000 tabs 
in Firefox, Safari, Opera, and Camino, and run quite a few Windows sessions 
with Visual Studio in Parallels.&lt;p&gt;
This laptop stability is a wholly new experience for me; Windows and Linux both 
have required fairly frequent reboots on the laptops I've had, and I've had 
several between 2000 and now. It's awesome to be able to trust the sleep and 
hibernate modes of the computer; certainly it's foreign to this Linux 
convert.&lt;p&gt;
Now, that doesn't mean I've turned into a raving Mac fanboy. I think much of 
their software sucks, the dock still annoys me, and their computer is nigh on 
unusable without &lt;a href="http://quicksilver.blacktree.com/"&gt;Quicksilver&lt;/a&gt;.  
However, their laptop hardware and its integration into the OS has been all 
that I hoped for and more.&lt;p&gt;
UPDATE: A few hours after posting this entry, a security update forced a reboot :)
</content>
	</entry>
</feed>
