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);
44 elsif ($self->preserve_case) {
45 $self->schema->storage->sql_maker->quote_char('"');
46 $self->schema->storage->sql_maker->name_sep('.');
50 sub _table_uniq_info {
51 my ($self, $table) = @_;
55 my $dbh = $self->schema->storage->dbh;
57 my $sth = $self->{_cache}->{db2_uniq} ||= $dbh->prepare(
58 q{SELECT kcu.COLNAME, kcu.CONSTNAME, kcu.COLSEQ
59 FROM SYSCAT.TABCONST as tc
60 JOIN SYSCAT.KEYCOLUSE as kcu
61 ON tc.CONSTNAME = kcu.CONSTNAME AND tc.TABSCHEMA = kcu.TABSCHEMA
62 WHERE tc.TABSCHEMA = ? and tc.TABNAME = ? and tc.TYPE = 'U'}
63 ) or die $DBI::errstr;
65 $sth->execute($self->db_schema, $self->_uc($table)) or die $DBI::errstr;
68 while(my $row = $sth->fetchrow_arrayref) {
69 my ($col, $constname, $seq) = @$row;
70 push(@{$keydata{$constname}}, [ $seq, $self->_lc($col) ]);
72 foreach my $keyname (keys %keydata) {
73 my @ordered_cols = map { $_->[1] } sort { $a->[0] <=> $b->[0] }
74 @{$keydata{$keyname}};
75 push(@uniqs, [ $keyname => \@ordered_cols ]);
83 # DBD::DB2 doesn't follow the DBI API for ->tables
85 my ($self, $opts) = @_;
87 my $dbh = $self->schema->storage->dbh;
88 my @tables = map $self->_lc($_), $dbh->tables(
89 $self->db_schema ? { TABLE_SCHEM => $self->db_schema } : undef
91 s/\Q$self->{_quoter}\E//g for @tables;
92 s/^.*\Q$self->{_namesep}\E// for @tables;
94 return $self->_filter_tables(\@tables, $opts);
98 my ($self, $table) = @_;
99 return $self->next::method($self->_uc($table));
103 my ($self, $table) = @_;
105 my $rels = $self->next::method($self->_uc($table));
107 foreach my $rel (@$rels) {
108 $rel->{remote_table} = $self->_lc($rel->{remote_table});
114 sub _columns_info_for {
118 my $result = $self->next::method($self->_uc($table));
120 my $dbh = $self->schema->storage->dbh;
122 while (my ($col, $info) = each %$result) {
123 # check for identities
124 my $sth = $dbh->prepare_cached(
128 WHERE tabschema = ? AND tabname = ? AND colname = ?
129 AND identity = 'Y' AND generated != ''
132 $sth->execute($self->db_schema, $self->_uc($table), $self->_uc($col));
133 if ($sth->fetchrow_array) {
134 $info->{is_auto_increment} = 1;
137 if ((eval { lc ${ $info->{default_value} } }||'') eq 'current timestamp') {
138 ${ $info->{default_value} } = 'current_timestamp';
139 delete $info->{size};
141 my $orig_deflt = 'current timestamp';
142 $info->{original}{default_value} = \$orig_deflt;
151 L<DBIx::Class::Schema::Loader>, L<DBIx::Class::Schema::Loader::Base>,
152 L<DBIx::Class::Schema::Loader::DBI>
156 See L<DBIx::Class::Schema::Loader/AUTHOR> and L<DBIx::Class::Schema::Loader/CONTRIBUTORS>.
160 This library is free software; you can redistribute it and/or modify it under
161 the same terms as Perl itself.
166 # vim:et sts=4 sw=4 tw=0: