X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FSchema%2FLoader%2FDBI%2FOracle.pm;h=957b00a89bc677090bc0132f87cd9085633011d6;hb=b1ad1a8402a5eb0955c6b76310809c2ab29291a9;hp=6c17767ab52778b10e52d066eaba2f4a03c74f2c;hpb=c39e35077d88eb3c81696032a2e51fdf5cb69eab;p=dbsrgits%2FDBIx-Class-Schema-Loader.git diff --git a/lib/DBIx/Class/Schema/Loader/DBI/Oracle.pm b/lib/DBIx/Class/Schema/Loader/DBI/Oracle.pm index 6c17767..957b00a 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/Oracle.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/Oracle.pm @@ -1,6 +1,4 @@ -package # hide from pause/cpan for now, as there's a permissions - # issue and it's screwing the rest of the package - DBIx::Class::Schema::Loader::DBI::Oracle; +package DBIx::Class::Schema::Loader::DBI::Oracle; use strict; use warnings; @@ -8,7 +6,7 @@ use base 'DBIx::Class::Schema::Loader::DBI'; use Carp::Clan qw/^DBIx::Class/; use Class::C3; -our $VERSION = '0.04002'; +our $VERSION = '0.04999_10'; =head1 NAME @@ -32,6 +30,16 @@ This module is considered experimental and not well tested yet. =cut +sub _setup { + my $self = shift; + + $self->next::method(@_); + + my $dbh = $self->schema->storage->dbh; + $self->{db_schema} ||= $dbh->selectrow_array('SELECT USER FROM DUAL', {}); +} + + sub _table_columns { my ($self, $table) = @_; @@ -66,68 +74,76 @@ sub _tables_list { sub _table_uniq_info { my ($self, $table) = @_; - my @uniqs; my $dbh = $self->schema->storage->dbh; my $sth = $dbh->prepare_cached( - qq{SELECT constraint_name, ucc.column_name FROM user_constraints JOIN user_cons_columns ucc USING (constraint_name) WHERE ucc.table_name=? AND constraint_type='U'} - ,{}, 1); - - $sth->execute(uc $table); + q{ + SELECT constraint_name, acc.column_name + FROM all_constraints JOIN all_cons_columns acc USING (constraint_name) + WHERE acc.table_name=? and acc.owner = ? AND constraint_type='U' + ORDER BY acc.position + }, + {}, 1); + + $sth->execute(uc $table,$self->{db_schema} ); my %constr_names; while(my $constr = $sth->fetchrow_arrayref) { - my $constr_name = $constr->[0]; - my $constr_def = $constr->[1]; + my $constr_name = lc $constr->[0]; + my $constr_def = lc $constr->[1]; $constr_name =~ s/\Q$self->{_quoter}\E//; $constr_def =~ s/\Q$self->{_quoter}\E//; - push @{$constr_names{$constr_name}}, lc $constr_def; + push @{$constr_names{$constr_name}}, $constr_def; } - map { - push(@uniqs, [ lc $_ => $constr_names{$_} ]); - } keys %constr_names; - + + my @uniqs = map { [ $_ => $constr_names{$_} ] } keys %constr_names; return \@uniqs; } sub _table_pk_info { - my ( $self, $table ) = @_; - return $self->SUPER::_table_pk_info(uc $table); + my ($self, $table) = @_; + return $self->next::method(uc $table); } sub _table_fk_info { my ($self, $table) = @_; - my $dbh = $self->schema->storage->dbh; - my $sth = $dbh->foreign_key_info( '', '', '', '', - $self->db_schema, uc $table ); - return [] if !$sth; - - my %rels; - - my $i = 1; # for unnamed rels, which hopefully have only 1 column ... - while(my $raw_rel = $sth->fetchrow_arrayref) { - my $uk_tbl = lc $raw_rel->[2]; - my $uk_col = lc $raw_rel->[3]; - my $fk_col = lc $raw_rel->[7]; - my $relid = ($raw_rel->[11] || ( "__dcsld__" . $i++ )); - $uk_tbl =~ s/\Q$self->{_quoter}\E//g; - $uk_col =~ s/\Q$self->{_quoter}\E//g; - $fk_col =~ s/\Q$self->{_quoter}\E//g; - $relid =~ s/\Q$self->{_quoter}\E//g; - $rels{$relid}->{tbl} = $uk_tbl; - $rels{$relid}->{cols}->{$uk_col} = $fk_col; + my $rels = $self->next::method(uc $table); + + foreach my $rel (@$rels) { + $rel->{remote_table} = lc $rel->{remote_table}; } - my @rels; - foreach my $relid (keys %rels) { - push(@rels, { - remote_columns => [ keys %{$rels{$relid}->{cols}} ], - local_columns => [ values %{$rels{$relid}->{cols}} ], - remote_table => $rels{$relid}->{tbl}, - }); + return $rels; +} + +sub _columns_info_for { + my ($self, $table) = @_; + return $self->next::method(uc $table); +} + +sub _extra_column_info { + my ($self, $info) = @_; + my %extra_info; + + my ($table, $column) = @$info{qw/TABLE_NAME COLUMN_NAME/}; + + my $dbh = $self->schema->storage->dbh; + my $sth = $dbh->prepare_cached( + q{ + SELECT COUNT(*) + FROM all_triggers ut JOIN all_trigger_cols atc USING (trigger_name) + WHERE atc.table_name = ? AND atc.column_name = ? + AND column_usage LIKE '%NEW%' AND column_usage LIKE '%OUT%' + AND trigger_type = 'BEFORE EACH ROW' AND triggering_event LIKE '%INSERT%' + }, + {}, 1); + + $sth->execute($table, $column); + if ($sth->fetchrow_array) { + $extra_info{is_auto_increment} = 1; } - return \@rels; + return \%extra_info; } =head1 SEE ALSO @@ -139,6 +155,8 @@ L TSUNODA Kazuya C +Dagfinn Ilmari Mannsåker C + =cut 1;