X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FStorage%2FDBI.pm;h=0141e1c7b2b966d0907cf472b0bb5ad2cad01f21;hb=ec10b4644f46ea1b51fe4be0addff6831cc3a267;hp=c20a93144ee6966c1cde36d35bdd401f3da9efd0;hpb=7fc9269f5384a071cba4a212ca6c7321b25509ae;p=dbsrgits%2FDBIx-Class-Historic.git diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index c20a931..0141e1c 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -926,6 +926,22 @@ sub _fix_bind_params { } @bind; } +sub _flatten_bind_params { + my ($self, @bind) = @_; + + ### Turn @bind from something like this: + ### ( [ "artist", 1 ], [ "cdid", 1, 3 ] ) + ### to this: + ### ( 1, 1, 3 ) + return + map { + if ( defined( $_ && $_->[1] ) ) { + @{$_}[ 1 .. $#$_ ]; + } + else { undef; } + } @bind; +} + sub _query_start { my ( $self, $sql, @bind ) = @_; @@ -1229,18 +1245,27 @@ sub _select_args { return @args; } -sub count { +sub _trim_attributes_for_count { my ($self, $source, $attrs) = @_; - - my $tmp_attrs = { %$attrs }; + my %attrs = %$attrs; # take off any column specs, any pagers, record_filter is cdbi, and no point of ordering a count - delete $tmp_attrs->{$_} for (qw/columns +columns select +select as +as rows offset page pager order_by record_filter/); + delete @attrs{qw/ + columns +columns select +select as +as rows offset page pager order_by + record_filter/)}; + + return \%attrs; +} + +sub count { + my ($self, $source, $attrs) = @_; + + my $new_attrs = $self->_trim_attributes_for_count($source, $attrs); - $tmp_attrs->{select} = { count => '*' }; - $tmp_attrs->{as} = [qw/count/]; + $new_attrs->{select} = { count => '*' }; + $new_attrs->{as} = [qw/count/]; - my $tmp_rs = $source->resultset_class->new($source, $tmp_attrs); + my $tmp_rs = $source->resultset_class->new($source, $new_attrs); my ($count) = $tmp_rs->cursor->next; # if the offset/rows attributes are still present, we did not use