1 package DBIx::Class::Schema::Loader::DBI::Oracle;
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::Oracle - DBIx::Class::Schema::Loader::DBI
17 Oracle Implementation.
21 See L<DBIx::Class::Schema::Loader::Base>.
28 $self->next::method(@_);
30 my $dbh = $self->schema->storage->dbh;
32 my ($current_schema) = $dbh->selectrow_array('SELECT USER FROM DUAL', {});
34 $self->{db_schema} ||= $current_schema;
36 if (lc($self->db_schema) ne lc($current_schema)) {
37 $dbh->do('ALTER SESSION SET current_schema=' . $self->db_schema);
42 my ($self, $table) = @_;
44 return $self->_quote_table_name($table);
48 my ($self, $opts) = @_;
50 my $dbh = $self->schema->storage->dbh;
53 for my $table ( $dbh->tables(undef, $self->db_schema, '%', 'TABLE,VIEW') ) { #catalog, schema, table, type
54 my $quoter = $dbh->get_info(29);
55 $table =~ s/$quoter//g;
57 # remove "user." (schema) prefixes
60 next if $table eq 'PLAN_TABLE';
63 if $table =~ /\A(\w+)\z/;
66 return $self->_filter_tables(\@tables, $opts);
70 my ($self, $table) = @_;
72 my $dbh = $self->schema->storage->dbh;
74 my $sth = $dbh->column_info(undef, $self->db_schema, uc $table, '%');
75 return [ map lc($_->{COLUMN_NAME}), @{ $sth->fetchall_arrayref({ COLUMN_NAME => 1 }) || [] } ];
78 sub _table_uniq_info {
79 my ($self, $table) = @_;
81 my $dbh = $self->schema->storage->dbh;
83 my $sth = $dbh->prepare_cached(
85 SELECT constraint_name, acc.column_name
86 FROM all_constraints JOIN all_cons_columns acc USING (constraint_name)
87 WHERE acc.table_name=? and acc.owner = ? AND constraint_type='U'
92 $sth->execute(uc $table,$self->{db_schema} );
94 while(my $constr = $sth->fetchrow_arrayref) {
95 my $constr_name = lc $constr->[0];
96 my $constr_def = lc $constr->[1];
97 $constr_name =~ s/\Q$self->{_quoter}\E//;
98 $constr_def =~ s/\Q$self->{_quoter}\E//;
99 push @{$constr_names{$constr_name}}, $constr_def;
102 my @uniqs = map { [ $_ => $constr_names{$_} ] } keys %constr_names;
107 my ($self, $table) = @_;
108 return $self->next::method(uc $table);
112 my ($self, $table) = @_;
114 my $rels = $self->next::method(uc $table);
116 foreach my $rel (@$rels) {
117 $rel->{remote_table} = lc $rel->{remote_table};
123 sub _columns_info_for {
124 my ($self, $table) = @_;
125 return $self->next::method(uc $table);
128 sub _extra_column_info {
129 my ($self, $table, $column, $info, $dbi_info) = @_;
132 my $dbh = $self->schema->storage->dbh;
133 my $sth = $dbh->prepare_cached(
136 FROM all_triggers ut JOIN all_trigger_cols atc USING (trigger_name)
137 WHERE atc.table_name = ? AND atc.column_name = ?
138 AND lower(column_usage) LIKE '%new%' AND lower(column_usage) LIKE '%out%'
139 AND trigger_type = 'BEFORE EACH ROW' AND lower(triggering_event) LIKE '%insert%'
143 $sth->execute($table, $column);
144 if ($sth->fetchrow_array) {
145 $extra_info{is_auto_increment} = 1;
153 L<DBIx::Class::Schema::Loader>, L<DBIx::Class::Schema::Loader::Base>,
154 L<DBIx::Class::Schema::Loader::DBI>
158 See L<DBIx::Class::Schema::Loader/AUTHOR> and L<DBIx::Class::Schema::Loader/CONTRIBUTORS>.
162 This library is free software; you can redistribute it and/or modify it under
163 the same terms as Perl itself.