1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
|
#!/usr/bin/perl -w
#
# @(#)$Id: t55mdata.t,v 2003.2 2003/01/03 19:02:36 jleffler Exp $
#
# Test MetaData functions _tables, _columns for DBD::Informix
#
# Copyright 1997,1999 Jonathan Leffler
# Copyright 2000 Informix Software Inc
# Copyright 2002-03 IBM
use DBD::Informix::TestHarness;
use DBD::Informix::Metadata;
use strict;
print "1..4\n";
# Test connection
my $dbh = &connect_to_test_database({ AutoCommit => 1, PrintError => 1 });
my $view = "dbd_ix_view01";
my $private1 = "dbd_ix_private01";
my $private2 = "'informix'.dbd_ix_private02";
my $public1 = "dbd_ix_public01";
# Drop pre-existing versions of views and synonyms (unchecked)
$dbh->{PrintError} = 0;
$dbh->do("DROP VIEW $view");
$dbh->do("DROP SYNONYM $public1");
$dbh->do("DROP SYNONYM $private1");
$dbh->do("DROP SYNONYM $private2");
$dbh->{PrintError} = 1;
stmt_ok();
# Create new views and synonyms
$dbh->do(qq{
CREATE VIEW $view AS
SELECT T.Owner, T.TabName, T.TabType, C.ColNo, C.ColName
FROM 'informix'.SysTables T, 'informix'.SysColumns C
WHERE C.Tabid = T.Tabid}
)
or die "DBI::errstr";
# Public and private synonyms were introduced in version 5.00.
# You cannot use PUBLIC or PRIVATE in a MODE ANSI database.
my $public = "PUBLIC";
my $private = "PRIVATE";
if ($dbh->{ix_ModeAnsiDatabase})
{
$public = "";
$private = "";
}
$dbh->do("CREATE $public SYNONYM $public1 FOR 'informix'.SysColumns")
or die "DBI::errstr";
$dbh->do("CREATE $private SYNONYM $private1 FOR 'informix'.SysTables")
or die "DBI::errstr";
# The next statement only works if you are a DBA.
$dbh->{PrintError} = 0;
$dbh->do("CREATE $private SYNONYM $private2 FOR 'informix'.SysTables");
$dbh->{PrintError} = 1;
stmt_ok();
sub print_tables
{
my ($dbh, @ctrl) = @_;
my @list = $dbh->func(@ctrl, '_tables');
my $pad = ($#ctrl >= 0) ? " " : "";
print "# Information about @ctrl${pad}tables in database $dbh->{Name}\n";
my $item;
for $item (@list)
{
print "# $item\n";
}
}
sub print_columns
{
my ($dbh, @tables) = @_;
my @list = $dbh->func(@tables, '_columns');
my $plural = ($#tables >= 0) ? "s" : "";
{
local($") = ", "; # $" is also known as $LIST_SEPARATOR
print "# Information about columns in table$plural @tables\n";
}
my $rowref;
for $rowref (@list)
{
my @row = @{$rowref};
my $tab = ix_map_tablename($row[0], $row[1]);
my $nulls = ($row[4] >= 256) ? "N" : "Y";
$row[4] -= 256 if ($row[4] > 256);
printf "# %-30s %3d %-18s %s %4d %4d\n", $tab, $row[2], $row[3],
$nulls, $row[4], $row[5];
}
}
print "# DBI Version $DBI::VERSION\n";
print "# DBD::Informix version $dbh->{Driver}->{Version}\n";
print "# Database $dbh->{Name}\n";
$dbh->{ChopBlanks} = 1;
# @(#)KLUDGE: Should verify that expected tables are included.
print_tables($dbh, 'view');
# Verify correct number of entries?
print_tables($dbh, 'base', 'user');
# Verify correct number of entries?
print_tables($dbh, 'base', 'system');
# Verify correct number of entries?
print_tables($dbh, 'synonym', 'tables');
# Verify correct number of entries?
print_tables($dbh, 'system');
# Verify correct number of entries?
print_tables($dbh);
stmt_ok();
# @(#)KLUDGE: should verify that columns are as expected!
print_columns($dbh, $view, $private1, $public1);
stmt_ok();
$dbh->disconnect or die "DBI::errstr";
all_ok();
|