pod fixes
[dbsrgits/DBIx-Class-Historic.git] / lib / DBIx / Class / Storage / DBI / MultiDistinctEmulation.pm
CommitLineData
286f32b3 1package DBIx::Class::Storage::DBI::MultiDistinctEmulation;
2
3use strict;
4use warnings;
5
6use base qw/DBIx::Class::Storage::DBI/;
7
8sub _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
21sub 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
311;
32
33=head1 NAME
34
e48d4b16 35DBIx::Class::Storage::DBI::MultiDistinctEmulation - Some databases can't handle count distincts with multiple cols. They should use base on this.
286f32b3 36
37=head1 SYNOPSIS
38
39=head1 DESCRIPTION
40
41This class allows count distincts with multiple columns for retarded databases (Oracle and SQLite)
42
43=head1 AUTHORS
44
45Luke Saunders <luke.saunders@gmail.com>
46
47=head1 LICENSE
48
49You may distribute this code under the same terms as Perl itself.
50
51=cut