From: Robert Bohne Date: Thu, 14 Oct 2010 07:29:57 +0000 (+0200) Subject: Added _table_comment and _column_comment to DBI::Oracle X-Git-Tag: 0.07003~40 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4cd5155bb0df2e2e59378d9e878af90285967e12;p=dbsrgits%2FDBIx-Class-Schema-Loader.git Added _table_comment and _column_comment to DBI::Oracle --- diff --git a/Changes b/Changes index 1be260c..ba5f445 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,6 @@ Revision history for Perl extension DBIx::Class::Schema::Loader + - Added table/column comment support for Oracle - Fix missing require (RT#62072) 0.07002 2010-09-11 01:48:00 diff --git a/lib/DBIx/Class/Schema/Loader/Base.pm b/lib/DBIx/Class/Schema/Loader/Base.pm index b261921..baf36b1 100644 --- a/lib/DBIx/Class/Schema/Loader/Base.pm +++ b/lib/DBIx/Class/Schema/Loader/Base.pm @@ -1798,7 +1798,7 @@ sub _make_pod { " $_: $s" } sort keys %$attrs, ); - if (my $comment = $self->__column_comment($self->{_class2table}{$class}, $col_counter)) { + if (my $comment = $self->__column_comment($self->{_class2table}{$class}, $col_counter, $name)) { $self->_pod( $class, $comment ); } } diff --git a/lib/DBIx/Class/Schema/Loader/DBI/Oracle.pm b/lib/DBIx/Class/Schema/Loader/DBI/Oracle.pm index 84f801f..a2cb3ad 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/Oracle.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/Oracle.pm @@ -121,6 +121,33 @@ sub _table_uniq_info { return \@uniqs; } +sub _table_comment { + my ( $self, $table ) = @_; + my ($table_comment) = $self->schema->storage->dbh->selectrow_array( + q{ + SELECT comments FROM all_tab_comments + WHERE owner = ? + AND table_name = ? + AND table_type = 'TABLE' + }, undef, $self->db_schema, $self->_uc($table) + ); + + return $table_comment +} + +sub _column_comment { + my ( $self, $table, $column_number, $column_name ) = @_; + my ($column_comment) = $self->schema->storage->dbh->selectrow_array( + q{ + SELECT comments FROM all_col_comments + WHERE owner = ? + AND table_name = ? + AND column_name = ? + }, undef, $self->db_schema, $self->_uc( $table ), $self->_uc( $column_name ) + ); + return $column_comment +} + sub _table_pk_info { my ($self, $table) = (shift, shift); diff --git a/t/14ora_common.t b/t/14ora_common.t index c8ee80c..2cbe77f 100644 --- a/t/14ora_common.t +++ b/t/14ora_common.t @@ -3,6 +3,7 @@ use lib qw(t/lib); use dbixcsl_common_tests; use Test::More; use Test::Exception; +use File::Slurp (); my $dsn = $ENV{DBICTEST_ORA_DSN} || ''; my $user = $ENV{DBICTEST_ORA_USER} || ''; @@ -125,7 +126,18 @@ my $tester = dbixcsl_common_tests->new( 'urowid(3333)' => { data_type => 'urowid', size => 3333 }, }, extra => { - count => 1, + create => [ + q{ + CREATE TABLE oracle_loader_test1 ( + id NUMBER(11), + value VARCHAR2(100) + ) + }, + q{ COMMENT ON TABLE oracle_loader_test1 IS 'oracle_loader_test1 table comment' }, + q{ COMMENT ON COLUMN oracle_loader_test1.value IS 'oracle_loader_test1.value column comment' }, + ], + drop => [qw/oracle_loader_test1/], + count => 3, run => sub { my ($schema, $monikers, $classes) = @_; @@ -139,6 +151,18 @@ my $tester = dbixcsl_common_tests->new( skip 'not running common tests', 1; } } + + SKIP: { + skip 'not running comment tests', 1 unless (my $class = $classes->{oracle_loader_test1}); + my $filename = $schema->_loader->_get_dump_filename($class); + my $code = File::Slurp::slurp $filename; + + like $code, qr/^=head1 NAME\n\n^$class - oracle_loader_test1 table comment\n\n^=cut\n/m, + 'table comment'; + + like $code, qr/^=head2 value\n\n(.+:.+\n)+\noracle_loader_test1\.value column comment\n\n/m, + 'column comment and attrs'; + } }, }, );