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.07000';
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)', {});
41 if (not defined $self->preserve_case) {
42 $self->preserve_case(0);
46 sub _table_uniq_info {
47 my ($self, $table) = @_;
51 my $dbh = $self->schema->storage->dbh;
53 my $sth = $self->{_cache}->{db2_uniq} ||= $dbh->prepare(
54 q{SELECT kcu.COLNAME, kcu.CONSTNAME, kcu.COLSEQ
55 FROM SYSCAT.TABCONST as tc
56 JOIN SYSCAT.KEYCOLUSE as kcu
57 ON tc.CONSTNAME = kcu.CONSTNAME AND tc.TABSCHEMA = kcu.TABSCHEMA
58 WHERE tc.TABSCHEMA = ? and tc.TABNAME = ? and tc.TYPE = 'U'}
59 ) or die $DBI::errstr;
61 $sth->execute($self->db_schema, uc $table) or die $DBI::errstr;
64 while(my $row = $sth->fetchrow_arrayref) {
65 my ($col, $constname, $seq) = @$row;
66 push(@{$keydata{$constname}}, [ $seq, lc $col ]);
68 foreach my $keyname (keys %keydata) {
69 my @ordered_cols = map { $_->[1] } sort { $a->[0] <=> $b->[0] }
70 @{$keydata{$keyname}};
71 push(@uniqs, [ $keyname => \@ordered_cols ]);
79 # DBD::DB2 doesn't follow the DBI API for ->tables
81 my ($self, $opts) = @_;
83 my $dbh = $self->schema->storage->dbh;
84 my @tables = map { lc } $dbh->tables(
85 $self->db_schema ? { TABLE_SCHEM => $self->db_schema } : undef
87 s/\Q$self->{_quoter}\E//g for @tables;
88 s/^.*\Q$self->{_namesep}\E// for @tables;
90 return $self->_filter_tables(\@tables, $opts);
94 my ($self, $table) = @_;
95 return $self->next::method(uc $table);
99 my ($self, $table) = @_;
101 my $rels = $self->next::method(uc $table);
103 foreach my $rel (@$rels) {
104 $rel->{remote_table} = lc $rel->{remote_table};
110 sub _columns_info_for {
114 my $result = $self->next::method(uc $table);
116 my $dbh = $self->schema->storage->dbh;
118 while (my ($col, $info) = each %$result) {
119 # check for identities
120 my $sth = $dbh->prepare_cached(
124 WHERE tabschema = ? AND tabname = ? AND colname = ?
125 AND identity = 'Y' AND generated != ''
128 $sth->execute($self->db_schema, uc $table, uc $col);
129 if ($sth->fetchrow_array) {
130 $info->{is_auto_increment} = 1;
133 if (eval { lc ${ $info->{default_value} } }||'' eq 'current timestamp') {
134 ${ $info->{default_value} } = 'CURRENT_TIMESTAMP';
135 delete $info->{size};
144 L<DBIx::Class::Schema::Loader>, L<DBIx::Class::Schema::Loader::Base>,
145 L<DBIx::Class::Schema::Loader::DBI>
149 See L<DBIx::Class::Schema::Loader/AUTHOR> and L<DBIx::Class::Schema::Loader/CONTRIBUTORS>.
153 This library is free software; you can redistribute it and/or modify it under
154 the same terms as Perl itself.
159 # vim:et sts=4 sw=4 tw=0: