From: Rafael Kitover Date: Thu, 20 May 2010 14:56:13 +0000 (-0400) Subject: Oracle sequence detection X-Git-Tag: 0.07000~4 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=5cd600fa91ca3940bafce0ab5f5ff0372ca8388e;p=dbsrgits%2FDBIx-Class-Schema-Loader.git Oracle sequence detection --- diff --git a/Changes b/Changes index 0f959b2..bee1d26 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,7 @@ Revision history for Perl extension DBIx::Class::Schema::Loader + - sequence is detected for Oracle + - fix for SQLite is_auto_increment detection when table is empty (hobbs) - rescan now reloads all tables - minor type info improvements for all DBs - fix erroneous default_value for MySQL NOT NULL columns (RT#57225) diff --git a/lib/DBIx/Class/Schema/Loader/DBI/Oracle.pm b/lib/DBIx/Class/Schema/Loader/DBI/Oracle.pm index a3fb1eb..55e6a4e 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/Oracle.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/Oracle.pm @@ -137,8 +137,11 @@ sub _columns_info_for { my $dbh = $self->schema->storage->dbh; + local $dbh->{LongReadLen} = 100000; + local $dbh->{LongTruncOk} = 1; + my $sth = $dbh->prepare_cached(q{ -SELECT atc.column_name +SELECT atc.column_name, ut.trigger_body FROM all_triggers ut JOIN all_trigger_cols atc USING (trigger_name) WHERE atc.table_name = ? @@ -148,8 +151,16 @@ AND upper(trigger_type) LIKE '%BEFORE EACH ROW%' AND lower(triggering_event) LIK $sth->execute($self->_uc($table)); - while (my ($col_name) = $sth->fetchrow_array) { - $result->{$self->_lc($col_name)}{is_auto_increment} = 1; + while (my ($col_name, $trigger_body) = $sth->fetchrow_array) { + $col_name = $self->_lc($col_name); + + $result->{$col_name}{is_auto_increment} = 1; + + if (my ($seq_name) = $trigger_body =~ /"?(\w+)"?\.nextval/i) { + $seq_name = $self->_lc($seq_name); + + $result->{$col_name}{sequence} = $seq_name; + } } while (my ($col, $info) = each %$result) { diff --git a/t/14ora_common.t b/t/14ora_common.t index 1cab6fa..1232939 100644 --- a/t/14ora_common.t +++ b/t/14ora_common.t @@ -124,6 +124,23 @@ my $tester = dbixcsl_common_tests->new( 'urowid' => { data_type => 'urowid' }, 'urowid(3333)' => { data_type => 'urowid', size => 3333 }, }, + extra => { + count => 1, + run => sub { + my ($schema, $monikers, $classes) = @_; + + SKIP: { + if (my $source = $monikers->{loader_test1s}) { + is $schema->source($source)->column_info('id')->{sequence}, + 'loader_test1s_id_seq', + 'Oracle sequence detection'; + } + else { + skip 1, 'not running common tests'; + } + } + }, + }, ); if( !$dsn || !$user ) {