1use strict; 2use warnings; 3 4use DBI; 5use Test::More; 6use vars qw($test_dsn $test_user $test_password); 7use lib 't', '.'; 8require 'lib.pl'; 9 10my ($dbh, $sth, $aref); 11eval {$dbh= DBI->connect($test_dsn, $test_user, $test_password, 12 { RaiseError => 1, PrintError => 1, AutoCommit => 0 });}; 13if ($@) { 14 plan skip_all => "no database connection"; 15} 16plan tests => 30; 17 18ok $dbh->do("DROP TABLE IF EXISTS dbd_mysql_t40numrows"); 19 20my $create= <<EOT; 21CREATE TABLE dbd_mysql_t40numrows ( 22 id INT(4) NOT NULL DEFAULT 0, 23 name varchar(64) NOT NULL DEFAULT '' 24) 25EOT 26 27ok $dbh->do($create), "CREATE TABLE dbd_mysql_t40numrows"; 28 29ok $dbh->do("INSERT INTO dbd_mysql_t40numrows VALUES( 1, 'Alligator Descartes' )"), 'inserting first row'; 30 31ok ($sth = $dbh->prepare("SELECT * FROM dbd_mysql_t40numrows WHERE id = 1")); 32 33ok $sth->execute; 34 35is $sth->rows, 1, '\$sth->rows should be 1'; 36 37ok ($aref= $sth->fetchall_arrayref); 38 39is scalar @$aref, 1, 'Verified rows should be 1'; 40 41ok $sth->finish; 42 43ok $dbh->do("INSERT INTO dbd_mysql_t40numrows VALUES( 2, 'Jochen Wiedmann' )"), 'inserting second row'; 44 45ok ($sth = $dbh->prepare("SELECT * FROM dbd_mysql_t40numrows WHERE id >= 1")); 46 47ok $sth->execute; 48 49is $sth->rows, 2, '\$sth->rows should be 2'; 50 51ok ($aref= $sth->fetchall_arrayref); 52 53is scalar @$aref, 2, 'Verified rows should be 2'; 54 55ok $sth->finish; 56 57ok $dbh->do("INSERT INTO dbd_mysql_t40numrows VALUES(3, 'Tim Bunce')"), "inserting third row"; 58 59ok ($sth = $dbh->prepare("SELECT * FROM dbd_mysql_t40numrows WHERE id >= 2")); 60 61ok $sth->execute; 62 63is $sth->rows, 2, 'rows should be 2'; 64 65ok ($aref= $sth->fetchall_arrayref); 66 67is scalar @$aref, 2, 'Verified rows should be 2'; 68 69ok $sth->finish; 70 71ok ($sth = $dbh->prepare("SELECT * FROM dbd_mysql_t40numrows")); 72 73ok $sth->execute; 74 75is $sth->rows, 3, 'rows should be 3'; 76 77ok ($aref= $sth->fetchall_arrayref); 78 79is scalar @$aref, 3, 'Verified rows should be 3'; 80 81ok $dbh->do("DROP TABLE dbd_mysql_t40numrows"), "drop table dbd_mysql_t40numrows"; 82 83ok $dbh->disconnect; 84