File: dbi-primary_key_info.t

package info (click to toggle)
libdbd-firebird-perl 0.91-2%2Bdeb7u1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 680 kB
  • sloc: perl: 4,085; ansic: 2,262; makefile: 14
file content (76 lines) | stat: -rw-r--r-- 1,818 bytes parent folder | download | duplicates (3)
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
#!perl -w
# vim: ft=perl

# Changes 2011-01-21   stefansbv:
# - use testlib.pl instead of lib.pl

use strict;
use warnings;

use Test::More;
use lib 't','.';

use TestFirebird;
my $T = TestFirebird->new;

my ( $dbh, $error_str )
    = $T->connect_to_database(
    { RaiseError => 1, PrintError => 0, AutoCommit => 0 } );

if ($error_str) {
    BAIL_OUT("Unknown: $error_str!");
}

unless ( $dbh->isa('DBI::db') ) {
    plan skip_all => 'Connection to database failed, cannot continue testing';
}
else {
    plan tests => 13;
}

ok($dbh, 'Connected to the database');

# ------- TESTS ------------------------------------------------------------- #

#
#   Find a possible new table name
#
my $table = find_new_table($dbh);
ok($table, qq{Table is '$table'});

ok($dbh->do(<<__eosql), "CREATE TABLE $table");
  CREATE TABLE $table(
    Z INTEGER NOT NULL,
    Y CHAR(10) NOT NULL,
    X INTEGER NOT NULL,
    K CHAR(3) NOT NULL,
    PRIMARY KEY(Z, Y, X),
    UNIQUE(K)
  )
__eosql

my $sth = $dbh->primary_key_info(undef, undef, $table);
ok($sth, "Got primary key info");
is_deeply($sth->{NAME_uc},
   [qw|TABLE_CAT TABLE_SCHEM TABLE_NAME COLUMN_NAME KEY_SEQ PK_NAME|]);

my $key_info = $sth->fetch;
is_deeply([@$key_info[0..4]], [ undef, undef, $table, 'Z', '1' ]);
ok($key_info->[5] =~ /\S/, "PK_NAME is set"); # Something like RBD$PRIMARY123

$key_info = $sth->fetch;
is_deeply([@$key_info[0..4]], [ undef, undef, $table, 'Y', '2' ]);
ok($key_info->[5] =~ /\S/, "PK_NAME is set");

$key_info = $sth->fetch;
is_deeply([@$key_info[0..4]], [ undef, undef, $table, 'X', '3' ]);
ok($key_info->[5] =~ /\S/, "PK_NAME is set");

$sth->finish;

is_deeply([ $dbh->primary_key(undef, undef, $table) ], [qw|Z Y X|],
          "Check primary_key results");

ok($dbh->do("DROP TABLE $table"), "Dropped table");

$dbh->disconnect();