File: dbi.t

package info (click to toggle)
libdata-stream-bulk-perl 0.11-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 208 kB
  • sloc: perl: 976; makefile: 2
file content (82 lines) | stat: -rw-r--r-- 1,368 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/perl

use strict;
use warnings;

use Test::More;

use Test::Requires {
    'DBI'       => 0,
    'DBD::Mock' => 1.37,
};

our $dbh;

BEGIN {
	plan skip_all => $@ unless eval {
		$dbh = DBI->connect( 'DBI:Mock:', '', '' )
			|| die "Cannot create handle: $DBI::errstr\n"
	};
}

use Data::Stream::Bulk::DBI;

my @data = (
	[ qw(col1 col2 col3) ],
	[ qw(foo bar gorch) ],
	[ qw(zot oi lalala) ],
	[ qw(those meddling kids) ],
);

{
	$dbh->{mock_add_resultset} = [ @data ];

	my $sth = $dbh->prepare("SELECT * FROM foo;");

	$sth->execute;

	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" );

	is_deeply( [ $d->items ], [ ], "no more" );

	ok( $d->is_done, "now we're done" );

}

{
	$dbh->{mock_add_resultset} = [ @data ];

	my $sth = $dbh->prepare("SELECT * FROM foo;");

	$sth->execute;

	my $d = Data::Stream::Bulk::DBI->new(
		sth => $sth,
		max_rows => 1,
	);

	ok( !$d->is_done, "not yet 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" );
}

done_testing;