support CamelCase table names
[dbsrgits/DBIx-Class-Schema-Loader.git] / lib / DBIx / Class / Schema / Loader / DBI / Oracle.pm
index 7d8150b..d93cfe3 100644 (file)
@@ -2,32 +2,24 @@ package DBIx::Class::Schema::Loader::DBI::Oracle;
 
 use strict;
 use warnings;
-use base 'DBIx::Class::Schema::Loader::DBI';
+use base qw/
+    DBIx::Class::Schema::Loader::DBI::Component::QuotedDefault
+    DBIx::Class::Schema::Loader::DBI
+/;
 use Carp::Clan qw/^DBIx::Class/;
 use Class::C3;
 
-our $VERSION = '0.04999_09';
+our $VERSION = '0.07000';
 
 =head1 NAME
 
 DBIx::Class::Schema::Loader::DBI::Oracle - DBIx::Class::Schema::Loader::DBI 
 Oracle Implementation.
 
-=head1 SYNOPSIS
-
-  package My::Schema;
-  use base qw/DBIx::Class::Schema::Loader/;
-
-  __PACKAGE__->loader_options( debug => 1 );
-
-  1;
-
 =head1 DESCRIPTION
 
 See L<DBIx::Class::Schema::Loader::Base>.
 
-This module is considered experimental and not well tested yet.
-
 =cut
 
 sub _setup {
@@ -36,22 +28,24 @@ sub _setup {
     $self->next::method(@_);
 
     my $dbh = $self->schema->storage->dbh;
-    $self->{db_schema} ||= $dbh->selectrow_array('SELECT USER FROM DUAL', {});
-}
 
+    my ($current_schema) = $dbh->selectrow_array('SELECT USER FROM DUAL', {});
 
-sub _table_columns {
-    my ($self, $table) = @_;
+    $self->{db_schema} ||= $current_schema;
 
-    my $dbh = $self->schema->storage->dbh;
+    if (lc($self->db_schema) ne lc($current_schema)) {
+        $dbh->do('ALTER SESSION SET current_schema=' . $self->db_schema);
+    }
+}
+
+sub _table_as_sql {
+    my ($self, $table) = @_;
 
-    my $sth = $dbh->prepare($self->schema->storage->sql_maker->select($table, undef, \'1 = 0'));
-    $sth->execute;
-    return \@{$sth->{NAME_lc}};
+    return $self->_quote_table_name($table);
 }
 
 sub _tables_list { 
-    my $self = shift;
+    my ($self, $opts) = @_;
 
     my $dbh = $self->schema->storage->dbh;
 
@@ -68,7 +62,17 @@ sub _tables_list {
         push @tables, $1
           if $table =~ /\A(\w+)\z/;
     }
-    return @tables;
+
+    return $self->_filter_tables(\@tables, $opts);
+}
+
+sub _table_columns {
+    my ($self, $table) = @_;
+
+    my $dbh = $self->schema->storage->dbh;
+
+    my $sth = $dbh->column_info(undef, $self->db_schema, uc $table, '%');
+    return [ map lc($_->{COLUMN_NAME}), @{ $sth->fetchall_arrayref({ COLUMN_NAME => 1 }) || [] } ];
 }
 
 sub _table_uniq_info {
@@ -80,12 +84,12 @@ sub _table_uniq_info {
         q{
             SELECT constraint_name, acc.column_name
             FROM all_constraints JOIN all_cons_columns acc USING (constraint_name)
-            WHERE acc.table_name=? AND constraint_type='U'
+            WHERE acc.table_name=? and acc.owner = ? AND constraint_type='U'
             ORDER BY acc.position
         },
         {}, 1);
 
-    $sth->execute(uc $table);
+    $sth->execute(uc $table,$self->{db_schema} );
     my %constr_names;
     while(my $constr = $sth->fetchrow_arrayref) {
         my $constr_name = lc $constr->[0];
@@ -122,19 +126,17 @@ sub _columns_info_for {
 }
 
 sub _extra_column_info {
-    my ($self, $info) = @_;
+    my ($self, $table, $column, $info, $dbi_info) = @_;
     my %extra_info;
 
-    my ($table, $column) = @$info{qw/TABLE_NAME COLUMN_NAME/};
-
     my $dbh = $self->schema->storage->dbh;
     my $sth = $dbh->prepare_cached(
         q{
             SELECT COUNT(*)
             FROM all_triggers ut JOIN all_trigger_cols atc USING (trigger_name)
             WHERE atc.table_name = ? AND atc.column_name = ?
-            AND column_usage LIKE '%NEW%' AND column_usage LIKE '%OUT%'
-            AND trigger_type = 'BEFORE EACH ROW' AND triggering_event LIKE '%INSERT%'
+            AND lower(column_usage) LIKE '%new%' AND lower(column_usage) LIKE '%out%'
+            AND trigger_type = 'BEFORE EACH ROW' AND lower(triggering_event) LIKE '%insert%'
         },
         {}, 1);
 
@@ -153,9 +155,12 @@ L<DBIx::Class::Schema::Loader::DBI>
 
 =head1 AUTHOR
 
-TSUNODA Kazuya C<drk@drk7.jp>
+See L<DBIx::Class::Schema::Loader/AUTHOR> and L<DBIx::Class::Schema::Loader/CONTRIBUTORS>.
+
+=head1 LICENSE
 
-Dagfinn Ilmari MannsÃ¥ker C<ilmari@ilmari.org>
+This library is free software; you can redistribute it and/or modify it under
+the same terms as Perl itself.
 
 =cut