From: Peter Rabbitson Date: Thu, 18 Jun 2009 06:40:18 +0000 (+0000) Subject: Cleanup attribute handling - I deal with resolved attributes throughout, no point... X-Git-Tag: v0.08108~81 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=630eaa8d965ed9135a3c76d81816bd2df49ee422;p=dbsrgits%2FDBIx-Class.git Cleanup attribute handling - I deal with resolved attributes throughout, no point in complicating things further --- diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index 4038fb6..8ad1f7d 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -1144,7 +1144,7 @@ sub count { return $self->search(@_)->count if @_ and defined $_[0]; return scalar @{ $self->get_cache } if $self->get_cache; - my $meth = $self->_has_attr (qw/prefetch collapse distinct group_by/) + my $meth = $self->_has_resolved_attr (qw/collapse group_by/) ? 'count_grouped' : 'count' ; @@ -1276,15 +1276,15 @@ sub _rs_update_delete { my $rsrc = $self->result_source; - my $needs_group_by_subq = $self->_has_attr (qw/prefetch distinct join seen_join group_by/); - my $needs_subq = $self->_has_attr (qw/row offset page/); + my $needs_group_by_subq = $self->_has_resolved_attr (qw/collapse group_by -join/); + my $needs_subq = $self->_has_resolved_attr (qw/row offset/); if ($needs_group_by_subq or $needs_subq) { # make a new $rs selecting only the PKs (that's all we really need) my $attrs = $self->_resolved_attrs_copy; - delete $attrs->{$_} for qw/prefetch collapse select +select as +as columns +columns/; + delete $attrs->{$_} for qw/collapse select as/; $attrs->{columns} = [ map { "$attrs->{alias}.$_" } ($self->result_source->primary_columns) ]; if ($needs_group_by_subq) { @@ -1808,14 +1808,14 @@ sub _is_deterministic_value { return 0; } -# _has_attr +# _has_resolved_attr # # determines if the resultset defines at least one # of the attributes supplied # # used to determine if a subquery is neccessary -sub _has_attr { +sub _has_resolved_attr { my ($self, @attr_names) = @_; my $attrs = $self->_resolved_attrs; @@ -1823,7 +1823,7 @@ sub _has_attr { my $join_check_req; for my $n (@attr_names) { - ++$join_check_req if $n =~ /join/; + ++$join_check_req if $n eq '-join'; my $attr = $attrs->{$n}; @@ -1840,7 +1840,7 @@ sub _has_attr { } } - # a join can be expressed as a multi-level from + # a resolved join is expressed as a multi-level from return 1 if ( $join_check_req and @@ -2622,10 +2622,12 @@ sub _resolved_attrs { $attrs->{collapse} = $collapse; - if ($attrs->{page} && not exists $attrs->{resolved_offset}) { - $attrs->{offset} = ($attrs->{rows} * ($attrs->{page} - 1)) + + # if both page and offset are specified, produce a combined offset + # even though it doesn't make much sense, this is what pre 081xx has + # been doing + if (my $page = delete $attrs->{page}) { + $attrs->{offset} = ($attrs->{rows} * ($page - 1)) + ($attrs->{offset} || 0); - $attrs->{resolved_offset} = $attrs->{offset}; } return $self->{_attrs} = $attrs; diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index 1ed743d..9edae6e 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -1311,8 +1311,8 @@ sub count { my $tmp_attrs = { %$attrs }; - # take off any pagers, record_filter is cdbi, and no point of ordering a count - delete $tmp_attrs->{$_} for (qw/select as rows offset page order_by record_filter/); + # take off any limits, record_filter is cdbi, and no point of ordering a count + delete $tmp_attrs->{$_} for (qw/select as rows offset order_by record_filter/); # overwrite the selector $tmp_attrs->{select} = { count => '*' }; @@ -1336,7 +1336,7 @@ sub count_grouped { my $sub_attrs = { %$attrs }; # these can not go in the subquery, and there is no point of ordering it - delete $sub_attrs->{$_} for qw/prefetch collapse select as order_by/; + delete $sub_attrs->{$_} for qw/collapse select as order_by/; # if we prefetch, we group_by primary keys only as this is what we would get out of the rs via ->next/->all # simply deleting group_by suffices, as the code below will re-fill it @@ -1353,7 +1353,7 @@ sub count_grouped { }]; # the subquery replaces this - delete $attrs->{$_} for qw/where bind prefetch collapse group_by having having_bind rows offset page pager/; + delete $attrs->{$_} for qw/where bind collapse group_by having having_bind rows offset/; return $self->count ($source, $attrs); }