diff -r -u -N DBIx-Class-0.08007/lib/DBIx/Class/Storage/DBI/Oracle/Generic.pm DBIx-Class-0.08007.patched/lib/DBIx/Class/Storage/DBI/Oracle/Generic.pm --- DBIx-Class-0.08007/lib/DBIx/Class/Storage/DBI/Oracle/Generic.pm 2007-09-04 20:33:11.000000000 +0200 +++ DBIx-Class-0.08007.patched/lib/DBIx/Class/Storage/DBI/Oracle/Generic.pm 2007-09-06 11:42:04.000000000 +0200 @@ -32,8 +32,8 @@ sub _dbh_last_insert_id { my ($self, $dbh, $source, $col) = @_; my $seq = ($source->column_info($col)->{sequence} ||= $self->get_autoinc_seq($source,$col)); - my $sql = 'SELECT ' . $seq . '.currval FROM DUAL'; - my ($id) = $dbh->selectrow_array($sql); + + my $id = $self->_sequence_fetch( 'currval', $seq ); return $id; } @@ -59,6 +59,26 @@ $self->throw_exception("Unable to find a sequence INSERT trigger on table '" . $source->name . "'."); } +sub insert { + my ( $self, $source, $to_insert ) = @_; + foreach my $col ( $source->primary_columns ) { + if ( !defined $to_insert->{$col} ) { + my $col_info = $source->column_info($col); + + if ( $col_info->{is_auto_increment} ) { + $to_insert->{$col} = $self->_sequence_fetch( 'nextval', $col_info->{sequence} || $self->_dbh_get_autoinc_seq($self->dbh, $source) ); + } + } + } + $self->next::method( $source, $to_insert ); +} + +sub _sequence_fetch { + my ( $self, $type, $seq ) = @_; + my ($id) = $self->dbh->selectrow_array("SELECT ${seq}.${type} FROM DUAL"); + return $id; +} + =head2 get_autoinc_seq Returns the sequence name for an autoincrement column diff -r -u -N DBIx-Class-0.08007/t/73oracle.t DBIx-Class-0.08007.patched/t/73oracle.t --- DBIx-Class-0.08007/t/73oracle.t 2007-08-11 23:07:59.000000000 +0200 +++ DBIx-Class-0.08007.patched/t/73oracle.t 2007-09-06 10:40:58.000000000 +0200 @@ -11,7 +11,7 @@ 'Warning: This test drops and creates tables called \'artist\', \'cd\' and \'track\'' unless ($dsn && $user && $pass); -plan tests => 7; +plan tests => 8; my $schema = DBICTest::Schema->connect($dsn, $user, $pass); @@ -19,16 +19,21 @@ eval { $dbh->do("DROP SEQUENCE artist_seq"); + $dbh->do("DROP SEQUENCE artist_oracle_seq"); $dbh->do("DROP TABLE artist"); + $dbh->do("DROP TABLE artist_oracle"); $dbh->do("DROP TABLE cd"); $dbh->do("DROP TABLE track"); }; $dbh->do("CREATE SEQUENCE artist_seq START WITH 1 MAXVALUE 999999 MINVALUE 0"); +$dbh->do("CREATE SEQUENCE artist_oracle_seq START WITH 1 MAXVALUE 999999 MINVALUE 0"); $dbh->do("CREATE TABLE artist (artistid NUMBER(12), name VARCHAR(255))"); +$dbh->do("CREATE TABLE artist_oracle (artistid NUMBER(12), name VARCHAR(255))"); $dbh->do("CREATE TABLE cd (cdid NUMBER(12), artist NUMBER(12), title VARCHAR(255), year VARCHAR(4))"); $dbh->do("CREATE TABLE track (trackid NUMBER(12), cd NUMBER(12), position NUMBER(12), title VARCHAR(255), last_updated_on DATE)"); $dbh->do("ALTER TABLE artist ADD (CONSTRAINT artist_pk PRIMARY KEY (artistid))"); +$dbh->do("ALTER TABLE artist_oracle ADD (CONSTRAINT artist_oracle_pk PRIMARY KEY (artistid))"); $dbh->do(qq{ CREATE OR REPLACE TRIGGER artist_insert_trg BEFORE INSERT ON artist @@ -95,11 +100,17 @@ is( scalar @results, 1, "Group by with limit OK" ); } +# test auto increment using sequences WITHOUT triggers +$new = $schema->resultset('ArtistOracle')->create({ name => 'foo' }); +is($new->artistid, 1, "Oracle Auto-PK without trigger worked"); + # clean up our mess END { if($dbh) { $dbh->do("DROP SEQUENCE artist_seq"); + $dbh->do("DROP SEQUENCE artist_oracle_seq"); $dbh->do("DROP TABLE artist"); + $dbh->do("DROP TABLE artist_oracle"); $dbh->do("DROP TABLE cd"); $dbh->do("DROP TABLE track"); } diff -r -u -N DBIx-Class-0.08007/t/lib/DBICTest/Schema/ArtistOracle.pm DBIx-Class-0.08007.patched/t/lib/DBICTest/Schema/ArtistOracle.pm --- DBIx-Class-0.08007/t/lib/DBICTest/Schema/ArtistOracle.pm 1970-01-01 01:00:00.000000000 +0100 +++ DBIx-Class-0.08007.patched/t/lib/DBICTest/Schema/ArtistOracle.pm 2007-09-06 10:40:42.000000000 +0200 @@ -0,0 +1,26 @@ +package # hide from PAUSE + DBICTest::Schema::ArtistOracle; + +use base 'DBIx::Class::Core'; + +__PACKAGE__->table('artist_oracle'); +__PACKAGE__->source_info({ + "source_info_key_A" => "source_info_value_A", + "source_info_key_B" => "source_info_value_B", + "source_info_key_C" => "source_info_value_C", +}); +__PACKAGE__->add_columns( + 'artistid' => { + data_type => 'integer', + is_auto_increment => 1, + sequence => 'artist_oracle_seq', + }, + 'name' => { + data_type => 'varchar', + size => 100, + is_nullable => 1, + }, +); +__PACKAGE__->set_primary_key('artistid'); + +1; diff -r -u -N DBIx-Class-0.08007/t/lib/DBICTest/Schema.pm DBIx-Class-0.08007.patched/t/lib/DBICTest/Schema.pm --- DBIx-Class-0.08007/t/lib/DBICTest/Schema.pm 2007-08-11 23:07:59.000000000 +0200 +++ DBIx-Class-0.08007.patched/t/lib/DBICTest/Schema.pm 2007-09-06 10:40:05.000000000 +0200 @@ -7,6 +7,7 @@ __PACKAGE__->load_classes(qw/ Artist + ArtistOracle Employee CD FileColumn