1 package DBIx::Class::Schema::Loader::DBI::DB2;
6 DBIx::Class::Schema::Loader::DBI::Component::QuotedDefault
7 DBIx::Class::Schema::Loader::DBI
9 use Carp::Clan qw/^DBIx::Class/;
12 our $VERSION = '0.06001';
16 DBIx::Class::Schema::Loader::DBI::DB2 - DBIx::Class::Schema::Loader::DBI DB2 Implementation.
21 use base qw/DBIx::Class::Schema::Loader/;
23 __PACKAGE__->loader_options( db_schema => "MYSCHEMA" );
29 See L<DBIx::Class::Schema::Loader::Base>.
36 $self->next::method(@_);
38 my $dbh = $self->schema->storage->dbh;
39 $self->{db_schema} ||= $dbh->selectrow_array('VALUES(CURRENT_USER)', {});
42 sub _table_uniq_info {
43 my ($self, $table) = @_;
47 my $dbh = $self->schema->storage->dbh;
49 my $sth = $self->{_cache}->{db2_uniq} ||= $dbh->prepare(
50 q{SELECT kcu.COLNAME, kcu.CONSTNAME, kcu.COLSEQ
51 FROM SYSCAT.TABCONST as tc
52 JOIN SYSCAT.KEYCOLUSE as kcu
53 ON tc.CONSTNAME = kcu.CONSTNAME AND tc.TABSCHEMA = kcu.TABSCHEMA
54 WHERE tc.TABSCHEMA = ? and tc.TABNAME = ? and tc.TYPE = 'U'}
55 ) or die $DBI::errstr;
57 $sth->execute($self->db_schema, uc $table) or die $DBI::errstr;
60 while(my $row = $sth->fetchrow_arrayref) {
61 my ($col, $constname, $seq) = @$row;
62 push(@{$keydata{$constname}}, [ $seq, lc $col ]);
64 foreach my $keyname (keys %keydata) {
65 my @ordered_cols = map { $_->[1] } sort { $a->[0] <=> $b->[0] }
66 @{$keydata{$keyname}};
67 push(@uniqs, [ $keyname => \@ordered_cols ]);
75 # DBD::DB2 doesn't follow the DBI API for ->tables
77 my ($self, $opts) = @_;
79 my $dbh = $self->schema->storage->dbh;
80 my @tables = map { lc } $dbh->tables(
81 $self->db_schema ? { TABLE_SCHEM => $self->db_schema } : undef
83 s/\Q$self->{_quoter}\E//g for @tables;
84 s/^.*\Q$self->{_namesep}\E// for @tables;
86 return $self->_filter_tables(\@tables, $opts);
90 my ($self, $table) = @_;
91 return $self->next::method(uc $table);
95 my ($self, $table) = @_;
97 my $rels = $self->next::method(uc $table);
99 foreach my $rel (@$rels) {
100 $rel->{remote_table} = lc $rel->{remote_table};
106 sub _columns_info_for {
107 my ($self, $table) = @_;
108 return $self->next::method(uc $table);
111 sub _extra_column_info {
112 my ($self, $table, $column, $info, $dbi_info) = @_;
115 my $dbh = $self->schema->storage->dbh;
116 my $sth = $dbh->prepare_cached(
120 WHERE tabschema = ? AND tabname = ? AND colname = ?
121 AND identity = 'Y' AND generated != ''
124 $sth->execute($self->db_schema, $table, $column);
125 if ($sth->fetchrow_array) {
126 $extra_info{is_auto_increment} = 1;
134 L<DBIx::Class::Schema::Loader>, L<DBIx::Class::Schema::Loader::Base>,
135 L<DBIx::Class::Schema::Loader::DBI>
139 See L<DBIx::Class::Schema::Loader/AUTHOR> and L<DBIx::Class::Schema::Loader/CONTRIBUTORS>.
143 This library is free software; you can redistribute it and/or modify it under
144 the same terms as Perl itself.