Commit | Line | Data |
d87d939a |
1 | package DBIx::Class::Schema::Loader::DBI::Oracle; |
e7262300 |
2 | |
3 | use strict; |
4 | use warnings; |
6b0e47fc |
5 | use base qw/ |
6 | DBIx::Class::Schema::Loader::DBI::Component::QuotedDefault |
7 | DBIx::Class::Schema::Loader::DBI |
8 | /; |
e7262300 |
9 | use Carp::Clan qw/^DBIx::Class/; |
10 | use Class::C3; |
11 | |
9990e58f |
12 | our $VERSION = '0.07000'; |
e7262300 |
13 | |
14 | =head1 NAME |
15 | |
16 | DBIx::Class::Schema::Loader::DBI::Oracle - DBIx::Class::Schema::Loader::DBI |
17 | Oracle Implementation. |
18 | |
e7262300 |
19 | =head1 DESCRIPTION |
20 | |
21 | See L<DBIx::Class::Schema::Loader::Base>. |
22 | |
e7262300 |
23 | =cut |
24 | |
d0e184e9 |
25 | sub _setup { |
26 | my $self = shift; |
27 | |
28 | $self->next::method(@_); |
29 | |
30 | my $dbh = $self->schema->storage->dbh; |
46065bcb |
31 | |
32 | my ($current_schema) = $dbh->selectrow_array('SELECT USER FROM DUAL', {}); |
33 | |
34 | $self->{db_schema} ||= $current_schema; |
35 | |
36 | if (lc($self->db_schema) ne lc($current_schema)) { |
37 | $dbh->do('ALTER SESSION SET current_schema=' . $self->db_schema); |
38 | } |
d0e184e9 |
39 | } |
40 | |
075aff97 |
41 | sub _table_as_sql { |
e7262300 |
42 | my ($self, $table) = @_; |
43 | |
075aff97 |
44 | return $self->_quote_table_name($table); |
e7262300 |
45 | } |
46 | |
47 | sub _tables_list { |
bfb43060 |
48 | my ($self, $opts) = @_; |
e7262300 |
49 | |
50 | my $dbh = $self->schema->storage->dbh; |
51 | |
52 | my @tables; |
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; |
56 | |
57 | # remove "user." (schema) prefixes |
58 | $table =~ s/\w+\.//; |
59 | |
60 | next if $table eq 'PLAN_TABLE'; |
61 | $table = lc $table; |
62 | push @tables, $1 |
63 | if $table =~ /\A(\w+)\z/; |
64 | } |
ffb03c96 |
65 | |
bfb43060 |
66 | return $self->_filter_tables(\@tables, $opts); |
e7262300 |
67 | } |
68 | |
4337bddf |
69 | sub _table_columns { |
70 | my ($self, $table) = @_; |
71 | |
72 | my $dbh = $self->schema->storage->dbh; |
73 | |
74 | my $sth = $dbh->column_info(undef, $self->db_schema, uc $table, '%'); |
75 | return [ map lc($_->{COLUMN_NAME}), @{ $sth->fetchall_arrayref({ COLUMN_NAME => 1 }) || [] } ]; |
76 | } |
77 | |
e7262300 |
78 | sub _table_uniq_info { |
79 | my ($self, $table) = @_; |
80 | |
e7262300 |
81 | my $dbh = $self->schema->storage->dbh; |
82 | |
83 | my $sth = $dbh->prepare_cached( |
65ab592d |
84 | q{ |
c7bf4194 |
85 | SELECT constraint_name, acc.column_name |
86 | FROM all_constraints JOIN all_cons_columns acc USING (constraint_name) |
8803e4ed |
87 | WHERE acc.table_name=? and acc.owner = ? AND constraint_type='U' |
c7bf4194 |
88 | ORDER BY acc.position |
65ab592d |
89 | }, |
90 | {}, 1); |
e7262300 |
91 | |
8803e4ed |
92 | $sth->execute(uc $table,$self->{db_schema} ); |
e7262300 |
93 | my %constr_names; |
94 | while(my $constr = $sth->fetchrow_arrayref) { |
65ab592d |
95 | my $constr_name = lc $constr->[0]; |
96 | my $constr_def = lc $constr->[1]; |
e7262300 |
97 | $constr_name =~ s/\Q$self->{_quoter}\E//; |
98 | $constr_def =~ s/\Q$self->{_quoter}\E//; |
65ab592d |
99 | push @{$constr_names{$constr_name}}, $constr_def; |
e7262300 |
100 | } |
65ab592d |
101 | |
102 | my @uniqs = map { [ $_ => $constr_names{$_} ] } keys %constr_names; |
e7262300 |
103 | return \@uniqs; |
104 | } |
105 | |
106 | sub _table_pk_info { |
65ab592d |
107 | my ($self, $table) = @_; |
108 | return $self->next::method(uc $table); |
e7262300 |
109 | } |
110 | |
111 | sub _table_fk_info { |
112 | my ($self, $table) = @_; |
113 | |
65ab592d |
114 | my $rels = $self->next::method(uc $table); |
e7262300 |
115 | |
65ab592d |
116 | foreach my $rel (@$rels) { |
117 | $rel->{remote_table} = lc $rel->{remote_table}; |
e7262300 |
118 | } |
119 | |
65ab592d |
120 | return $rels; |
121 | } |
122 | |
123 | sub _columns_info_for { |
124 | my ($self, $table) = @_; |
125 | return $self->next::method(uc $table); |
e7262300 |
126 | } |
127 | |
fb328d1a |
128 | sub _extra_column_info { |
45be2ce7 |
129 | my ($self, $table, $column, $info, $dbi_info) = @_; |
fb328d1a |
130 | my %extra_info; |
131 | |
fb328d1a |
132 | my $dbh = $self->schema->storage->dbh; |
133 | my $sth = $dbh->prepare_cached( |
134 | q{ |
135 | SELECT COUNT(*) |
c7bf4194 |
136 | FROM all_triggers ut JOIN all_trigger_cols atc USING (trigger_name) |
137 | WHERE atc.table_name = ? AND atc.column_name = ? |
4337bddf |
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%' |
fb328d1a |
140 | }, |
141 | {}, 1); |
142 | |
143 | $sth->execute($table, $column); |
144 | if ($sth->fetchrow_array) { |
145 | $extra_info{is_auto_increment} = 1; |
146 | } |
147 | |
148 | return \%extra_info; |
149 | } |
150 | |
e7262300 |
151 | =head1 SEE ALSO |
152 | |
153 | L<DBIx::Class::Schema::Loader>, L<DBIx::Class::Schema::Loader::Base>, |
154 | L<DBIx::Class::Schema::Loader::DBI> |
155 | |
156 | =head1 AUTHOR |
157 | |
9cc8e7e1 |
158 | See L<DBIx::Class::Schema::Loader/AUTHOR> and L<DBIx::Class::Schema::Loader/CONTRIBUTORS>. |
e7262300 |
159 | |
be80bba7 |
160 | =head1 LICENSE |
161 | |
162 | This library is free software; you can redistribute it and/or modify it under |
163 | the same terms as Perl itself. |
fb328d1a |
164 | |
e7262300 |
165 | =cut |
166 | |
167 | 1; |