comparison DBD/t/18bc.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 => 8;
20 } else {
21 plan skip_all => 'Cannot test without DB info';
22 }
23
24 pass('Bind column tests');
25
26 my $dbh = DBI->connect or die "Connect failed: $DBI::errstr\n";
27 pass('Database connection created');
28
29 my $tbl = $DBD_TEST::table_name;
30
31 ok( DBD_TEST::tab_create( $dbh ),"CREATE TABLE $tbl");
32
33 $dbh->{AutoCommit} = 0;
34
35 $dbh->do("INSERT INTO $tbl( A, B ) VALUES( 10,'Stuff here')");
36
37 $dbh->commit;
38
39 my $sth;
40
41 $sth = $dbh->prepare("DELETE FROM $tbl");
42 $sth->execute;
43 my $s = $sth->rows;
44 my $t = $DBI::rows;
45 is( $s, $t,"sth->rows: $s DBI::rows: $t");
46
47 $dbh->rollback;
48
49 $sth = $dbh->prepare("SELECT * FROM $tbl WHERE 1 = 0");
50 $sth->execute;
51 my @row = $sth->fetchrow;
52 if ( $sth->err ) {
53 print ' $sth->err : ', $sth->err , "\n";
54 print ' $sth->errstr: ', $sth->errstr, "\n";
55 print ' $dbh->state : ', $dbh->state , "\n";
56 # print ' $sth->state : ', $sth->state , "\n";
57 }
58 pass("Fetched empty result set: (@row)");
59
60 $sth = $dbh->prepare("SELECT A, B FROM $tbl");
61 $sth->execute;
62 while ( my $row = $sth->fetch ) {
63 print '# @row a, b : ', $row->[0], ',', $row->[1], "\n";
64 }
65
66 my $Ok;
67
68 $Ok = 1;
69 my ( $a, $b );
70 $sth->execute;
71 $sth->bind_col( 1, \$a );
72 $sth->bind_col( 2, \$b );
73 while ( $sth->fetch ) {
74 print '# bind_col a, b : ', $a, ',', $b, "\n";
75 unless ( defined $a && defined $b ) {
76 $Ok = 0;
77 $sth->finish;
78 last;
79 }
80 }
81 is( $Ok, 1,'All fields defined');
82
83 $Ok = 1;
84 ( $a, $b ) = ( undef, undef );
85 $sth->execute;
86 $sth->bind_columns( undef, \$b, \$a );
87 while ( $sth->fetch )
88 {
89 print '# bind_columns a, b : ', $b, ',', $a, "\n";
90 unless ( defined $a && defined $b ) {
91 $Ok = 0;
92 $sth->finish;
93 last;
94 }
95 }
96 is( $Ok, 1,'All fields defined');
97
98 ok( $dbh->disconnect,'Disconnect');