X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FStorage%2FDBI.pm;h=6b6f7dd55218ee9e7282d429af04c57ce146fe5a;hb=07cda1c5a7df6656772dfd65c488c19c15126168;hp=8595c16c8961111055c6ab7d82975db3604e8aa3;hpb=ec6415a9f63389db5a76f593c2d1686015ca95cd;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index 8595c16..6b6f7dd 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -206,6 +206,12 @@ sub DESTROY { # some databases spew warnings on implicit disconnect local $SIG{__WARN__} = sub {}; $self->_dbh(undef); + + # this op is necessary, since the very last perl runtime statement + # triggers a global destruction shootout, and the $SIG localization + # may very well be destroyed before perl actually gets to do the + # $dbh undef + 1; } # handle pid changes correctly - do not destroy parent's connection @@ -1571,14 +1577,12 @@ sub _execute { $self->dbh_do('_dbh_execute', @_); # retry over disconnects } -sub insert { +sub _prefetch_autovalues { my ($self, $source, $to_insert) = @_; my $colinfo = $source->columns_info; - # mix with auto-nextval marked values (a bit of a speed hit, but - # no saner way to handle this yet) - my $auto_nextvals = {} ; + my %values; for my $col (keys %$colinfo) { if ( $colinfo->{$col}{auto_nextval} @@ -1589,8 +1593,8 @@ sub insert { ref $to_insert->{$col} eq 'SCALAR' ) ) { - $auto_nextvals->{$col} = $self->_sequence_fetch( - 'nextval', + $values{$col} = $self->_sequence_fetch( + 'NEXTVAL', ( $colinfo->{$col}{sequence} ||= $self->_dbh_get_autoinc_seq($self->_get_dbh, $source, $col) ), @@ -1598,8 +1602,16 @@ sub insert { } } + \%values; +} + +sub insert { + my ($self, $source, $to_insert) = @_; + + my $prefetched_values = $self->_prefetch_autovalues($source, $to_insert); + # fuse the values - $to_insert = { %$to_insert, %$auto_nextvals }; + $to_insert = { %$to_insert, %$prefetched_values }; # list of primary keys we try to fetch from the database # both not-exsists and scalarrefs are considered @@ -1624,7 +1636,7 @@ sub insert { my ($rv, $sth) = $self->_execute('insert' => [], $source, $bind_attributes, $to_insert, $sqla_opts); - my %returned_cols = %$auto_nextvals; + my %returned_cols; if (my $retlist = $sqla_opts->{returning}) { my @ret_vals = try { @@ -1637,7 +1649,7 @@ sub insert { @returned_cols{@$retlist} = @ret_vals if @ret_vals; } - return \%returned_cols; + return { %$prefetched_values, %returned_cols }; }