Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

this makes oracle materialised views and DDL parse correctly #27

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/DBIx/Class/Schema/Loader/Base.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2696,7 +2696,7 @@ sub _setup_src_meta {
}

my @non_nullable_uniqs = grep {
all { $col_info->{$_}{is_nullable} == 0 } @{ $_->[1] }
all { exists $col_info->{$_} && $col_info->{$_}{is_nullable} == 0 } @{ $_->[1] }
} @uniqs;

if ($self->uniq_to_primary && (not @$pks) && @non_nullable_uniqs) {
Expand Down
22 changes: 19 additions & 3 deletions lib/DBIx/Class/Schema/Loader/DBI/Oracle.pm
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,19 @@ EOF
sub _table_uniq_info {
my ($self, $table) = @_;

## Oracle's DDL for materialised views makes it really easy to conflate
## with tables. Adding the left join here means don't pick up
## spurious virtual column constraints for mvs
my $sth = $self->dbh->prepare_cached(<<'EOF', {}, 1);
SELECT ac.constraint_name, acc.column_name
FROM all_constraints ac, all_cons_columns acc
LEFT JOIN all_mviews mv on mv.owner = acc.owner and mv.mview_name = acc.table_name
WHERE acc.table_name=? AND acc.owner = ?
AND ac.table_name = acc.table_name AND ac.owner = acc.owner
AND acc.constraint_name = ac.constraint_name
AND ac.constraint_type = 'U'
AND ac.status = 'ENABLED'
AND mv.mview_name is null
ORDER BY acc.position
EOF

Expand Down Expand Up @@ -415,12 +420,23 @@ sub _dbh_column_info {

sub _view_definition {
my ($self, $view) = @_;

return scalar $self->schema->storage->dbh->selectrow_array(<<'EOF', {}, $view->schema, $view->name);
my $viewdef = scalar $self->schema->storage->dbh
->selectrow_array(<<'EOF', {}, $view->name, $view->schema);
SELECT text
FROM all_views
WHERE owner = ? AND view_name = ?
WHERE view_name = ? AND owner = ?
EOF
return $viewdef if $viewdef;
if ($DBD::Oracle::VERSION < 1.81) {
warn "DBD::Oracle must be version 1.81 or greater to be able to find materialised views\n";
return '';
}
my $mview = eval { scalar $self->schema->storage->dbh
->selectrow_array(<<'EOF', {}, $view->name, $view->schema);
select dbms_metadata.get_ddl('MATERIALIZED_VIEW', ?, ?) from dual
EOF
};
return $mview;
}

=head1 SEE ALSO
Expand Down