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