comparison DBD/t/41ddtbl.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 => 26;
20 } else {
21 plan skip_all => 'Cannot test without DB info';
22 }
23
24 pass('Table info tests');
25
26 my $dbh = DBI->connect or die "Connect failed: $DBI::errstr\n";
27 pass('Database connection created');
28
29 my $tbl = lc $DBD_TEST::table_name;
30
31 ok( DBD_TEST::tab_create( $dbh ),"CREATE TABLE $tbl");
32 {
33 my @names = qw(TABLE_CAT TABLE_SCHEM TABLE_NAME TABLE_TYPE REMARKS);
34 my $sth = $dbh->table_info;
35 my $rows = 0;
36 while ( my $row = $sth->fetch ) {
37 $rows++;
38 }
39 my $names = $sth->{NAME_uc};
40 is( $names->[$_], $names[$_],"Column: $names->[$_] $names[$_]")
41 for 0 .. $#names;
42
43 is( $dbh->tables, $rows,"Total tables count: $rows");
44 }
45 {
46 my $sth = $dbh->table_info( undef, undef, undef,'TABLE');
47 ok( defined $sth,'Statement handle defined');
48
49 my $row = $sth->fetch;
50 is( $row->[3],'TABLE','Fetched a TABLE?');
51 }
52 {
53 my $sth = $dbh->table_info( undef, undef, $tbl,'TABLE');
54 ok( defined $sth,'Statement handle defined');
55
56 my $row = $sth->fetch;
57 is( $row->[2], $tbl,"Is this $tbl?");
58 is( $row->[3],'TABLE',"Is $tbl a TABLE?");
59 }
60 {
61 my $sth = $dbh->table_info( undef, undef, $tbl,'VIEW');
62 ok( defined $sth,'Statement handle defined');
63
64 my $row = $sth->fetch;
65 ok( !defined $row,"$tbl isn't a VIEW!");
66 }
67 =for todo
68 {
69 my $sth = $dbh->table_info('%');
70 ok( defined $sth,'Statement handle defined');
71
72 print "Catalogs:\n";
73 while ( my $row = $sth->fetch )
74 {
75 local $^W = 0;
76 local $, = "\t";
77 print @$row,"\n";
78 }
79 }
80 {
81 my $sth = $dbh->table_info( undef,'%');
82 ok( defined $sth,'Statement handle defined');
83
84 print "Schemata:\n";
85 while ( my $row = $sth->fetch )
86 {
87 local $^W = 0;
88 local $, = "\t";
89 print @$row,"\n";
90 }
91 }
92 {
93 my $sth = $dbh->table_info( undef, undef, undef,'%');
94 ok( defined $sth,'Statement handle defined');
95
96 print "Table types:\n";
97 while ( my $row = $sth->fetch )
98 {
99 local $^W = 0;
100 local $, = "\t";
101 print @$row,"\n";
102 }
103 }
104 =cut
105
106 # -----------------------------------------------------------------------------
107 {
108 my $sth;
109
110 # Table Info
111 eval {
112 $sth = $dbh->table_info;
113 };
114 ok( (!$@ and defined $sth ),'table_info tested');
115 $sth = undef;
116
117 # Tables
118 eval {
119 $sth = $dbh->tables;
120 };
121 ok( (!$@ and defined $sth ),'tables tested');
122 $sth = undef;
123
124 # Test Table Info
125 $sth = $dbh->table_info( undef, undef, undef );
126 ok( defined $sth,'table_info( undef, undef, undef ) tested');
127 DBD_TEST::dump_results( $sth );
128 $sth = undef;
129
130 $sth = $dbh->table_info( undef, undef, undef,'VIEW');
131 ok( defined $sth, q(table_info( undef, undef, undef,'VIEW') tested) );
132 DBD_TEST::dump_results( $sth );
133 $sth = undef;
134
135 # Test Table Info Rule 19a
136 $sth = $dbh->table_info('%','','');
137 ok( defined $sth, q(table_info('%','','') tested) );
138 DBD_TEST::dump_results( $sth );
139 $sth = undef;
140
141 # Test Table Info Rule 19b
142 $sth = $dbh->table_info('','%','');
143 ok( defined $sth, q(table_info('','%','') tested) );
144 DBD_TEST::dump_results( $sth );
145 $sth = undef;
146
147 # Test Table Info Rule 19c
148 $sth = $dbh->table_info('','','','%');
149 ok( defined $sth, q(table_info('','','','%') tested) );
150 DBD_TEST::dump_results( $sth );
151 $sth = undef;
152
153 # Test to see if this database contains any of the defined table types.
154 $sth = $dbh->table_info('','','','%');
155 ok( defined $sth, q(table_info('','','','%') tested) );
156 if ( $sth ) {
157 my $err = 0;
158 my $ref = $sth->fetchall_hashref(lc 'TABLE_TYPE');
159 for my $type ( sort keys %$ref ) {
160 print "# $type:\n";
161 my $sth = $dbh->table_info( undef, undef, undef, $type ) or $err++;
162 DBD_TEST::dump_results( $sth );
163 }
164 is( $err, 0,'all table types selected');
165 }
166 $sth = undef;
167
168 }
169 # -----------------------------------------------------------------------------
170
171 ok( $dbh->disconnect,'Disconnect');