From: Rafael Kitover Date: Sun, 13 Jun 2010 15:48:44 +0000 (-0400) Subject: improve Oracle sequence detection and related test output X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=720448921cee676e52ed7e7b37c17352ea9b8470;p=dbsrgits%2FDBIx-Class-Historic.git improve Oracle sequence detection and related test output --- diff --git a/Changes b/Changes index 0f6aa20..5d0177a 100644 --- a/Changes +++ b/Changes @@ -2,6 +2,8 @@ Revision history for DBIx::Class * Fixes - Fixed rels ending with me breaking subqueried limit realiasing + - Oracle sequence detection now *really* works across schemas + (fixed some ommissions from 0.08123) 0.08123 2010-06-12 14:46 (UTC) * Fixes diff --git a/lib/DBIx/Class/Storage/DBI/Oracle/Generic.pm b/lib/DBIx/Class/Storage/DBI/Oracle/Generic.pm index 05e2c8b..4d8b781 100644 --- a/lib/DBIx/Class/Storage/DBI/Oracle/Generic.pm +++ b/lib/DBIx/Class/Storage/DBI/Oracle/Generic.pm @@ -146,12 +146,12 @@ sub _dbh_get_autoinc_seq { $sth->execute (@bind); while (my ($insert_trigger, $schema) = $sth->fetchrow_array) { - my ($seq_name) = $insert_trigger =~ m!("?[.\w"]+?"?)\.nextval!i; + my ($seq_name) = $insert_trigger =~ m!("?[.\w"]+"?)\.nextval!i; next unless $seq_name; if ($seq_name !~ /\./) { - $seq_name = join '.' => map $self->sql_maker->_quote($_), $schema, $seq_name; + $seq_name = join '.' => $schema, $seq_name; } return $seq_name; diff --git a/t/73oracle.t b/t/73oracle.t index 911fad5..daade01 100644 --- a/t/73oracle.t +++ b/t/73oracle.t @@ -670,15 +670,43 @@ SKIP: { $schema1_dbh->do("GRANT INSERT ON artist TO $user2"); $schema1_dbh->do("GRANT SELECT ON artist_seq TO $user2"); - my $rs = $schema2->resultset('Artist'); + my $rs = $schema2->resultset('ArtistFQN'); - # qualify table with schema - local $rs->result_source->{name} = "${user}.artist"; + # first test with unquoted (default) sequence name in trigger body lives_and { my $row = $rs->create({ name => 'From Different Schema' }); ok $row->artistid; } 'used autoinc sequence across schemas'; + + # now quote the sequence name + + $schema1_dbh->do(qq{ + CREATE OR REPLACE TRIGGER artist_insert_trg + BEFORE INSERT ON artist + FOR EACH ROW + BEGIN + IF :new.artistid IS NULL THEN + SELECT "ARTIST_SEQ".nextval + INTO :new.artistid + FROM DUAL; + END IF; + END; + }); + + # sequence is cached in the rsrc + delete $rs->result_source->column_info('artistid')->{sequence}; + + lives_and { + my $row = $rs->create({ name => 'From Different Schema With Quoted Sequence' }); + ok $row->artistid; + } 'used quoted autoinc sequence across schemas'; + + my $schema_name = uc $user; + + is $rs->result_source->column_info('artistid')->{sequence}, + qq[${schema_name}."ARTIST_SEQ"], + 'quoted sequence name correctly extracted'; } done_testing;