use strict;
use warnings;
use DBI;
-use SQL::Abstract;
+use SQL::Abstract::Limit;
use DBIx::Class::Storage::DBI::Cursor;
use base qw/DBIx::Class/;
sub new {
my $new = bless({}, ref $_[0] || $_[0]);
- $new->sql_maker(new SQL::Abstract);
$new->cursor("DBIx::Class::Storage::DBI::Cursor");
$new->debug(1) if $ENV{DBIX_CLASS_STORAGE_DBI_DEBUG};
return $new;
my ($self) = @_;
my @info = @{$self->connect_info || []};
$self->_dbh($self->_connect(@info));
+ $self->sql_maker(new SQL::Abstract::Limit( limit_dialect => $self->_dbh ));
}
sub _connect {
if (ref $condition eq 'SCALAR') {
$order = $1 if $$condition =~ s/ORDER BY (.*)$//i;
}
- my ($rv, $sth, @bind) = $self->_execute('select', $attrs->{bind}, $ident, $select, $condition, $order);
+ my ($rv, $sth, @bind) = $self->_execute('select', $attrs->{bind}, $ident, $select, $condition, $order, $attrs->{rows}, $attrs->{offset});
return $self->cursor->new($sth, \@bind, $attrs);
}
if (ref $condition eq 'SCALAR') {
$order = $1 if $$condition =~ s/ORDER BY (.*)$//i;
}
- my ($rv, $sth, @bind) = $self->_execute('select', $attrs->{bind}, $ident, $select, $condition, $order);
+ my ($rv, $sth, @bind) = $self->_execute('select', $attrs->{bind}, $ident, $select, $condition, $order, 1, $attrs->{offset});
return $sth->fetchrow_array;
}
--- /dev/null
+use strict;
+use Test::More;
+
+BEGIN {
+ eval "use DBD::SQLite";
+ plan $@ ? (skip_all => 'needs DBD::SQLite for testing') : (tests => 5);
+}
+
+use lib qw(t/lib);
+
+use_ok('DBICTest');
+
+# test LIMIT
+my $it = DBICTest::CD->search( {},
+ { rows => 3,
+ order_by => 'title' }
+);
+is( $it->count, 3, "count ok" );
+is( $it->next->title, "Caterwaulin' Blues", "iterator->next ok" );
+$it->next;
+$it->next;
+is( $it->next, undef, "next past end of resultset ok" );
+
+# test OFFSET
+my @cds = DBICTest::CD->search( {},
+ { rows => 2,
+ offset => 2,
+ order_by => 'year' }
+);
+is( $cds[0]->title, "Spoonful of bees", "offset ok" );