From: Rafael Kitover Date: Mon, 22 Nov 2010 08:41:56 +0000 (-0500) Subject: Fix multiple storage regressions from 52416317 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=e366f8071f0797f739114539858e59bd3aea3baa;p=dbsrgits%2FDBIx-Class-Historic.git Fix multiple storage regressions from 52416317 Factor out the pre-insert value fetching again, some storages need to hook there. The rest is just riba being retarded, Caelum++ --- diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index 8595c16..4d18d8d 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -1571,14 +1571,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,7 +1587,7 @@ sub insert { ref $to_insert->{$col} eq 'SCALAR' ) ) { - $auto_nextvals->{$col} = $self->_sequence_fetch( + $values{$col} = $self->_sequence_fetch( 'nextval', ( $colinfo->{$col}{sequence} ||= $self->_dbh_get_autoinc_seq($self->_get_dbh, $source, $col) @@ -1598,8 +1596,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 +1630,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 +1643,7 @@ sub insert { @returned_cols{@$retlist} = @ret_vals if @ret_vals; } - return \%returned_cols; + return { %$prefetched_values, %returned_cols }; } diff --git a/lib/DBIx/Class/Storage/DBI/Replicated.pm b/lib/DBIx/Class/Storage/DBI/Replicated.pm index 6dad218..9fa00f2 100644 --- a/lib/DBIx/Class/Storage/DBI/Replicated.pm +++ b/lib/DBIx/Class/Storage/DBI/Replicated.pm @@ -378,6 +378,7 @@ my @unimplemented = qw( _inner_join_to_node _group_over_selection + _prefetch_autovalues ); # the capability framework diff --git a/lib/DBIx/Class/Storage/DBI/SQLAnywhere.pm b/lib/DBIx/Class/Storage/DBI/SQLAnywhere.pm index df301d2..728220f 100644 --- a/lib/DBIx/Class/Storage/DBI/SQLAnywhere.pm +++ b/lib/DBIx/Class/Storage/DBI/SQLAnywhere.pm @@ -37,14 +37,16 @@ sub last_insert_id { shift->_identity } sub _new_uuid { 'UUIDTOSTR(NEWID())' } -sub insert { +sub _prefetch_autovalues { my $self = shift; my ($source, $to_insert) = @_; + my $values = $self->next::method(@_); + my $colinfo = $source->columns_info; my $identity_col = - first { $_->{is_auto_increment} } values %$colinfo; + first { $colinfo->{$_}{is_auto_increment} } keys %$colinfo; # user might have an identity PK without is_auto_increment if (not $identity_col) { @@ -72,12 +74,12 @@ sub insert { }; if (defined $identity) { - $to_insert->{$identity_col} = $identity; + $values->{$identity_col} = $identity; $self->_identity($identity); } } - return $self->next::method(@_); + return $values; } # convert UUIDs to strings in selects diff --git a/lib/DBIx/Class/Storage/DBI/Sybase/ASE.pm b/lib/DBIx/Class/Storage/DBI/Sybase/ASE.pm index dbbee6f..d2f5e2f 100644 --- a/lib/DBIx/Class/Storage/DBI/Sybase/ASE.pm +++ b/lib/DBIx/Class/Storage/DBI/Sybase/ASE.pm @@ -260,9 +260,13 @@ sub _prep_for_execute { first { $bind_info->{$_}{is_auto_increment} } keys %$bind_info ; + + my $columns_info = blessed $ident && $ident->columns_info; + my $identity_col = - blessed $ident && - first { $_->{is_auto_increment} } values %{ $ident->columns_info } + $columns_info && + first { $columns_info->{$_}{is_auto_increment} } + keys %$columns_info ; if (($op eq 'insert' && $bound_identity_col) || @@ -350,8 +354,11 @@ sub insert { my $self = shift; my ($source, $to_insert) = @_; + my $columns_info = $source->columns_info; + my $identity_col = - (first { $_->{is_auto_increment} } values %{ $source->columns_info } ) + (first { $columns_info->{$_}{is_auto_increment} } + keys %$columns_info ) || ''; # check for empty insert @@ -435,8 +442,11 @@ sub update { my $table = $source->name; + my $columns_info = $source->columns_info; + my $identity_col = - first { $_->{is_auto_increment} } values %{ $source->columns_info }; + first { $columns_info->{$_}{is_auto_increment} } + keys %$columns_info; my $is_identity_update = $identity_col && defined $fields->{$identity_col}; @@ -485,8 +495,11 @@ sub insert_bulk { my $self = shift; my ($source, $cols, $data) = @_; + my $columns_info = $source->columns_info; + my $identity_col = - first { $_->{is_auto_increment} } values %{ $source->columns_info }; + first { $columns_info->{$_}{is_auto_increment} } + keys %$columns_info; my $is_identity_insert = (first { $_ eq $identity_col } @{$cols}) ? 1 : 0;