[Bast-commits] r6503 - in DBIx-Class/0.08/branches/sybase:
lib/DBIx/Class/Storage lib/DBIx/Class/Storage/DBI t
caelum at dev.catalyst.perl.org
caelum at dev.catalyst.perl.org
Thu Jun 4 16:03:02 GMT 2009
Author: caelum
Date: 2009-06-04 16:03:01 +0000 (Thu, 04 Jun 2009)
New Revision: 6503
Modified:
DBIx-Class/0.08/branches/sybase/lib/DBIx/Class/Storage/DBI.pm
DBIx-Class/0.08/branches/sybase/lib/DBIx/Class/Storage/DBI/Sybase.pm
DBIx-Class/0.08/branches/sybase/t/746sybase.t
Log:
use TOP for sybase limit count thanks to refactored count
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 15:08:12 UTC (rev 6502)
+++ DBIx-Class/0.08/branches/sybase/lib/DBIx/Class/Storage/DBI/Sybase.pm 2009-06-04 16:03:01 UTC (rev 6503)
@@ -3,6 +3,7 @@
use strict;
use warnings;
+use Class::C3;
use base qw/DBIx::Class::Storage::DBI/;
use Carp::Clan qw/^DBIx::Class/;
@@ -63,26 +64,35 @@
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);
- $new_attrs->{select} = '1';
- $new_attrs->{as} = ['dummy'];
+ my $query = $source->resultset_class->new($source, $new_attrs)->as_query;
-# speed things up at least *a little*
- $new_attrs->{result_class} = 'DBIx::Class::ResultClass::HashRefInflator';
+ 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;
-
- $self->dbh->do("set rowcount $total");
+ my $top_query = $source->resultset_class->new($source, $top_attrs)->as_query;
- my $tmp_rs = $source->resultset_class->new($source, $new_attrs);
-
- my $count = 0;
- $count++ while $tmp_rs->cursor->next;
+ my $count_attrs = {};
+ $count_attrs->{from} = [{
+ count_subq => $top_query
+ }];
+ $count_attrs->{select} = { count => '*' };
+ $count_attrs->{as} = ['count'];
- $self->dbh->do("set rowcount 0");
+ my $tmp_rs = $source->resultset_class->new($source, $count_attrs);
+ my ($count) = $tmp_rs->cursor->next;
+ $count -= $offset;
+ $count = $attrs->{rows} if $count > $attrs->{rows};
+
return $count;
}
Modified: DBIx-Class/0.08/branches/sybase/lib/DBIx/Class/Storage/DBI.pm
===================================================================
--- DBIx-Class/0.08/branches/sybase/lib/DBIx/Class/Storage/DBI.pm 2009-06-04 15:08:12 UTC (rev 6502)
+++ DBIx-Class/0.08/branches/sybase/lib/DBIx/Class/Storage/DBI.pm 2009-06-04 16:03:01 UTC (rev 6503)
@@ -1252,7 +1252,7 @@
# take off any column specs, any pagers, record_filter is cdbi, and no point of ordering a count
delete @attrs{qw/
columns +columns select +select as +as rows offset page pager order_by
- record_filter/)};
+ record_filter/};
return \%attrs;
}
Modified: DBIx-Class/0.08/branches/sybase/t/746sybase.t
===================================================================
--- DBIx-Class/0.08/branches/sybase/t/746sybase.t 2009-06-04 15:08:12 UTC (rev 6502)
+++ DBIx-Class/0.08/branches/sybase/t/746sybase.t 2009-06-04 16:03:01 UTC (rev 6503)
@@ -11,7 +11,7 @@
plan skip_all => 'Set $ENV{DBICTEST_SYBASE_DSN}, _USER and _PASS to run this test'
unless ($dsn && $user);
-plan tests => 20*2;
+plan tests => (16 + 4*2)*2;
my @storage_types = (
'DBI::Sybase',
@@ -77,8 +77,22 @@
is( $it->next->name, "Artist 2", "iterator->next ok" );
is( $it->next, undef, "next past end of resultset ok" );
+# now try with offset
+ $it = $schema->resultset('Artist')->search({}, {
+ rows => 3,
+ offset => 3,
+ order_by => 'artistid',
+ });
+
+ is( $it->count, 3, "LIMIT with offset count ok" );
+
+ is( $it->next->name, "Artist 3", "iterator->next ok" );
+ $it->next;
+ is( $it->next->name, "Artist 5", "iterator->next ok" );
+ is( $it->next, undef, "next past end of resultset ok" );
+
SKIP: {
- skip 'quoting bug with NoBindVars', 8
+ skip 'quoting bug with NoBindVars', 4*2
if $storage_type eq 'DBI::Sybase::NoBindVars';
# Test DateTime inflation with DATETIME
More information about the Bast-commits
mailing list