comparison DBD/t/13count.t @ 0:cedccb7e0143

Copy of clients/perl directory without Tests from MonetDB changeset 4d2d4532228a.
author Sjoerd Mullender <sjoerd@acm.org>
date Mon, 19 Sep 2016 15:15:52 +0200 (2016-09-19)
parents
children a0ec9e080a5b
comparison
equal deleted inserted replaced
-1:000000000000 0:cedccb7e0143
1 #!perl -I./t
2
3 # This Source Code Form is subject to the terms of the Mozilla Public
4 # License, v. 2.0. If a copy of the MPL was not distributed with this
5 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 #
7 # Copyright 1997 - July 2008 CWI, August 2008 - 2016 MonetDB B.V.
8
9 $| = 1;
10
11 use strict;
12 use warnings;
13 use DBI();
14 use DBD_TEST();
15
16 use Test::More;
17
18 if ( defined $ENV{DBI_DSN} ) {
19 plan tests => 30;
20 } else {
21 plan skip_all => 'Cannot test without DB info';
22 }
23
24 pass('Row count tests');
25
26 my $dbh = DBI->connect or die "Connect failed: $DBI::errstr\n";
27 $dbh->{RaiseError} = 1;
28 $dbh->{PrintError} = 0;
29 pass('Database connection created');
30
31 my $tbl = $DBD_TEST::table_name;
32 my $cnt = 7;
33
34 ok( DBD_TEST::tab_create( $dbh ),"CREATE TABLE $tbl");
35
36 is( $dbh->do("INSERT INTO $tbl( A, B ) VALUES( $_,'T$_')"), 1,"($_) Insert")
37 for 1..$cnt;
38
39 my $sth = $dbh->prepare("SELECT * FROM $tbl");
40 is( $sth->rows, -1,'Rows (prepare) :'. $sth->rows );
41
42 for ( 1..2 ) { # (re)execute
43 $sth->execute;
44 # is( $sth->rows, 0,'Rows (execute) : '. $sth->rows );
45 my $i = 0;
46 while ( my $row = $sth->fetch ) {
47 is( $sth->rows, ++$i,"($_) Rows so far: $i");
48 # print "# Row $i: ", DBI::neat_list( $row ),"\n";
49 }
50 is( $sth->rows, $cnt,"($_) Rows total : $cnt");
51 }
52
53 #$sth = $dbh->prepare("SELECT count(*) FROM $tbl");
54
55 is( $dbh->do("DELETE FROM $tbl"), $cnt,"Delete: $cnt");
56 is( $dbh->do("DELETE FROM $tbl"),'0E0',"Delete: 0E0");
57
58 ok( $dbh->disconnect,'Disconnect');