Commit | Line | Data |
996be9ee |
1 | package DBIx::Class::Schema::Loader::DBI::DB2; |
2 | |
3 | use strict; |
4 | use warnings; |
5 | use base 'DBIx::Class::Schema::Loader::DBI'; |
fa994d3c |
6 | use Carp::Clan qw/^DBIx::Class/; |
996be9ee |
7 | use Class::C3; |
8 | |
9 | =head1 NAME |
10 | |
11 | DBIx::Class::Schema::Loader::DBI::DB2 - DBIx::Class::Schema::Loader::DBI DB2 Implementation. |
12 | |
13 | =head1 SYNOPSIS |
14 | |
15 | package My::Schema; |
16 | use base qw/DBIx::Class::Schema::Loader/; |
17 | |
18 | __PACKAGE__->loader_options( |
19 | relationships => 1, |
20 | db_schema => "MYSCHEMA", |
21 | ); |
22 | |
23 | 1; |
24 | |
25 | =head1 DESCRIPTION |
26 | |
27 | See L<DBIx::Class::Schema::Loader::Base>. |
28 | |
29 | =cut |
30 | |
31 | sub _table_uniq_info { |
32 | my ($self, $table) = @_; |
33 | |
34 | my @uniqs; |
35 | |
36 | my $dbh = $self->schema->storage->dbh; |
37 | |
5223f24a |
38 | my $sth = $self->{_cache}->{db2_uniq} ||= $dbh->prepare( |
39 | q{SELECT kcu.COLNAME, kcu.CONSTNAME, kcu.COLSEQ |
40 | FROM SYSCAT.TABCONST as tc |
41 | JOIN SYSCAT.KEYCOLUSE as kcu ON tc.CONSTNAME = kcu.CONSTNAME |
42 | WHERE tc.TABSCHEMA = ? and tc.TABNAME = ? and tc.TYPE = 'U'} |
4421d6a3 |
43 | ) or die $DBI::errstr; |
5223f24a |
44 | |
45 | $sth->execute($self->db_schema, $table) or die $DBI::errstr; |
996be9ee |
46 | |
47 | my %keydata; |
48 | while(my $row = $sth->fetchrow_arrayref) { |
49 | my ($col, $constname, $seq) = @$row; |
50 | push(@{$keydata{$constname}}, [ $seq, lc $col ]); |
51 | } |
52 | foreach my $keyname (keys %keydata) { |
53 | my @ordered_cols = map { $_->[1] } sort { $a->[0] <=> $b->[0] } |
54 | @{$keydata{$keyname}}; |
55 | push(@uniqs, [ $keyname => \@ordered_cols ]); |
56 | } |
4421d6a3 |
57 | |
996be9ee |
58 | $sth->finish; |
59 | |
60 | return \@uniqs; |
61 | } |
62 | |
63 | =head1 SEE ALSO |
64 | |
65 | L<DBIx::Class::Schema::Loader>, L<DBIx::Class::Schema::Loader::Base>, |
66 | L<DBIx::Class::Schema::Loader::DBI> |
67 | |
68 | =cut |
69 | |
70 | 1; |