1
0
Fork 0
mirror of https://github.com/DBD-SQLite/DBD-SQLite synced 2025-06-07 22:28:47 -04:00

Cleaning up the test

This commit is contained in:
Adam Kennedy 2009-04-05 02:32:10 +00:00
parent a3b6b5586b
commit 0c6f7fb3bd

View file

@ -5,34 +5,46 @@ BEGIN {
$^W = 1; $^W = 1;
} }
use Test::More tests => 6;
use Test::NoWarnings;
use t::lib::Test; use t::lib::Test;
use Test::More tests => 6;
use DBI;
my $dbh = connect_ok(); my $dbh = connect_ok();
$dbh->do( 'CREATE TABLE foo (bar TEXT, num INT)' ); $dbh->do('CREATE TABLE foo (bar TEXT, num INT)');
for (1..5) { foreach ( 1..5 ) {
$dbh->do('INSERT INTO foo (bar, num) VALUES (?,?)', undef, ($_%2 ? "odd" : "even"), $_); $dbh->do(
'INSERT INTO foo (bar, num) VALUES (?, ?)',
undef, ($_%2 ? "odd" : "even"), $_
);
} }
# DBI->trace(9); # DBI->trace(9);
# see if placeholder works # see if placeholder works
my ($v, $num) = $dbh->selectrow_array('SELECT bar, num FROM foo WHERE num = ?', undef, 3); my ($v, $num) = $dbh->selectrow_array(
ok $v eq 'odd' && $num == 3; 'SELECT bar, num FROM foo WHERE num = ?',
undef, 3
);
ok( $v eq 'odd' && $num == 3 );
# see if the sql itself works as expected # see if the sql itself works as expected
my $ar = $dbh->selectall_arrayref('SELECT bar FROM foo GROUP BY bar HAVING count(*) > 1'); my $ar = $dbh->selectall_arrayref(
ok 'SELECT bar FROM foo GROUP BY bar HAVING count(*) > 1'
ok @$ar == 2; );
is( scalar(@$ar), 2, 'Got 2 results' );
# known workaround # known workaround
# ref: http://code.google.com/p/gears/issues/detail?id=163 # ref: http://code.google.com/p/gears/issues/detail?id=163
$ar = $dbh->selectall_arrayref('SELECT bar FROM foo GROUP BY bar HAVING count(*) > 0+?', undef, 1); $ar = $dbh->selectall_arrayref(
ok @$ar == 2; 'SELECT bar FROM foo GROUP BY bar HAVING count(*) > 0+?',
undef, 1
);
is( scalar(@$ar), 2, 'Got 2 results' );
# and this is what should be tested # and this is what should be tested
$ar = $dbh->selectall_arrayref('SELECT bar FROM foo GROUP BY bar HAVING count(*) > ?', undef, 1); $ar = $dbh->selectall_arrayref(
print "4: @$_\n" for @$ar; 'SELECT bar FROM foo GROUP BY bar HAVING count(*) > ?',
ok @$ar == 2, "we got ".(@$ar)." items"; undef, 1
);
# print "4: @$_\n" for @$ar;
is( scalar(@$ar), 2, "we got ".(@$ar)." items" );