Fixed a bug with DBI iterators and made the tets self-bootstrapping and added the...
[dbsrgits/DBM-Deep.git] / lib / DBM / Deep / Iterator / DBI.pm
index 3b8f1c8..31ec7b8 100644 (file)
@@ -5,5 +5,29 @@ use warnings FATAL => 'all';
 
 use base qw( DBM::Deep::Iterator );
 
+sub reset {
+    my $self = shift;
+
+    eval { $self->{sth}->finish; };
+    delete $self->{sth};
+
+    return;
+}
+
+sub get_next_key {
+    my $self = shift;
+    my ($obj) = @_;
+
+    unless ( exists $self->{sth} ) {
+        $self->{sth} = $self->{engine}->storage->{dbh}->prepare(
+            "SELECT `key` FROM datas WHERE ref_id = ? ORDER BY RAND()",
+        );
+        $self->{sth}->execute( $self->{base_offset} );
+    }
+
+    my ($key) = $self->{sth}->fetchrow_array;
+    return $key;
+}
+
 1;
 __END__