<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>CrudVision - Lisa Seelye &#187; sql</title>
	<atom:link href="http://www.crudvision.com/category/sql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.crudvision.com</link>
	<description>Lisa Seelye's Blog. Yay</description>
	<lastBuildDate>Tue, 13 Apr 2010 21:26:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Eve Online Empyrean Age 1.0 Database Dump for PostgreSQL</title>
		<link>http://www.crudvision.com/2008/07/30/eve-online-empyrean-age-10-database-dump-for-postgresql/</link>
		<comments>http://www.crudvision.com/2008/07/30/eve-online-empyrean-age-10-database-dump-for-postgresql/#comments</comments>
		<pubDate>Wed, 30 Jul 2008 18:29:16 +0000</pubDate>
		<dc:creator>Lisa Seelye</dc:creator>
				<category><![CDATA[eve online]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[postgres]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://www.crudvision.com/?p=110</guid>
		<description><![CDATA[Today CCP announced the release of their MS SQL dump. Following in step with past conversions here is a Postgres version. Tested with 8.0.15 but should work on everything. This dump is odd: CCP is using integers where they mean to use booleans. So in those cases remember 1 is true, 0 is false. Good [...]]]></description>
			<content:encoded><![CDATA[<p>Today CCP <a href="http://myeve.eve-online.com/devblog.asp?a=blog&#038;bid=575">announced the release of their MS SQL dump</a>. Following in step with past conversions here is <a href="http://dl.eve-files.com/media/corp/crudvis/empyreanage1-postgres.zip">a Postgres version</a>. Tested with 8.0.15 but should work on everything.</p>
<p>This dump is odd: CCP is using integers where they mean to use booleans. So in those cases remember 1 is true, 0 is false. Good luck.</p>
<p>Edit: As a note the <a href="http://lisa.thedoh.com/projects/EO/">Eve Online Database Viewer</a> is updated with this dump.</p>
<p>Edit 2 (July 31, 2008): I nearly forgot to give props to <a href="http://bunjiboys.dk/">bunjiboys</a> for providing the .sql files from which the above dump is derrived.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.crudvision.com/2008/07/30/eve-online-empyrean-age-10-database-dump-for-postgresql/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Followup to My First Patch</title>
		<link>http://www.crudvision.com/2008/01/02/followup-to-my-first-patch/</link>
		<comments>http://www.crudvision.com/2008/01/02/followup-to-my-first-patch/#comments</comments>
		<pubDate>Wed, 02 Jan 2008 16:50:38 +0000</pubDate>
		<dc:creator>Lisa Seelye</dc:creator>
				<category><![CDATA[activerecord]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[oracle]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[snippet]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://www.crudvision.com/2008/01/02/followup-to-my-first-patch/</guid>
		<description><![CDATA[In reference to the post about My First Patch to the Rails trac I mentioned in the edit of the post that I emailed the maintainer. There&#8217;s been no response, unfortunately. So I&#8217;ll post the patch here so it&#8217;ll get a bit more visibility and hopefully Oracle users can find it helpful in speeding up [...]]]></description>
			<content:encoded><![CDATA[<p>In reference to the post about <a href="http://www.crudvision.com/2007/12/01/my-first-patch/">My First Patch</a> to the <a href="http://dev.rubyonrails.org/ticket/10331">Rails trac</a> I mentioned in the edit of the post that I emailed the maintainer. There&#8217;s been no response, unfortunately.</p>
<p>So I&#8217;ll post the patch here so it&#8217;ll get a bit more visibility and hopefully Oracle users can find it helpful in speeding up <code>rake db:migrate</code> on Oracle systems with a lot of indicies.</p>
<p><a href='http://www.crudvision.com/wp-content/uploads/2008/01/change_oracleadapter_indexes_to_run_quicker.diff' title='Patch to speed up Rails’s OracleAdapter#indexes method'>Patch to speed up Rails’s OracleAdapter#indexes method</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.crudvision.com/2008/01/02/followup-to-my-first-patch/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Eve Online Trinity Database dump</title>
		<link>http://www.crudvision.com/2007/12/09/eve-online-trinity-database-dump/</link>
		<comments>http://www.crudvision.com/2007/12/09/eve-online-trinity-database-dump/#comments</comments>
		<pubDate>Sun, 09 Dec 2007 14:58:03 +0000</pubDate>
		<dc:creator>Lisa Seelye</dc:creator>
				<category><![CDATA[eve online]]></category>
		<category><![CDATA[postgres]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://www.crudvision.com/2007/12/09/eve-online-trinity-database-dump/</guid>
		<description><![CDATA[As I&#8217;ve done for previous Eve Online database dumps here&#8217;s a Postgres (8.1) dump for Trinity. Hosted at http://www.eve-files.com and can be downloaded by clicking on right here Included in the zip archive is a Schema file as well as each individual table as a .sql file. They&#8217;re numbered 001 to 065. 001 is the [...]]]></description>
			<content:encoded><![CDATA[<p>As I&#8217;ve done for previous Eve Online database dumps here&#8217;s a Postgres (8.1) dump for Trinity. Hosted at http://www.eve-files.com and can be downloaded <a HREF="http://dl.eve-files.com/media/corp/crudvis/trinity-postgres-8.1.zip">by clicking on right here</a></p>
<p>Included in the zip archive is a Schema file as well as each individual table as a .sql file. They&#8217;re numbered 001 to 065. 001 is the schema (001_schema.sql) and is intended to be imported first. The others have no real order as there are no foreign key constraints but were numbered for my testing and sanity.</p>
<p><a href="http://lisa.thedoh.com/projects/EO/Trinity/">View the dump online</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.crudvision.com/2007/12/09/eve-online-trinity-database-dump/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Rails has_many gotcha</title>
		<link>http://www.crudvision.com/2007/12/08/rails-has_many-gotcha/</link>
		<comments>http://www.crudvision.com/2007/12/08/rails-has_many-gotcha/#comments</comments>
		<pubDate>Sat, 08 Dec 2007 13:39:04 +0000</pubDate>
		<dc:creator>Lisa Seelye</dc:creator>
				<category><![CDATA[activerecord]]></category>
		<category><![CDATA[crud]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[work]]></category>

		<guid isPermaLink="false">http://www.crudvision.com/2007/12/08/rails-has_many-gotcha/</guid>
		<description><![CDATA[With Rails there's a useful set of callback methods that can be used within model classes. They include after_create, before_validation and the one I want to talk about after_initialize. A lot of cool things can be done with after_initialize, especially if one uses the database as a means to store meta-data about a model. Use [...]]]></description>
			<content:encoded><![CDATA[<p>With Rails there's a useful set of <a href="http://api.rubyonrails.org/classes/ActiveRecord/Callbacks.html">callback methods</a> that can be used within model classes. They include <code>after_create</code>, <code>before_validation</code> and the one I want to talk about <code>after_initialize</code>.</p>
<p>A lot of cool things can be done with <code>after_initialize</code>, especially if one uses the database as a means to store meta-data about a model. Use the <code>after_initialize</code> method to transform your models with Ruby after they're fethced from the database. Consider the following User model definition:</p>
<div class="igBar"><span id="lruby-3"><a href="#" onclick="javascript:showCodeTxt('ruby-3'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">RUBY:</span>
<div id="ruby-3">
<div class="ruby">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#EB7070;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">class</span> User &lt;ActiveRecord::Base</div>
</li>
<li style="font-weight: bold;color:#8970EB;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; has_many :memberships, <img src='http://www.crudvision.com/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> rder =&gt; <span style="color:#996600;">"memberships.group_id, memberships.expires_at desc"</span>, :group =&gt; <span style="color:#996600;">"group_id"</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#EB7070;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">end</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>It's pretty clear that with the <code>:group => "group_id"</code> that I want a unique set of Membership objects. That works well when I've already got a User and do <code>user.memberships</code> but not at all when I do <code>User.find(:first, :include => :memberships)</code>; likely because of the way the join is set up and grouping on that may not be possible.</p>
<p>I still wanted to use eager loading so I thought that it would be an OK sacrifice to fetch all the Membership objects even if I wanted to pare it down after I initialize the User object (with eager loading). I defined:</p>
<div class="igBar"><span id="lruby-4"><a href="#" onclick="javascript:showCodeTxt('ruby-4'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">RUBY:</span>
<div id="ruby-4">
<div class="ruby">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#EB7070;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">class</span> User &lt;ActiveRecord::Base</div>
</li>
<li style="font-weight: bold;color:#8970EB;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#EB7070;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> after_initialize</div>
</li>
<li style="font-weight: bold;color:#8970EB;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">do</span> stuff with @memberships instance varible</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#EB7070;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span></div>
</li>
<li style="font-weight: bold;color:#8970EB;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">end</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Except it doesn't work. Quickly I found the following from <a href="http://dev.rubyonrails.org/browser/tags/rel_2-0-0_RC2/activerecord/lib/active_record/base.rb#L1140">active_record/base.rb</a> (click link for source): right where it does the after_initialize callback! But it wasn't working for me. I needed to dig further.</p>
<p>Further research indicated that before the creation of the @memberships instance variable that would hold the collection of Membership objects the after_initialize callback was being fired off in the User model. Using <code>after_initialize</code> would not work due to the design of ActiveRecord. I'm still searching for an elegant way to work the way I want. I'll post again when I find it!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.crudvision.com/2007/12/08/rails-has_many-gotcha/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>She does a little PHP, too</title>
		<link>http://www.crudvision.com/2007/12/07/she-does-a-little-php-too/</link>
		<comments>http://www.crudvision.com/2007/12/07/she-does-a-little-php-too/#comments</comments>
		<pubDate>Fri, 07 Dec 2007 21:44:06 +0000</pubDate>
		<dc:creator>Lisa Seelye</dc:creator>
				<category><![CDATA[eve online]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[postgres]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://www.crudvision.com/2007/12/07/she-does-a-little-php-too/</guid>
		<description><![CDATA[I don't like it but I'll do it. I rewrote my Eve Online Database Viewer. With the recent Trinity Dump (Postgres version coming soon) I wanted to rewrite the PHP script in order to better make use of mod_rewrite and to better handle errors.]]></description>
			<content:encoded><![CDATA[<p>I don't like it but I'll do it. <img src='http://www.crudvision.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>I rewrote my <a href="http://lisa.thedoh.com/projects/EO/">Eve Online Database Viewer</a>. With the recent <a href="http://myeve.eve-online.com/ingameboard.asp?a=topic&#038;threadID=650828">Trinity Dump</a> (Postgres version coming soon) I wanted to rewrite the PHP script in order to better make use of mod_rewrite and to better handle errors.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.crudvision.com/2007/12/07/she-does-a-little-php-too/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My First Patch</title>
		<link>http://www.crudvision.com/2007/12/01/my-first-patch/</link>
		<comments>http://www.crudvision.com/2007/12/01/my-first-patch/#comments</comments>
		<pubDate>Sat, 01 Dec 2007 21:05:25 +0000</pubDate>
		<dc:creator>Lisa Seelye</dc:creator>
				<category><![CDATA[open source]]></category>
		<category><![CDATA[oracle]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[work]]></category>

		<guid isPermaLink="false">http://www.crudvision.com/2007/12/01/my-first-patch/</guid>
		<description><![CDATA[I've submitted my first patch to the Rails trac today to speed up the OracleAdapter#indexes method (used in migrations). A client at work uses Oracle and in the production environment this method was taking upwards of 45 seconds to run per table!One of their DBAs gave me the SQL there, so I can't take the [...]]]></description>
			<content:encoded><![CDATA[<p>I've submitted my first patch to the Rails trac today to <a HREF="http://dev.rubyonrails.org/ticket/10331">speed up the OracleAdapter#indexes method</a> (used in migrations). A client at work uses Oracle and in the production environment this method was taking upwards of 45 seconds to run per table!One of their DBAs gave me the SQL there, so I can't take the credit, I just submitted it.</p>
<p>I hope it's accepted. Incidentally, it works and has saved me a lot of time with migrations.</p>
<p>Edit: Yeah, turns out that since turning these adapters into gems patches for them shouldn't be done through Rails trac. How irritating, but whatever. I've sent the patch do the current maintainer for review.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.crudvision.com/2007/12/01/my-first-patch/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Eve Online Revelations 2.2 Postgres Database Dump</title>
		<link>http://www.crudvision.com/2007/09/02/eve-online-revelations-22-postgres-database-dump/</link>
		<comments>http://www.crudvision.com/2007/09/02/eve-online-revelations-22-postgres-database-dump/#comments</comments>
		<pubDate>Sun, 02 Sep 2007 15:08:19 +0000</pubDate>
		<dc:creator>Lisa Seelye</dc:creator>
				<category><![CDATA[eve online]]></category>
		<category><![CDATA[postgres]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://www.crudvision.com/2007/09/02/eve-online-revelations-22-postgres-database-dump/</guid>
		<description><![CDATA[Just finished a Postgres port of the latest Eve Revelations database dump (as of the 2.2 patch). It can be downloaded from eve-files and can be browsed online at http://lisa.thedoh.com/projects/EO/?db=Rev22 I hope it's useful for everyone.]]></description>
			<content:encoded><![CDATA[<p>Just finished a Postgres port of the latest Eve Revelations database dump (as of the 2.2 patch). It can be downloaded from <a HREF="http://eve-files.com/dl/122719">eve-files</a> and can be browsed online at <a href="http://lisa.thedoh.com/projects/EO/?db=Rev22">http://lisa.thedoh.com/projects/EO/?db=Rev22</a></p>
<p>I hope it's useful for everyone.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.crudvision.com/2007/09/02/eve-online-revelations-22-postgres-database-dump/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Speeding up Beast Forum</title>
		<link>http://www.crudvision.com/2007/08/20/speeding-up-beast-forum/</link>
		<comments>http://www.crudvision.com/2007/08/20/speeding-up-beast-forum/#comments</comments>
		<pubDate>Mon, 20 Aug 2007 10:30:39 +0000</pubDate>
		<dc:creator>Lisa Seelye</dc:creator>
				<category><![CDATA[rails]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[work]]></category>

		<guid isPermaLink="false">http://www.crudvision.com/2007/08/20/speeding-up-beast-forum/</guid>
		<description><![CDATA[(n.b., the version of Beast we use may not be the most current. This post may not reflect what's in trunk.) One of our clients from work uses Beast forum. Unfortunately last week it kind of died. Mongrel's logs were complaining that it couldn't allocate memory, the index (ForumsController#index) was taking upwards of 12 seconds [...]]]></description>
			<content:encoded><![CDATA[<p>(n.b., the version of Beast we use may not be the most current. This post may not reflect what's in trunk.)</p>
<p>One of our clients from work uses <a href="http://beast.caboo.se">Beast forum</a>. Unfortunately last week it kind of died. Mongrel's logs were complaining that it couldn't allocate memory, the index (ForumsController#index) was taking upwards of 12 seconds to load...</p>
<p>The problem was SQL. Beast is very greedy when it displays the front page; it does a <code>forums.posts.last.created_at</code> to get the timestamp for when the last post was made. This is done for every top-level forum and it will destroy your site.</p>
<p>At about 21:30ish the previous night I disabled the site because my brain was mush and I couldn't focus enough to diagnose the problem to say nothing of finding a solution. The next day when I got to the office I spent the first 90 minutes of the day diagnosing and fixing the problem. I found that I could find the relevant data with a GROUP BY and ORDER BY with one query for all forums... Except the times were the FIRST post and not the LAST post.</p>
<p>So I spent the next two hours figuring out why MySQL didn't want to ORDER BY and formulating a query that was both quick, returned data for every forum and worked. This is the ugly thing that resulted:</p>
<div class="igBar"><span id="lsql-7"><a href="#" onclick="javascript:showCodeTxt('sql-7'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">SQL:</span>
<div id="sql-7">
<div class="sql">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#EB7070;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">-- moderator_only is assigned from clean data in the controller; it is safe.</span></div>
</li>
<li style="font-weight: bold;color:#8970EB;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #993333; font-weight: bold;">SELECT</span> posts.id, posts.created_at, posts.forum_id, posts.topic_id, users.login</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#EB7070;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #993333; font-weight: bold;">FROM</span> posts </div>
</li>
<li style="font-weight: bold;color:#8970EB;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #993333; font-weight: bold;">INNER</span> <span style="color: #993333; font-weight: bold;">JOIN</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span> MAX<span style="color:#006600; font-weight:bold;">&#40;</span>id<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> id <span style="color: #993333; font-weight: bold;">FROM</span> posts <span style="color: #993333; font-weight: bold;">GROUP</span> <span style="color: #993333; font-weight: bold;">BY</span> forum_id<span style="color:#006600; font-weight:bold;">&#41;</span> ids <span style="color: #993333; font-weight: bold;">ON</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#EB7070;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">posts.id = ids.id</div>
</li>
<li style="font-weight: bold;color:#8970EB;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #993333; font-weight: bold;">LEFT</span> <span style="color: #993333; font-weight: bold;">OUTER</span> <span style="color: #993333; font-weight: bold;">JOIN</span> users</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#EB7070;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #993333; font-weight: bold;">ON</span> users.id = posts.user_id</div>
</li>
<li style="font-weight: bold;color:#8970EB;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #993333; font-weight: bold;">LEFT</span> <span style="color: #993333; font-weight: bold;">OUTER</span> <span style="color: #993333; font-weight: bold;">JOIN</span> forums</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#EB7070;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #993333; font-weight: bold;">ON</span> forums.id = posts.forum_id</div>
</li>
<li style="font-weight: bold;color:#8970EB;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #993333; font-weight: bold;">WHERE</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#EB7070;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#40;</span>forums.moderator_only = <span style="color: #cc66cc;color:#800000;">0</span> <span style="color: #993333; font-weight: bold;">OR</span> forums.moderator_only = <span style="color: #808080; font-style: italic;">#{moderator_only}) AND forums.parent_id is null</span></div>
</li>
<li style="font-weight: bold;color:#8970EB;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> posts.created_at </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>This is fed into:</p>
<div class="igBar"><span id="lruby-8"><a href="#" onclick="javascript:showCodeTxt('ruby-8'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">RUBY:</span>
<div id="ruby-8">
<div class="ruby">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#EB7070;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">last_posts = Post.<span style="color:#9900CC;">find_by_sql</span> <span style="color:#996600;">"...."</span></div>
</li>
<li style="font-weight: bold;color:#8970EB;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">@last_posts = last_posts.<span style="color:#9900CC;">group_by</span> &amp;:forum_id </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>In the view we just substitute <code>forum.posts.last</code> with <code>@last_posts[forum.id].first</code> in all instances. This may have to bet tweaked for your setup because I'm not sure where Beast ends and client-specific stuff begins.</p>
<p>You see there's some parent_id things going on in the SQL. At work we made Beast forum nested. We do plan to make these changes available for others to use but it's just a matter of finding time to get rid of the client-specific modifications and merging to trunk.</p>
<p>This is one of the things that I'm proud about: the SQL query was a pain!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.crudvision.com/2007/08/20/speeding-up-beast-forum/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Forsaking SQL?</title>
		<link>http://www.crudvision.com/2007/08/19/forsaking-sql/</link>
		<comments>http://www.crudvision.com/2007/08/19/forsaking-sql/#comments</comments>
		<pubDate>Sun, 19 Aug 2007 10:30:52 +0000</pubDate>
		<dc:creator>Lisa Seelye</dc:creator>
				<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://www.crudvision.com/2007/08/19/forsaking-sql/</guid>
		<description><![CDATA[Whenever I need to make a change to data in a Rails-based table I very rarely use a GUI, in fact, the only time I have used a GUI is for Oracle (and we all know how I feel about that). Instead I favour the rails console. For me I find it easier to use [...]]]></description>
			<content:encoded><![CDATA[<p>Whenever I need to make a change to data in a Rails-based table I very rarely use a GUI, in fact, the only time I have used a GUI is for <a HREF="http://www.crudvision.com/?cat=25">Oracle</a> (and we all know how I feel about that). Instead I favour the rails console.</p>
<p>For me I find it easier to use the console because it reinforces the ORM - an entry in the table is just an instance of a class that models that table. I find that <code>Constellation.find(:all, :conditions =&gt; "faction_id = 0").each { |c| c.faction_id = nil ; c.save! }</code> is more meaningful (and easier) than sorting by the value of that column and mass updating. Icky <img src='http://www.crudvision.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>When I need to construct weird SQL queries, however, I'll drop to the mysql or psql shells. GUIs are icky and their bulky interfaces tend to slow complex queries down. Of course, I'm a console geek so I'm slightly biased here.</p>
<p>Anyways, I cringe a little when I see people opening SQL GUIs to find table structure or to find data values and to change single values. But hey, different strokes for different folks!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.crudvision.com/2007/08/19/forsaking-sql/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Rails, Fixtures, Oracle, and Insert Errors</title>
		<link>http://www.crudvision.com/2007/08/07/rails-fixtures-oracle-and-insert-errors/</link>
		<comments>http://www.crudvision.com/2007/08/07/rails-fixtures-oracle-and-insert-errors/#comments</comments>
		<pubDate>Tue, 07 Aug 2007 22:43:30 +0000</pubDate>
		<dc:creator>Lisa Seelye</dc:creator>
				<category><![CDATA[oracle]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[work]]></category>

		<guid isPermaLink="false">http://www.crudvision.com/2007/08/07/rails-fixtures-oracle-and-insert-errors/</guid>
		<description><![CDATA[At work I've been struggling with making one of our projects play nice with Oracle. I got Oracle XE installed through Windows XP in Parallels and just couldn't make my tests work. I kept getting errors that Rails couln't insert a nil value into a non-nil field (id). What this eventually boiled down to is [...]]]></description>
			<content:encoded><![CDATA[<p>At work I've been struggling with making one of our projects play nice with Oracle. I got Oracle XE installed through Windows XP in Parallels and just couldn't make my tests work. I kept getting errors that Rails couln't insert a nil value into a non-nil field (id).</p>
<p>What this eventually boiled down to is Rails fixtures <em>MUST</em> have an <code>id</code> attribute on them or you may run into errors! This was hidden behind the scenes since heretofore we were using auto_incrementing MySQL fields. To get this behaviour in Oracle one must do
<div class="igBar"><span id="lcode-10"><a href="#" onclick="javascript:showCodeTxt('code-10'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-10">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#EB7070;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">select #<span style="color:#006600; font-weight:bold;">&#123;</span>table_name<span style="color:#006600; font-weight:bold;">&#125;</span>_seq.<span style="">nextval</span> id from dual </div>
</li>
</ol>
</div>
</div>
</div>
<p> (done by Rails automatically, normally) or set up a Trigger (not done by rails, and would have to be done in a create_table migration). </p>
<p><strong>However</strong>, fixtures bypass the normal ActiveRecord::Base#create call and just does a raw execute insert into... Which means there's no value for id, unless it's specified in the fixture. This kept me at it for hours today and I only found it by hacking the fixtures source to make it print in the logs what it was doing!</p>
<p>Let this be a lesson! Always put in ids even if you don't care about their values.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.crudvision.com/2007/08/07/rails-fixtures-oracle-and-insert-errors/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 1.169 seconds -->
