X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FSchema%2FLoader%2FDBI%2FDB2.pm;h=bd9f061e780e1fb1ec9458758286122d24ee85d9;hb=53c4835c7c3e764f0881b196fb29f348916e8411;hp=75a92d9056f080fe4f6ce2ac08649792df1d74be;hpb=c4a69b87bd3d3fdda08f05d363311a6e9d3fc0f7;p=dbsrgits%2FDBIx-Class-Schema-Loader.git diff --git a/lib/DBIx/Class/Schema/Loader/DBI/DB2.pm b/lib/DBIx/Class/Schema/Loader/DBI/DB2.pm index 75a92d9..bd9f061 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/DB2.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/DB2.pm @@ -13,7 +13,7 @@ use namespace::clean; use DBIx::Class::Schema::Loader::Table (); -our $VERSION = '0.07010'; +our $VERSION = '0.07040'; =head1 NAME @@ -75,14 +75,14 @@ EOF 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; } @@ -91,7 +91,8 @@ sub _table_fk_info { 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 @@ -112,9 +113,16 @@ EOF 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 '%' @@ -132,17 +140,26 @@ EOF $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 _columns_info_for {