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
|
#!/usr/bin/perl -w
use strict;
use lib 't/lib';
use vars qw( $class );
use BookDB;
use Test::More tests => 5;
# ------------------------------------------------------------------------
$class = 'Data::Phrasebook';
use_ok $class;
my $file = 't/02phrases.txt';
# ------------------------------------------------------------------------
{
my $dbh = BookDB->new();
my $obj = $class->new(
class => 'SQL',
file => $file,
dbh => $dbh,
);
my ($count) = $obj
->query( 'count_author', {
author => 'Lawrence Miles'
} )
->fetchrow_array;
is( $count => 7, "Quick Miles" );
}
{
my $dbh = BookDB->new();
my $obj = $class->new(
class => 'SQL',
file => $file,
dbh => $dbh,
);
my $author = 'Lawrence Miles';
my $q = $obj->query( 'find_author' );
isa_ok( $q => 'Data::Phrasebook::SQL::Query' );
# Slow
{
my $count = 0;
$q->execute( author => $author );
while ( my $row = $q->fetchrow_hashref )
{
$count++ if $row->{author} eq $author;
}
is( $count => 7, "row by row Miles" );
$q->finish;
}
# fetchall_arrayref
{
my $count = 0;
$q->execute( author => $author );
my $r = $q->fetchall_arrayref;
is ( scalar @$r => 7, "fetchall Miles" );
$q->finish;
}
}
|