1
0
Fork 0
mirror of https://github.com/DBD-SQLite/DBD-SQLite synced 2025-06-08 14:48:32 -04:00
DBD-SQLite-SQLcipher/t/rt_29058_group_by.t
Adam Kennedy 85300f62f1 Now I can have my fancy module without CORION's hated dependency :)
Bundling Test::NoWarnings into inc
2009-04-05 23:42:14 +00:00

50 lines
1.1 KiB
Perl

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