Steffen Goeldner wrote:
>
> P.S.: A test for primary_key_info is under way.
>
Attached is a small test script for primary_key_info (t/19ddpk.t).
Steffen
#!/usr/bin/perl -I./t
$| = 1;
use strict;
use ADOTEST();
use Test::More tests => 9;
BEGIN { use_ok('DBD::ADO') }
my $dbh = DBI->connect or die "Connect failed: $DBI::errstr\n";
ok ( defined $dbh, 'Connection');
my $catalog = undef; # TODO: current catalog?
my $schema = undef; # TODO: current schema?
my $table = $ADOTEST::table_name;
my @types = ADOTEST::get_type_for_column( $dbh, 'A');
ok( @types > 0, 'Type info');
my $type = $types[0];
ok( $dbh->do("DROP TABLE $table"), 'Drop table');
my $sql = <<"SQL";
CREATE TABLE $table
(
K1 $type->{TYPE_NAME}
, K2 $type->{TYPE_NAME}
, PRIMARY KEY ( K1, K2 )
)
SQL
print $sql;
ok( $dbh->do( $sql ), 'Create table');
{
my $sth = $dbh->primary_key_info( $catalog, $schema, $table );
ok( defined $sth, 'Statement handle defined');
print "Primary key columns:\n";
my @cols;
while ( my $row = $sth->fetch )
{
local $^W = 0;
local $, = "\t";
print @$row, "\n";
push @cols, $row->[3];
}
is( @cols, 2, 'Primary key columns');
for ( 1, 2 )
{
is( $cols[$_-1], 'K' . $_, 'Primary key column names');
}
}