Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add all method to DBI

  • Loading branch information...
commit a46950524624f7310ebf99b9c0d5e72f987fe7c1 1 parent e3717aa
@nothingmuch authored
Showing with 49 additions and 14 deletions.
  1. +10 −0 lib/Data/Stream/Bulk/DBI.pm
  2. +39 −14 t/dbi.t
View
10 lib/Data/Stream/Bulk/DBI.pm
@@ -30,6 +30,16 @@ sub get_more {
$self->fetchall_arrayref( $self->slice, $self->max_rows );
}
+sub all {
+ my $self = shift;
+
+ my $all = $self->fetchall_arrayref( $self->slice );
+
+ $self->_set_done;
+
+ return @$all;
+}
+
__PACKAGE__->meta->make_immutable;
__PACKAGE__
View
53 t/dbi.t
@@ -26,28 +26,53 @@ my @data = (
[ qw(those meddling kids) ],
);
-$dbh->{mock_add_resultset} = [ @data ];
+{
+ $dbh->{mock_add_resultset} = [ @data ];
-my $sth = $dbh->prepare("SELECT * FROM foo;");
+ my $sth = $dbh->prepare("SELECT * FROM foo;");
-$sth->execute;
+ $sth->execute;
-my $d = Data::Stream::Bulk::DBI->new(
- sth => $sth,
- max_rows => 2,
-);
+ my $d = Data::Stream::Bulk::DBI->new(
+ sth => $sth,
+ max_rows => 2,
+ );
+
+ ok( !$d->is_done, "not yet done" );
+
+ is_deeply( $d->next, [ @data[1,2] ], "two rows" );
+
+ ok( !$d->is_done, "not yet done" );
+
+ is_deeply( [ $d->items ], [ $data[3] ], "one more" );
+
+ ok( !$d->is_done, "not yet done" );
-ok( !$d->is_done, "not yet done" );
+ is_deeply( [ $d->items ], [ ], "no more" );
-is_deeply( $d->next, [ @data[1,2] ], "two rows" );
+ ok( $d->is_done, "now we're done" );
-ok( !$d->is_done, "not yet done" );
+}
+
+{
+ $dbh->{mock_add_resultset} = [ @data ];
+
+ my $sth = $dbh->prepare("SELECT * FROM foo;");
-is_deeply( [ $d->items ], [ $data[3] ], "one more" );
+ $sth->execute;
-ok( !$d->is_done, "not yet done" );
+ my $d = Data::Stream::Bulk::DBI->new(
+ sth => $sth,
+ max_rows => 1,
+ );
-is_deeply( [ $d->items ], [ ], "no more" );
+ ok( !$d->is_done, "not yet done" );
-ok( $d->is_done, "now we're done" );
+ is_deeply( $d->next, [ $data[1] ], "one row" );
+ ok( !$d->is_done, "not yet done" );
+
+ is_deeply( [ $d->all ], [ @data[2,3] ], "all remaining rows" );
+
+ ok( $d->is_done, "now we're done" );
+}
Please sign in to comment.
Something went wrong with that request. Please try again.