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.05001';
16 DBIx::Class::Schema::Loader::DBI::Oracle - DBIx::Class::Schema::Loader::DBI
17 Oracle Implementation.
22 use base qw/DBIx::Class::Schema::Loader/;
24 __PACKAGE__->loader_options( debug => 1 );
30 See L<DBIx::Class::Schema::Loader::Base>.
32 This module is considered experimental and not well tested yet.
39 $self->next::method(@_);
41 my $dbh = $self->schema->storage->dbh;
43 my ($current_schema) = $dbh->selectrow_array('SELECT USER FROM DUAL', {});
45 $self->{db_schema} ||= $current_schema;
47 if (lc($self->db_schema) ne lc($current_schema)) {
48 $dbh->do('ALTER SESSION SET current_schema=' . $self->db_schema);
53 my ($self, $table) = @_;
55 return $self->_quote_table_name($table);
61 my $dbh = $self->schema->storage->dbh;
64 for my $table ( $dbh->tables(undef, $self->db_schema, '%', 'TABLE,VIEW') ) { #catalog, schema, table, type
65 my $quoter = $dbh->get_info(29);
66 $table =~ s/$quoter//g;
68 # remove "user." (schema) prefixes
71 next if $table eq 'PLAN_TABLE';
74 if $table =~ /\A(\w+)\z/;
76 return $self->_filter_tables(@tables);
79 sub _table_uniq_info {
80 my ($self, $table) = @_;
82 my $dbh = $self->schema->storage->dbh;
84 my $sth = $dbh->prepare_cached(
86 SELECT constraint_name, acc.column_name
87 FROM all_constraints JOIN all_cons_columns acc USING (constraint_name)
88 WHERE acc.table_name=? and acc.owner = ? AND constraint_type='U'
93 $sth->execute(uc $table,$self->{db_schema} );
95 while(my $constr = $sth->fetchrow_arrayref) {
96 my $constr_name = lc $constr->[0];
97 my $constr_def = lc $constr->[1];
98 $constr_name =~ s/\Q$self->{_quoter}\E//;
99 $constr_def =~ s/\Q$self->{_quoter}\E//;
100 push @{$constr_names{$constr_name}}, $constr_def;
103 my @uniqs = map { [ $_ => $constr_names{$_} ] } keys %constr_names;
108 my ($self, $table) = @_;
109 return $self->next::method(uc $table);
113 my ($self, $table) = @_;
115 my $rels = $self->next::method(uc $table);
117 foreach my $rel (@$rels) {
118 $rel->{remote_table} = lc $rel->{remote_table};
124 sub _columns_info_for {
125 my ($self, $table) = @_;
126 return $self->next::method(uc $table);
129 sub _extra_column_info {
130 my ($self, $info) = @_;
133 my ($table, $column) = @$info{qw/TABLE_NAME COLUMN_NAME/};
135 my $dbh = $self->schema->storage->dbh;
136 my $sth = $dbh->prepare_cached(
139 FROM all_triggers ut JOIN all_trigger_cols atc USING (trigger_name)
140 WHERE atc.table_name = ? AND atc.column_name = ?
141 AND column_usage LIKE '%NEW%' AND column_usage LIKE '%OUT%'
142 AND trigger_type = 'BEFORE EACH ROW' AND triggering_event LIKE '%INSERT%'
146 $sth->execute($table, $column);
147 if ($sth->fetchrow_array) {
148 $extra_info{is_auto_increment} = 1;
156 L<DBIx::Class::Schema::Loader>, L<DBIx::Class::Schema::Loader::Base>,
157 L<DBIx::Class::Schema::Loader::DBI>
161 See L<DBIx::Class::Schema::Loader/AUTHOR> and L<DBIx::Class::Schema::Loader/CONTRIBUTORS>.
165 This library is free software; you can redistribute it and/or modify it under
166 the same terms as Perl itself.