DBIx::Class::Schema::Loader::DBI
/;
use mro 'c3';
-
-use List::MoreUtils 'any';
-use namespace::clean;
-
+use List::Util 'any';
use DBIx::Class::Schema::Loader::Table ();
+use namespace::clean;
-our $VERSION = '0.07023';
+our $VERSION = '0.07047';
=head1 NAME
my ($col, $constname, $seq) = @$row;
push(@{$keydata{$constname}}, [ $seq, $self->_lc($col) ]);
}
- foreach my $keyname (keys %keydata) {
+ foreach my $keyname (sort keys %keydata) {
my @ordered_cols = map { $_->[1] } sort { $a->[0] <=> $b->[0] }
@{$keydata{$keyname}};
push(@uniqs, [ $keyname => \@ordered_cols ]);
}
$sth->finish;
-
+
return \@uniqs;
}
my $sth = $self->{_cache}->{db2_fk} ||= $self->dbh->prepare(<<'EOF');
SELECT tc.constname, sr.reftabschema, sr.reftabname,
- kcu.colname, rkcu.colname, kcu.colseq
+ kcu.colname, rkcu.colname, kcu.colseq,
+ sr.deleterule, sr.updaterule
FROM syscat.tabconst tc
JOIN syscat.keycoluse kcu
ON tc.constname = kcu.constname
AND tc.tabname = sr.tabname
JOIN syscat.keycoluse rkcu
ON sr.refkeyname = rkcu.constname
+ AND sr.reftabschema = rkcu.tabschema
+ AND sr.reftabname = rkcu.tabname
AND kcu.colseq = rkcu.colseq
WHERE tc.tabschema = ?
AND tc.tabname = ?
my %rels;
+ my %rules = (
+ A => 'NO ACTION',
+ C => 'CASCADE',
+ N => 'SET NULL',
+ R => 'RESTRICT',
+ );
+
COLS: while (my @row = $sth->fetchrow_array) {
my ($fk, $remote_schema, $remote_table, $local_col, $remote_col,
- $colseq) = @row;
+ $colseq, $delete_rule, $update_rule) = @row;
if (not exists $rels{$fk}) {
if ($self->db_schema && $self->db_schema->[0] ne '%'
$rels{$fk}{local_columns}[$colseq-1] = $self->_lc($local_col);
$rels{$fk}{remote_columns}[$colseq-1] = $self->_lc($remote_col);
+
+ $rels{$fk}{attrs} ||= {
+ on_delete => $rules{$delete_rule},
+ on_update => $rules{$update_rule},
+ is_deferrable => 1, # DB2 has no deferrable constraints
+ };
}
return [ values %rels ];
}
-# DBD::DB2 doesn't follow the DBI API for ->tables
+# DBD::DB2 doesn't follow the DBI API for ->tables (pre 1.85), but since its
+# backwards compatible we don't change it.
+# DBD::DB2 1.85 and beyond default TABLE_NAME to '', previously defaulted to
+# '%'. so we supply it.
sub _dbh_tables {
my ($self, $schema) = @_;
- return $self->dbh->tables($schema ? { TABLE_SCHEM => $schema } : undef);
+ return $self->dbh->tables($schema ? { TABLE_SCHEM => $schema, TABLE_NAME => '%' } : undef);
+}
+
+sub _dbh_table_info {
+ my $self = shift;
+
+ local $^W = 0; # shut up undef warning from DBD::DB2
+
+ $self->next::method(@_);
}
sub _columns_info_for {
L<DBIx::Class::Schema::Loader>, L<DBIx::Class::Schema::Loader::Base>,
L<DBIx::Class::Schema::Loader::DBI>
-=head1 AUTHOR
+=head1 AUTHORS
-See L<DBIx::Class::Schema::Loader/AUTHOR> and L<DBIx::Class::Schema::Loader/CONTRIBUTORS>.
+See L<DBIx::Class::Schema::Loader/AUTHORS>.
=head1 LICENSE