[Bast-commits] r6504 -
DBIx-Class/0.08/branches/sybase/lib/DBIx/Class/Storage/DBI
caelum at dev.catalyst.perl.org
caelum at dev.catalyst.perl.org
Thu Jun 4 16:41:54 GMT 2009
Author: caelum
Date: 2009-06-04 16:41:54 +0000 (Thu, 04 Jun 2009)
New Revision: 6504
Modified:
DBIx-Class/0.08/branches/sybase/lib/DBIx/Class/Storage/DBI/Sybase.pm
Log:
back to counting rows for Sybase LIMIT counts
Modified: DBIx-Class/0.08/branches/sybase/lib/DBIx/Class/Storage/DBI/Sybase.pm
===================================================================
--- DBIx-Class/0.08/branches/sybase/lib/DBIx/Class/Storage/DBI/Sybase.pm 2009-06-04 16:03:01 UTC (rev 6503)
+++ DBIx-Class/0.08/branches/sybase/lib/DBIx/Class/Storage/DBI/Sybase.pm 2009-06-04 16:41:54 UTC (rev 6504)
@@ -63,40 +63,27 @@
sub count {
my ($self, $source, $attrs) = @_;
- if (exists $attrs->{rows}) {
- my $offset = $attrs->{offset} || 0;
- my $total = $attrs->{rows} + $offset;
+ if (not exists $attrs->{rows}) {
+ return $self->next::method(@_);
+ }
- my $new_attrs = $self->_trim_attributes_for_count($source, $attrs);
+ my $offset = $attrs->{offset} || 0;
+ my $total = $attrs->{rows} + $offset;
- my $query = $source->resultset_class->new($source, $new_attrs)->as_query;
+ my $new_attrs = $self->_trim_attributes_for_count($source, $attrs);
+ $new_attrs->{select} = '1';
+ $new_attrs->{as} = ['dummy'];
- my $top_attrs = {};
- $top_attrs->{from} = [{
- top_subq => $query
- }];
- $top_attrs->{select} = "TOP $total 1";
- $top_attrs->{as} = ['total'];
+ my $tmp_rs = $source->resultset_class->new($source, $new_attrs);
- my $top_query = $source->resultset_class->new($source, $top_attrs)->as_query;
+ $self->dbh->{syb_rowcount} = $total;
- my $count_attrs = {};
- $count_attrs->{from} = [{
- count_subq => $top_query
- }];
- $count_attrs->{select} = { count => '*' };
- $count_attrs->{as} = ['count'];
+ my $count = 0;
+ $count++ while $tmp_rs->cursor->next;
- my $tmp_rs = $source->resultset_class->new($source, $count_attrs);
- my ($count) = $tmp_rs->cursor->next;
+ $self->dbh->{syb_rowcount} = 0;
- $count -= $offset;
- $count = $attrs->{rows} if $count > $attrs->{rows};
-
- return $count;
- }
-
- return $self->next::method(@_);
+ return $count - $offset;
}
sub datetime_parser_type { "DBIx::Class::Storage::DBI::Sybase::DateTime" }
More information about the Bast-commits
mailing list