| 1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
# This tests, whether the number of rows can be retrieved. |
| 4 |
|
| 5 |
use strict; |
| 6 |
use warnings; |
| 7 |
use Test::More; |
| 8 |
|
| 9 |
BEGIN { use_ok ("DBI") } |
| 10 |
require "./t/lib.pl"; |
| 11 |
|
| 12 |
sub TrueRows { |
| 13 |
my $sth = shift; |
| 14 |
my $count = 0; |
| 15 |
$count++ while $sth->fetch; |
| 16 |
$count; |
| 17 |
} # TrueRows |
| 18 |
|
| 19 |
my @tbl_def = ( |
| 20 |
[ "id", "INTEGER", 4, 0 ], |
| 21 |
[ "name", "CHAR", 64, 0 ], |
| 22 |
); |
| 23 |
|
| 24 |
my ($sth, $rows); |
| 25 |
|
| 26 |
ok (my $dbh = Connect (), "connect"); |
| 27 |
|
| 28 |
ok (my $tbl = FindNewTable ($dbh), "find new test table"); |
| 29 |
|
| 30 |
like (my $def = TableDefinition ($tbl, @tbl_def), |
| 31 |
qr{^create table $tbl}i, "table definition"); |
| 32 |
ok ($dbh->do ($def), "create table"); |
| 33 |
|
| 34 |
ok ($dbh->do ("INSERT INTO $tbl VALUES (1, 'Alligator Descartes')"), "insert"); |
| 35 |
|
| 36 |
ok ($sth = $dbh->prepare ("SELECT * FROM $tbl WHERE id = 1"), "prepare"); |
| 37 |
ok ($sth->execute, "execute"); |
| 38 |
|
| 39 |
is ($sth->rows, 1, "numrows"); |
| 40 |
is (TrueRows ($sth), 1, "true rows"); |
| 41 |
|
| 42 |
ok ($sth->finish, "finish"); |
| 43 |
undef $sth; |
| 44 |
|
| 45 |
|
| 46 |
ok ($dbh->do ("INSERT INTO $tbl VALUES (2, 'Jochen Wiedman')"), "insert"); |
| 47 |
|
| 48 |
ok ($sth = $dbh->prepare ("SELECT * FROM $tbl WHERE id >= 1"), "prepare"); |
| 49 |
ok ($sth->execute, "execute"); |
| 50 |
|
| 51 |
$rows = $sth->rows; |
| 52 |
ok ($rows == 2 || $rows == -1, "rows"); |
| 53 |
is (TrueRows ($sth), 2, "true rows"); |
| 54 |
|
| 55 |
ok ($sth->finish, "finish"); |
| 56 |
undef $sth; |
| 57 |
|
| 58 |
ok ($dbh->do ("INSERT INTO $tbl VALUES (3, 'Tim Bunce')"), "insert"); |
| 59 |
|
| 60 |
ok ($sth = $dbh->prepare ("SELECT * FROM $tbl WHERE id >= 2"), "prepare"); |
| 61 |
ok ($sth->execute, "execute"); |
| 62 |
|
| 63 |
$rows = $sth->rows; |
| 64 |
ok ($rows == 2 || $rows == -1, "rows"); |
| 65 |
is (TrueRows ($sth), 2, "true rows"); |
| 66 |
|
| 67 |
ok ($sth->finish, "finish"); |
| 68 |
undef $sth; |
| 69 |
|
| 70 |
ok ($dbh->do ("DROP TABLE $tbl"), "drop"); |
| 71 |
ok ($dbh->disconnect, "disconnect"); |
| 72 |
|
| 73 |
done_testing (); |