[Bps-public-commit] r11306 - DBIx-SearchBuilder/trunk/SearchBuilder/Handle

ruz at bestpractical.com ruz at bestpractical.com
Mon Mar 31 17:12:28 EDT 2008


Author: ruz
Date: Mon Mar 31 17:12:28 2008
New Revision: 11306

Modified:
   DBIx-SearchBuilder/trunk/SearchBuilder/Handle/SQLite.pm

Log:
* add support for order by outer column

Modified: DBIx-SearchBuilder/trunk/SearchBuilder/Handle/SQLite.pm
==============================================================================
--- DBIx-SearchBuilder/trunk/SearchBuilder/Handle/SQLite.pm	(original)
+++ DBIx-SearchBuilder/trunk/SearchBuilder/Handle/SQLite.pm	Mon Mar 31 17:12:28 2008
@@ -76,6 +76,27 @@
     return undef;
 }
 
+sub DistinctQuery {
+    my $self = shift;
+    my $statementref = shift;
+    my $sb = shift;
+
+    return $self->SUPER::DistinctQuery( $statementref, $sb, @_ )
+        if $sb->_GroupClause || $sb->_OrderClause !~ /(?<!main)\./;
+
+    local $sb->{'group_by'} = [{FIELD => 'id'}];
+    local $sb->{'order_by'} = [
+        map {
+            ($_->{'ALIAS'}||'') ne "main"
+            ? { %{$_}, FIELD => ((($_->{'ORDER'}||'') =~ /^des/i)?'MAX':'MIN') ."(".$_->{FIELD}.")" }
+            : $_
+        }
+        @{$sb->{'order_by'}}
+    ];
+    $$statementref = "SELECT main.* FROM $$statementref";
+    $$statementref .= $sb->_GroupClause;
+    $$statementref .= $sb->_OrderClause;
+}
 
 =head2 DistinctCount STATEMENTREF
 



More information about the Bps-public-commit mailing list