Commit | Line | Data |
c39e3507 |
1 | package # hide from pause/cpan for now, as there's a permissions |
2 | # issue and it's screwing the rest of the package |
3 | DBIx::Class::Schema::Loader::DBI::Oracle; |
e7262300 |
4 | |
5 | use strict; |
6 | use warnings; |
7 | use base 'DBIx::Class::Schema::Loader::DBI'; |
8 | use Carp::Clan qw/^DBIx::Class/; |
9 | use Class::C3; |
10 | |
a6db40af |
11 | our $VERSION = '0.04005'; |
e7262300 |
12 | |
13 | =head1 NAME |
14 | |
15 | DBIx::Class::Schema::Loader::DBI::Oracle - DBIx::Class::Schema::Loader::DBI |
16 | Oracle Implementation. |
17 | |
18 | =head1 SYNOPSIS |
19 | |
20 | package My::Schema; |
21 | use base qw/DBIx::Class::Schema::Loader/; |
22 | |
23 | __PACKAGE__->loader_options( debug => 1 ); |
24 | |
25 | 1; |
26 | |
27 | =head1 DESCRIPTION |
28 | |
29 | See L<DBIx::Class::Schema::Loader::Base>. |
30 | |
31 | This module is considered experimental and not well tested yet. |
32 | |
33 | =cut |
34 | |
d0e184e9 |
35 | sub _setup { |
36 | my $self = shift; |
37 | |
38 | $self->next::method(@_); |
39 | |
40 | my $dbh = $self->schema->storage->dbh; |
41 | $self->{db_schema} ||= $dbh->selectrow_array('SELECT USER FROM DUAL', {}); |
42 | } |
43 | |
44 | |
e7262300 |
45 | sub _table_columns { |
46 | my ($self, $table) = @_; |
47 | |
48 | my $dbh = $self->schema->storage->dbh; |
49 | |
50 | my $sth = $dbh->prepare($self->schema->storage->sql_maker->select($table, undef, \'1 = 0')); |
51 | $sth->execute; |
52 | return \@{$sth->{NAME_lc}}; |
53 | } |
54 | |
55 | sub _tables_list { |
56 | my $self = shift; |
57 | |
58 | my $dbh = $self->schema->storage->dbh; |
59 | |
60 | my @tables; |
61 | for my $table ( $dbh->tables(undef, $self->db_schema, '%', 'TABLE,VIEW') ) { #catalog, schema, table, type |
62 | my $quoter = $dbh->get_info(29); |
63 | $table =~ s/$quoter//g; |
64 | |
65 | # remove "user." (schema) prefixes |
66 | $table =~ s/\w+\.//; |
67 | |
68 | next if $table eq 'PLAN_TABLE'; |
69 | $table = lc $table; |
70 | push @tables, $1 |
71 | if $table =~ /\A(\w+)\z/; |
72 | } |
73 | return @tables; |
74 | } |
75 | |
76 | sub _table_uniq_info { |
77 | my ($self, $table) = @_; |
78 | |
e7262300 |
79 | my $dbh = $self->schema->storage->dbh; |
80 | |
81 | my $sth = $dbh->prepare_cached( |
65ab592d |
82 | q{ |
83 | SELECT constraint_name, ucc.column_name |
84 | FROM user_constraints JOIN user_cons_columns ucc USING (constraint_name) |
85 | WHERE ucc.table_name=? AND constraint_type='U' |
fbc9e196 |
86 | ORDER BY ucc.position |
65ab592d |
87 | }, |
88 | {}, 1); |
e7262300 |
89 | |
90 | $sth->execute(uc $table); |
91 | my %constr_names; |
92 | while(my $constr = $sth->fetchrow_arrayref) { |
65ab592d |
93 | my $constr_name = lc $constr->[0]; |
94 | my $constr_def = lc $constr->[1]; |
e7262300 |
95 | $constr_name =~ s/\Q$self->{_quoter}\E//; |
96 | $constr_def =~ s/\Q$self->{_quoter}\E//; |
65ab592d |
97 | push @{$constr_names{$constr_name}}, $constr_def; |
e7262300 |
98 | } |
65ab592d |
99 | |
100 | my @uniqs = map { [ $_ => $constr_names{$_} ] } keys %constr_names; |
e7262300 |
101 | return \@uniqs; |
102 | } |
103 | |
104 | sub _table_pk_info { |
65ab592d |
105 | my ($self, $table) = @_; |
106 | return $self->next::method(uc $table); |
e7262300 |
107 | } |
108 | |
109 | sub _table_fk_info { |
110 | my ($self, $table) = @_; |
111 | |
65ab592d |
112 | my $rels = $self->next::method(uc $table); |
e7262300 |
113 | |
65ab592d |
114 | foreach my $rel (@$rels) { |
115 | $rel->{remote_table} = lc $rel->{remote_table}; |
e7262300 |
116 | } |
117 | |
65ab592d |
118 | return $rels; |
119 | } |
120 | |
121 | sub _columns_info_for { |
122 | my ($self, $table) = @_; |
123 | return $self->next::method(uc $table); |
e7262300 |
124 | } |
125 | |
126 | =head1 SEE ALSO |
127 | |
128 | L<DBIx::Class::Schema::Loader>, L<DBIx::Class::Schema::Loader::Base>, |
129 | L<DBIx::Class::Schema::Loader::DBI> |
130 | |
131 | =head1 AUTHOR |
132 | |
133 | TSUNODA Kazuya C<drk@drk7.jp> |
134 | |
135 | =cut |
136 | |
137 | 1; |