# DB2 support in radiant. Patch proposal

**URL:** <https://www.ruby-forum.com/t/db2-support-in-radiant-patch-proposal/105258>\
**Category:** Radiant CMS\
**Created:** [May 28, 2007, 6:11am UTC](https://www.ruby-forum.com/t/db2-support-in-radiant-patch-proposal/105258 "2007-05-28T06:11:00Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![lerzegov](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/b4bc9f/32.png) [@lerzegov](https://www.ruby-forum.com/u/lerzegov)\
**Post date:** [May 28, 2007, 6:11am UTC](https://www.ruby-forum.com/t/db2-support-in-radiant-patch-proposal/105258/1 "2007-05-28T06:11:00Z")

</div>

Hi.  
I am experimenting IBM DB2 Express as a back-end for Radiant. Results  
are encouraging so far. Some problems needed tweaks to the ibm\_db  
adapter for rails or to environment settings (see tracker on  
[http://rubyforge.org/projects/rubyibm/](http://rubyforge.org/projects/rubyibm/) for details). People at IBM have  
been very responsive. Though more complicated to set up vis-a-vis mysql  
or postgres, db2 has native support for xml, and this is the reason why  
I am interested in using it in rails.  
I propose the following patch to radiant/app/models/archive\_finder.rb in  
order to support db2 specific syntax for date fields:

def extract(part, field)  
#puts ActiveRecord::Base.connection.adapter\_name  
case ActiveRecord::Base.connection.adapter\_name  
#start of patch  
when /ibm\_db/i  
format = case part  
when /year/i  
“YEAR(#{field})”  
when /month/i  
“MONTH(#{field})”  
when /day/i  
“DAY(#{field})”  
end  
format  
#end of patch  
when /sqlite/i  
format = case part  
when /year/i  
‘%Y’  
when /month/i  
‘%m’  
when /day/i  
‘%d’  
end  
“CAST(STRFTIME(‘#{format}’, #{field}) AS INTEGER)”  
when /sqlserver/i  
“DATEPART(#{part.upcase}, #{field})”  
else  
“EXTRACT(#{part.upcase} FROM #{field})”  
end  
end

Luca Erzegovesi

---

<div class="post-metadata">

**Author:** ![lerzegov](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/b4bc9f/32.png) [@lerzegov](https://www.ruby-forum.com/u/lerzegov)\
**Post date:** [May 28, 2007, 8:51am UTC](https://www.ruby-forum.com/t/db2-support-in-radiant-patch-proposal/105258/2 "2007-05-28T08:51:36Z")

</div>

> I am interested in using it in rails.  
> I propose the following patch to  
> radiant/app/models/archive\_finder.rb in  
> order to support db2 specific syntax for date fields:
> 
> def extract(part, field)

Oh god… ewwwwwwww…

In the interests of sanity, lets pretend that radiant never had  
a switch based on ActiveRecord::Base.connection.adapter\_name.

[http://dev.radiantcms.org/radiant/changeset/447](http://dev.radiantcms.org/radiant/changeset/447)

I’d propose that we dump the archive\_finder completely - it’s  
only used from the tags, and now that the code is sane, there’s  
no need to keep it locked in a corner. Any objections?

Dan.

---

<div class="post-metadata">

**Author:** ![lerzegov](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/b4bc9f/32.png) [@lerzegov](https://www.ruby-forum.com/u/lerzegov)\
**Post date:** [May 28, 2007, 10:59am UTC](https://www.ruby-forum.com/t/db2-support-in-radiant-patch-proposal/105258/3 "2007-05-28T10:59:47Z")

</div>

Daniel S. wrote:

> In the interests of sanity, lets pretend that radiant never had  
> a switch based on ActiveRecord::Base.connection.adapter\_name.
> 
> [http://dev.radiantcms.org/radiant/changeset/447](http://dev.radiantcms.org/radiant/changeset/447)

Did this change preserve existing functionality?

> I’d propose that we dump the archive\_finder completely - it’s  
> only used from the tags, and now that the code is sane, there’s  
> no need to keep it locked in a corner. Any objections?

And replace it with what? I’m not sure what you are proposing.

–  
John L.  
[http://wiseheartdesign.com](http://wiseheartdesign.com)

---

<div class="post-metadata">

**Author:** ![lerzegov](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/b4bc9f/32.png) [@lerzegov](https://www.ruby-forum.com/u/lerzegov)\
**Post date:** [May 28, 2007, 6:03pm UTC](https://www.ruby-forum.com/t/db2-support-in-radiant-patch-proposal/105258/4 "2007-05-28T18:03:41Z")

</div>

Luca,

In the future you can submit a ticket on the Trac with the prefix  
[PATCH].

Sean

---

<div class="post-metadata">

**Author:** ![lerzegov](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/b4bc9f/32.png) [@lerzegov](https://www.ruby-forum.com/u/lerzegov)\
**Post date:** [May 29, 2007, 1:47am UTC](https://www.ruby-forum.com/t/db2-support-in-radiant-patch-proposal/105258/5 "2007-05-29T01:47:31Z")

</div>

> Daniel S. wrote:
> 
> > In the interests of sanity, lets pretend that radiant never had  
> > a switch based on ActiveRecord::Base.connection.adapter\_name.
> > 
> > [http://dev.radiantcms.org/radiant/changeset/447](http://dev.radiantcms.org/radiant/changeset/447)
> 
> Did this change preserve existing functionality?

Yes - all tests pass, and unless there’s a database that doesn’t  
allow comparison on date fields or I’m reading the code wrong it  
will do exactly the same thing.

> > I’d propose that we dump the archive\_finder completely - it’s  
> > only used from the tags, and now that the code is sane, there’s  
> > no need to keep it locked in a corner. Any objections?
> 
> And replace it with what? I’m not sure what you are proposing.

Each of the methods in archive\_finder are used in exactly one place -  
the corresponding archive\_xx\_index\_page tag. The code used to be quite  
complicated, and the day finder depended on the year and month finder.  
Now however, the code is quite simple and has no interdependencies,  
so I think the code would be clearer just inlined into the tags.

For example, the archive:children tag in archive\_day\_index\_page would  
be:

tag “archive:children” do |tag|  
if request\_uri =~ %r{/(\d{4})/(\d{2})/(\d{2})/?$}  
start = Time.local($1, $2, $3)  
finish = start.tomorrow  
tag.locals.children = parent.children.find(:all,  
:conditions =\> [  
‘published\_at \>= ? and published\_at \< ?’,  
start,  
finish,  
]  
)  
tag.expand  
end  
end

(code is actually more compact, but I’ve formatted across many lines  
because something is wrapping my lines wierdly).

Dan.

---

<div class="post-metadata">

**Author:** ![lerzegov](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/b4bc9f/32.png) [@lerzegov](https://www.ruby-forum.com/u/lerzegov)\
**Post date:** [May 29, 2007, 2:03am UTC](https://www.ruby-forum.com/t/db2-support-in-radiant-patch-proposal/105258/6 "2007-05-29T02:03:31Z")

</div>

IIRC, that ‘extract’ method that was removed was designed to deal with  
sqlite3. Also, the size of your range is only one day.

Sean

---

<div class="post-metadata">

**Author:** ![lerzegov](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/b4bc9f/32.png) [@lerzegov](https://www.ruby-forum.com/u/lerzegov)\
**Post date:** [May 29, 2007, 2:21am UTC](https://www.ruby-forum.com/t/db2-support-in-radiant-patch-proposal/105258/7 "2007-05-29T02:21:32Z")

</div>

> IIRC, that ‘extract’ method that was removed was designed to  
> deal with sqlite3.

Yes, but it was only necessary because the original code was doing the  
search in a platform specific way by relying on functions to  
transform a date into a string and perform a string comparison. The new  
approach just does a comparison on the fields as  
dates and checks that it lies within a range, so there’s nothing special  
about it.

Also the new approach would allow you to put an index on the  
published\_at column to get that running zippy - most db’s don’t deal  
well with functions and indexes. Not that that’s going to have any real  
impact until you’ve got A LOT of pages, but it’s nice  
anyway.

> Also, the size of your range is only one day.

Yes, that’s because my example was for the day index page - the month  
index would use Time#next\_month and the year index  
Time#next\_year.

Dan.

---

<div class="post-metadata">

**Author:** ![lerzegov](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/b4bc9f/32.png) [@lerzegov](https://www.ruby-forum.com/u/lerzegov)\
**Post date:** [May 29, 2007, 3:04am UTC](https://www.ruby-forum.com/t/db2-support-in-radiant-patch-proposal/105258/8 "2007-05-29T03:04:34Z")

</div>

Daniel S. wrote:

> Each of the methods in archive\_finder are used in exactly one place -  
> the corresponding archive\_xx\_index\_page tag. The code used to be quite  
> complicated, and the day finder depended on the year and month finder.  
> Now however, the code is quite simple and has no interdependencies,  
> so I think the code would be clearer just inlined into the tags.

I’m all for clarity. Go for it.

–  
John L.  
[http://wiseheartdesign.com](http://wiseheartdesign.com)
