Bump version for 0.04006 release
[dbsrgits/DBIx-Class-Schema-Loader.git] / lib / DBIx / Class / Schema / Loader / DBI / DB2.pm
CommitLineData
996be9ee 1package DBIx::Class::Schema::Loader::DBI::DB2;
2
3use strict;
4use warnings;
5use base 'DBIx::Class::Schema::Loader::DBI';
fa994d3c 6use Carp::Clan qw/^DBIx::Class/;
996be9ee 7use Class::C3;
8
eb1de218 9our $VERSION = '0.04006';
32f784fc 10
996be9ee 11=head1 NAME
12
13DBIx::Class::Schema::Loader::DBI::DB2 - DBIx::Class::Schema::Loader::DBI DB2 Implementation.
14
15=head1 SYNOPSIS
16
17 package My::Schema;
18 use base qw/DBIx::Class::Schema::Loader/;
19
59cfa251 20 __PACKAGE__->loader_options( db_schema => "MYSCHEMA" );
996be9ee 21
22 1;
23
24=head1 DESCRIPTION
25
26See L<DBIx::Class::Schema::Loader::Base>.
27
28=cut
29
30sub _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'}
4421d6a3 42 ) or die $DBI::errstr;
5223f24a 43
a168c1c4 44 $sth->execute($self->db_schema, uc $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 }
4421d6a3 56
996be9ee 57 $sth->finish;
58
59 return \@uniqs;
60}
61
a168c1c4 62sub _tables_list {
63 my $self = shift;
64 return map lc, $self->next::method;
65}
66
67sub _table_pk_info {
68 my ($self, $table) = @_;
69 return $self->next::method(uc $table);
70}
71
72sub _table_fk_info {
73 my ($self, $table) = @_;
74
75 my $rels = $self->next::method(uc $table);
76
77 foreach my $rel (@$rels) {
78 $rel->{remote_table} = lc $rel->{remote_table};
79 }
80
81 return $rels;
82}
83
84sub _columns_info_for {
85 my ($self, $table) = @_;
86 return $self->next::method(uc $table);
87}
88
996be9ee 89=head1 SEE ALSO
90
91L<DBIx::Class::Schema::Loader>, L<DBIx::Class::Schema::Loader::Base>,
92L<DBIx::Class::Schema::Loader::DBI>
93
94=cut
95
961;