added some notes in the tests and fixed get_from_storage to actually use the new...
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI / MultiDistinctEmulation.pm
1 package DBIx::Class::Storage::DBI::MultiDistinctEmulation;
2
3 use strict;
4 use warnings;
5
6 use base qw/DBIx::Class::Storage::DBI/;
7
8 sub _select {
9   my ($self, $ident, $select, $condition, $attrs) = @_;
10
11   # hack to make count distincts with multiple columns work in SQLite and Oracle
12   if (ref $select eq 'ARRAY') { 
13       @{$select} = map {$self->replace_distincts($_)} @{$select};
14   } else { 
15       $select = $self->replace_distincts($select);
16   }
17
18   return $self->next::method($ident, $select, $condition, $attrs);
19 }
20
21 sub replace_distincts {
22     my ($self, $select) = @_;
23
24     $select->{count}->{distinct} = join("||", @{$select->{count}->{distinct}}) 
25         if (ref $select eq 'HASH' && $select->{count} && ref $select->{count} eq 'HASH' && 
26             $select->{count}->{distinct} && ref $select->{count}->{distinct} eq 'ARRAY');
27
28     return $select;
29 }
30
31 1;
32
33 =head1 NAME 
34
35 DBIx::Class::Storage::DBI::MultiDistinctEmulation - Some databases can't handle count distincts with multiple cols. They should use base on this.
36
37 =head1 SYNOPSIS
38
39 =head1 DESCRIPTION
40
41 This class allows count distincts with multiple columns for retarded databases (Oracle and SQLite)
42
43 =head1 AUTHORS
44
45 Luke Saunders <luke.saunders@gmail.com>
46
47 =head1 LICENSE
48
49 You may distribute this code under the same terms as Perl itself.
50
51 =cut