Date: | Fri, 17 Oct 2003 08:10:39 +0800 |
From: | Autrijus Tang <autrijus [...] autrijus.org> |
To: | bug-dbix-searchbuilder [...] rt.cpan.org |
Subject: | [PATCH] Make OrderBy take FUNCTION(FIELD) |
Here I have a query that must be ->OrderByCols(
{ FIELD => 'ISNULL(Description)'},
{ FIELD => 'Name' }
);
So below is the patch that makes it happen. :-)
Thanks,
/Autrijus/
--- SearchBuilder.pm Mon Aug 11 20:10:15 2003
+++ /usr/local/lib/perl5/site_perl/5.8.0/DBIx/SearchBuilder.pm Thu Aug 14 20:46:04 2003
@@ -923,7 +923,7 @@
Takes a paramhash of ALIAS, FIELD and ORDER.
ALIAS defaults to main
-FIELD defaults to the primary key of the main table.
+FIELD defaults to the primary key of the main table. Also accepts C<FUNCTION(FIELD)> format
ORDER defaults to ASC(ending). DESC(ending) is also a valid value for OrderBy
@@ -966,6 +966,12 @@
if ( ($rowhash{'ALIAS'}) and
($rowhash{'FIELD'}) and
($rowhash{'ORDER'}) ) {
+
+ if ($rowhash{'FIELD'} =~ /^(\w+\()(.*\))$/) {
+ # handle 'FUNCTION(FIELD)' formatted fields
+ $rowhash{'ALIAS'} = $1 . $rowhash{'ALIAS'};
+ $rowhash{'FIELD'} = $2;
+ }
$clause .= ($clause ? ", " : " ");
$clause .= $rowhash{'ALIAS'} . ".";