X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FStorage%2FDBI%2FMultiDistinctEmulation.pm;fp=lib%2FDBIx%2FClass%2FStorage%2FDBI%2FMultiDistinctEmulation.pm;h=f38c03b7fb93aeb1eefc408bbc017f50efb4a3ce;hb=286f32b3cfaa7a96e3626d2b13a33302390e22bd;hp=0000000000000000000000000000000000000000;hpb=182fee362308526aa3f6161e8d79d566e7df520e;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/Storage/DBI/MultiDistinctEmulation.pm b/lib/DBIx/Class/Storage/DBI/MultiDistinctEmulation.pm new file mode 100644 index 0000000..f38c03b --- /dev/null +++ b/lib/DBIx/Class/Storage/DBI/MultiDistinctEmulation.pm @@ -0,0 +1,51 @@ +package DBIx::Class::Storage::DBI::MultiDistinctEmulation; + +use strict; +use warnings; + +use base qw/DBIx::Class::Storage::DBI/; + +sub _select { + my ($self, $ident, $select, $condition, $attrs) = @_; + + # hack to make count distincts with multiple columns work in SQLite and Oracle + if (ref $select eq 'ARRAY') { + @{$select} = map {$self->replace_distincts($_)} @{$select}; + } else { + $select = $self->replace_distincts($select); + } + + return $self->next::method($ident, $select, $condition, $attrs); +} + +sub replace_distincts { + my ($self, $select) = @_; + + $select->{count}->{distinct} = join("||", @{$select->{count}->{distinct}}) + if (ref $select eq 'HASH' && $select->{count} && ref $select->{count} eq 'HASH' && + $select->{count}->{distinct} && ref $select->{count}->{distinct} eq 'ARRAY'); + + return $select; +} + +1; + +=head1 NAME + +DBIx::Class::Storage::DBI::Retarded - Some databases can't handle count distincts with multiple cols. They should use base on this. + +=head1 SYNOPSIS + +=head1 DESCRIPTION + +This class allows count distincts with multiple columns for retarded databases (Oracle and SQLite) + +=head1 AUTHORS + +Luke Saunders + +=head1 LICENSE + +You may distribute this code under the same terms as Perl itself. + +=cut