blib/lib/DBM/Deep/Iterator/DBI.pm untested

filter: Statementstmt 0.0% 0 / 23 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 32 CC 2 SCAR 12.0
CC
2
Cov
0%
get_next_key
6.0
reset
2.0
BEGIN
2.0
CRAP 3.3
1 package DBM::Deep::Iterator::DBI;
2  
3 use strict;
4 use warnings FATAL => 'all';
5  
6 use base qw( DBM::Deep::Iterator );
7  
8 sub reset {
9 my $self = shift;
10  
11 eval { $self->{sth}->finish; };
12 delete $self->{sth};
13  
14 return;
15 }
16  
17 sub get_next_key {
18 my $self = shift;
19 my ($obj) = @_;
20  
21 unless ( exists $self->{sth} ) {
22 # For mysql, this needs to be RAND()
23 # For sqlite, this needs to be random()
24 my $storage = $self->{engine}->storage;
25 $self->{sth} = $storage->{dbh}->prepare(
26 "SELECT `key` FROM datas WHERE ref_id = ? ORDER BY "
27 . $storage->rand_function,
28 );
29 $self->{sth}->execute( $self->{base_offset} );
30 }
31  
32 my ($key) = $self->{sth}->fetchrow_array;
33 return $key;
34 }
35  
36 1;
37 __END__