From: Rafael Kitover Date: Thu, 4 Jun 2009 16:41:54 +0000 (+0000) Subject: back to counting rows for Sybase LIMIT counts X-Git-Tag: v0.08112~14^2~153 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=6537ddaaaf25fe29ac81b6589c8bd1de63db58c8;p=dbsrgits%2FDBIx-Class.git back to counting rows for Sybase LIMIT counts --- diff --git a/lib/DBIx/Class/Storage/DBI/Sybase.pm b/lib/DBIx/Class/Storage/DBI/Sybase.pm index c68cfd6..b0aef93 100644 --- a/lib/DBIx/Class/Storage/DBI/Sybase.pm +++ b/lib/DBIx/Class/Storage/DBI/Sybase.pm @@ -63,40 +63,27 @@ sub _dbh_last_insert_id { sub count { my ($self, $source, $attrs) = @_; - if (exists $attrs->{rows}) { - my $offset = $attrs->{offset} || 0; - my $total = $attrs->{rows} + $offset; - - my $new_attrs = $self->_trim_attributes_for_count($source, $attrs); - - my $query = $source->resultset_class->new($source, $new_attrs)->as_query; + if (not exists $attrs->{rows}) { + return $self->next::method(@_); + } - my $top_attrs = {}; - $top_attrs->{from} = [{ - top_subq => $query - }]; - $top_attrs->{select} = "TOP $total 1"; - $top_attrs->{as} = ['total']; + my $offset = $attrs->{offset} || 0; + my $total = $attrs->{rows} + $offset; - my $top_query = $source->resultset_class->new($source, $top_attrs)->as_query; + my $new_attrs = $self->_trim_attributes_for_count($source, $attrs); + $new_attrs->{select} = '1'; + $new_attrs->{as} = ['dummy']; - my $count_attrs = {}; - $count_attrs->{from} = [{ - count_subq => $top_query - }]; - $count_attrs->{select} = { count => '*' }; - $count_attrs->{as} = ['count']; + my $tmp_rs = $source->resultset_class->new($source, $new_attrs); - my $tmp_rs = $source->resultset_class->new($source, $count_attrs); - my ($count) = $tmp_rs->cursor->next; + $self->dbh->{syb_rowcount} = $total; - $count -= $offset; - $count = $attrs->{rows} if $count > $attrs->{rows}; + my $count = 0; + $count++ while $tmp_rs->cursor->next; - return $count; - } + $self->dbh->{syb_rowcount} = 0; - return $self->next::method(@_); + return $count - $offset; } sub datetime_parser_type { "DBIx::Class::Storage::DBI::Sybase::DateTime" }