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);
40 if (not defined $self->preserve_case) {
41 $self->preserve_case(0);
46 my ($self, $table) = @_;
48 return $self->_quote_table_name($table);
52 my ($self, $opts) = @_;
54 my $dbh = $self->schema->storage->dbh;
57 for my $table ( $dbh->tables(undef, $self->db_schema, '%', 'TABLE,VIEW') ) { #catalog, schema, table, type
58 my $quoter = $dbh->get_info(29);
59 $table =~ s/$quoter//g;
61 # remove "user." (schema) prefixes
64 next if $table eq 'PLAN_TABLE';
67 if $table =~ /\A(\w+)\z/;
70 return $self->_filter_tables(\@tables, $opts);
74 my ($self, $table) = @_;
76 my $dbh = $self->schema->storage->dbh;
78 my $sth = $dbh->column_info(undef, $self->db_schema, uc $table, '%');
79 return [ map lc($_->{COLUMN_NAME}), @{ $sth->fetchall_arrayref({ COLUMN_NAME => 1 }) || [] } ];
82 sub _table_uniq_info {
83 my ($self, $table) = @_;
85 my $dbh = $self->schema->storage->dbh;
87 my $sth = $dbh->prepare_cached(
89 SELECT constraint_name, acc.column_name
90 FROM all_constraints JOIN all_cons_columns acc USING (constraint_name)
91 WHERE acc.table_name=? and acc.owner = ? AND constraint_type='U'
96 $sth->execute(uc $table,$self->{db_schema} );
98 while(my $constr = $sth->fetchrow_arrayref) {
99 my $constr_name = lc $constr->[0];
100 my $constr_def = lc $constr->[1];
101 $constr_name =~ s/\Q$self->{_quoter}\E//;
102 $constr_def =~ s/\Q$self->{_quoter}\E//;
103 push @{$constr_names{$constr_name}}, $constr_def;
106 my @uniqs = map { [ $_ => $constr_names{$_} ] } keys %constr_names;
111 my ($self, $table) = @_;
112 return $self->next::method(uc $table);
116 my ($self, $table) = @_;
118 my $rels = $self->next::method(uc $table);
120 foreach my $rel (@$rels) {
121 $rel->{remote_table} = lc $rel->{remote_table};
127 sub _columns_info_for {
128 my ($self, $table) = (shift, shift);
130 my $result = $self->next::method(uc $table, @_);
132 my $dbh = $self->schema->storage->dbh;
134 my $sth = $dbh->prepare_cached(q{
135 SELECT atc.column_name
137 JOIN all_trigger_cols atc USING (trigger_name)
138 WHERE atc.table_name = ?
139 AND lower(column_usage) LIKE '%new%' AND lower(column_usage) LIKE '%out%'
140 AND upper(trigger_type) LIKE '%BEFORE EACH ROW%' AND lower(triggering_event) LIKE '%insert%'
143 $sth->execute(uc $table);
145 while (my ($col_name) = $sth->fetchrow_array) {
146 $result->{lc $col_name}{is_auto_increment} = 1;
149 while (my ($col, $info) = each %$result) {
150 no warnings 'uninitialized';
152 if ($info->{data_type} =~ /^(?:n?[cb]lob|long(?: raw)?|bfile|date|binary_(?:float|double)|rowid)\z/i) {
153 delete $info->{size};
156 if ($info->{data_type} =~ /^n(?:var)?char2?\z/i) {
157 $info->{size} = $info->{size} / 2;
159 elsif (lc($info->{data_type}) eq 'number') {
160 $info->{data_type} = 'numeric';
162 if (eval { $info->{size}[0] == 38 && $info->{size}[1] == 0 }) {
163 $info->{data_type} = 'integer';
164 delete $info->{size};
167 elsif (my ($precision) = $info->{data_type} =~ /^timestamp\((\d+)\)(?: with (?:local )?time zone)?\z/i) {
168 $info->{data_type} = join ' ', $info->{data_type} =~ /[a-z]+/ig;
170 if ($precision == 6) {
171 delete $info->{size};
174 $info->{size} = $precision;
177 elsif (($precision) = $info->{data_type} =~ /^interval year\((\d+)\) to month\z/i) {
178 $info->{data_type} = join ' ', $info->{data_type} =~ /[a-z]+/ig;
180 if ($precision == 2) {
181 delete $info->{size};
184 $info->{size} = $precision;
187 elsif (my ($day_precision, $second_precision) = $info->{data_type} =~ /^interval day\((\d+)\) to second\((\d+)\)\z/i) {
188 $info->{data_type} = join ' ', $info->{data_type} =~ /[a-z]+/ig;
190 if ($day_precision == 2 && $second_precision == 6) {
191 delete $info->{size};
194 $info->{size} = [ $day_precision, $second_precision ];
197 elsif (lc($info->{data_type}) eq 'urowid' && $info->{size} == 4000) {
198 delete $info->{size};
201 if (eval { lc(${ $info->{default_value} }) eq 'sysdate' }) {
202 ${ $info->{default_value} } = 'current_timestamp';
211 L<DBIx::Class::Schema::Loader>, L<DBIx::Class::Schema::Loader::Base>,
212 L<DBIx::Class::Schema::Loader::DBI>
216 See L<DBIx::Class::Schema::Loader/AUTHOR> and L<DBIx::Class::Schema::Loader/CONTRIBUTORS>.
220 This library is free software; you can redistribute it and/or modify it under
221 the same terms as Perl itself.
226 # vim:et sts=4 sw=4 tw=0: