comparison DBD/t/42ddcol.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 => 25;
20 } else {
21 plan skip_all => 'Cannot test without DB info';
22 }
23
24 pass('Column 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 {
32 ok( DBD_TEST::tab_create( $dbh ),"CREATE TABLE $tbl");
33 }
34 # TODO: handle catalog and schema ($tbl may exist in more then one schema)
35 {
36 my $sth;
37
38 eval { $sth = $dbh->column_info( undef, undef, undef, undef ) };
39 ok( (!$@ and defined $sth ),'column_info tested');
40 $sth = undef;
41 }
42 {
43 my $sth = $dbh->column_info( undef, undef, $tbl,'b');
44 ok( defined $sth,'Statement handle defined');
45
46 my $row = $sth->fetch;
47 is( $row->[ 2], $tbl,"Is this table name $tbl?");
48 is( $row->[ 3], 'b','Is this column name b?');
49 }
50 {
51 my $sth = $dbh->column_info( undef, undef, $tbl, undef );
52 ok( defined $sth,'Statement handle defined');
53
54 my @ColNames = sort keys %DBD_TEST::TestFieldInfo;
55 print "# Columns:\n";
56 my $i = 0;
57 while ( my $row = $sth->fetch )
58 {
59 $i++;
60 {
61 no warnings 'uninitialized';
62 local $, = ":"; print '# ', @$row, "\n";
63 }
64 $row->[ 3] = uc $row->[ 3];
65 is( $row->[ 2], $tbl ,"Is this table name $tbl?");
66 is( $row->[16], $i ,"Is this ordinal position $i?");
67 is( $row->[ 3], $ColNames[$i-1] ,"Is this column name $ColNames[$i-1]?");
68 my $ti = DBD_TEST::get_type_for_column( $dbh, $row->[3] );
69 # is( $row->[ 4] , $ti->{DATA_TYPE},"Is this data type $ti->{DATA_TYPE}?");
70 is( $row->[ 5] , $ti->{TYPE_NAME},"Is this type name $ti->{TYPE_NAME}?");
71 }
72 }
73
74 ok( $dbh->disconnect,'Disconnect');