From: Rafael Kitover Date: Wed, 10 Jun 2009 12:35:52 +0000 (+0000) Subject: Sybase count by first pk, if available X-Git-Tag: v0.08112~14^2~138 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8cebbed0ed3df5a60809f9187a0a13cb1574d798;p=dbsrgits%2FDBIx-Class.git Sybase count by first pk, if available --- diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index a9070e0..c95195f 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -1325,7 +1325,7 @@ sub _resolve_ident_sources { return $alias2source; } -sub _trim_attributes_for_count { +sub _copy_attributes_for_count { my ($self, $source, $attrs) = @_; my %attrs = %$attrs; @@ -1338,7 +1338,7 @@ sub _trim_attributes_for_count { sub count { my ($self, $source, $attrs) = @_; - my $tmp_attrs = $self->_trim_attributes_for_count($source, $attrs); + my $tmp_attrs = $self->_copy_attributes_for_count($source, $attrs); # overwrite the selector $tmp_attrs->{select} = { count => '*' }; diff --git a/lib/DBIx/Class/Storage/DBI/Sybase.pm b/lib/DBIx/Class/Storage/DBI/Sybase.pm index 385ac30..4ffaae2 100644 --- a/lib/DBIx/Class/Storage/DBI/Sybase.pm +++ b/lib/DBIx/Class/Storage/DBI/Sybase.pm @@ -81,9 +81,11 @@ sub count { my $offset = $attrs->{offset} || 0; my $total = $attrs->{rows} + $offset; - my $new_attrs = $self->_trim_attributes_for_count($source, $attrs); - $new_attrs->{select} = '1'; - $new_attrs->{as} = ['dummy']; + my $new_attrs = $self->_copy_attributes_for_count($source, $attrs); + + my $first_pk = ($source->primary_columns)[0]; + + $new_attrs->{select} = $first_pk ? "me.$first_pk" : 1; my $tmp_rs = $source->resultset_class->new($source, $new_attrs);