X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FStorage%2FDBI%2FOracle%2FGeneric.pm;h=336070a0d456458c1f2eee9c66504a2d23b61c30;hb=b83736a7d3235d2f50fe5695550eb3637432d960;hp=568b56172da9c9f91da4ba46d97b52a900f4e397;hpb=9930caaf7e7c250d914cb1440d9a0f1dd2a1dedc;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/Storage/DBI/Oracle/Generic.pm b/lib/DBIx/Class/Storage/DBI/Oracle/Generic.pm index 568b561..336070a 100644 --- a/lib/DBIx/Class/Storage/DBI/Oracle/Generic.pm +++ b/lib/DBIx/Class/Storage/DBI/Oracle/Generic.pm @@ -7,8 +7,7 @@ use mro 'c3'; use DBIx::Class::Carp; use Scope::Guard (); use Context::Preserve 'preserve_context'; -use Try::Tiny; -use List::Util 'first'; +use DBIx::Class::_Util qw( modver_gt_or_eq modver_gt_or_eq_and_lt dbic_internal_try ); use namespace::clean; __PACKAGE__->sql_limit_dialect ('RowNum'); @@ -103,9 +102,6 @@ sub deployment_statements { my ($schema, $type, $version, $dir, $sqltargs, @rest) = @_; $sqltargs ||= {}; - my $quote_char = $self->schema->storage->sql_maker->quote_char; - $sqltargs->{quote_table_names} = $quote_char ? 1 : 0; - $sqltargs->{quote_field_names} = $quote_char ? 1 : 0; if ( ! exists $sqltargs->{producer_args}{oracle_version} @@ -121,8 +117,9 @@ sub deployment_statements { sub _dbh_last_insert_id { my ($self, $dbh, $source, @columns) = @_; my @ids = (); + my $ci = $source->columns_info(\@columns); foreach my $col (@columns) { - my $seq = ($source->column_info($col)->{sequence} ||= $self->get_autoinc_seq($source,$col)); + my $seq = ( $ci->{$col}{sequence} ||= $self->get_autoinc_seq($source,$col)); my $id = $self->_sequence_fetch( 'CURRVAL', $seq ); push @ids, $id; } @@ -275,20 +272,21 @@ sub _ping { local $dbh->{RaiseError} = 1; local $dbh->{PrintError} = 0; - return try { + ( dbic_internal_try { $dbh->do('select 1 from dual'); 1; - } catch { - 0; - }; + }) + ? 1 + : 0 + ; } sub _dbh_execute { #my ($self, $dbh, $sql, $bind, $bind_attrs) = @_; - my ($self, $bind) = @_[0,3]; + my ($self, $sql, $bind) = @_[0,2,3]; # Turn off sth caching for multi-part LOBs. See _prep_for_execute below - local $self->{disable_sth_caching} = 1 if first { + local $self->{disable_sth_caching} = 1 if grep { ($_->[0]{_ora_lob_autosplit_part}||0) > (__cache_queries_with_max_lob_parts - 1) @@ -300,33 +298,41 @@ sub _dbh_execute { return shift->$next(@_) if $self->transaction_depth; - # cheat the blockrunner - we do want to rerun things regardless of outer state - local $self->{_in_do_block}; + # Cheat the blockrunner we are just about to create: + # We *do* want to rerun things regardless of outer state + local $self->{_in_do_block} + if $self->{_in_do_block}; - return DBIx::Class::Storage::BlockRunner->new( + DBIx::Class::Storage::BlockRunner->new( storage => $self, - run_code => $next, - run_args => \@_, wrap_txn => 0, retry_handler => sub { # ORA-01003: no statement parsed (someone changed the table somehow, # invalidating your cursor.) - return 0 if ($_[0]->retried_count or $_[0]->last_exception !~ /ORA-01003/); - - # re-prepare towards new table data - if (my $dbh = $_[0]->storage->_dbh) { - delete $dbh->{CachedKids}{$_[0]->run_args->[2]}; + if ( + $_[0]->failed_attempt_count == 1 + and + $_[0]->last_exception =~ /ORA-01003/ + and + my $dbh = $_[0]->storage->_dbh + ) { + delete $dbh->{CachedKids}{$sql}; + return 1; + } + else { + return 0; } - return 1; }, - )->run; + )->run( $next, @_ ); } sub _dbh_execute_for_fetch { - #my ($self, $sth, $tuple_status, @extra) = @_; + #my ($self, $source, $sth, $proto_bind, $cols, $data) = @_; - # DBD::Oracle warns loudly on partial execute_for_fetch failures - local $_[1]->{PrintWarn} = 0; + # Older DBD::Oracle warns loudly on partial execute_for_fetch failures + # before https://metacpan.org/source/PYTHIAN/DBD-Oracle-1.28/Changes#L7-9 + local $_[2]->{PrintWarn} = 0 + unless modver_gt_or_eq( 'DBD::Oracle', '1.28' ); shift->next::method(@_); } @@ -417,11 +423,18 @@ sub _dbi_attrs_for_bind { my $attrs = $self->next::method($ident, $bind); - for my $i (0 .. $#$attrs) { - if (keys %{$attrs->[$i]||{}} and my $col = $bind->[$i][0]{dbic_colname}) { - $attrs->[$i]{ora_field} = $col; - } - } + # Push the column name into all bind attrs, make sure to *NOT* write into + # the existing $attrs->[$idx]{..} hashref, as it is cached by the call to + # next::method above. + # FIXME - this code will go away when the LobWriter refactor lands + $attrs->[$_] + and + keys %{ $attrs->[$_] } + and + $bind->[$_][0]{dbic_colname} + and + $attrs->[$_] = { %{$attrs->[$_]}, ora_field => $bind->[$_][0]{dbic_colname} } + for 0 .. $#$attrs; $attrs; } @@ -431,20 +444,11 @@ sub bind_attribute_by_data_type { if ($self->_is_lob_type($dt)) { - # this is a hot-ish codepath, store an escape-flag in the DBD namespace, so that - # things like Class::Unload work (unlikely but possible) - unless ($DBD::Oracle::__DBIC_DBD_VERSION_CHECK_OK__) { - - # no earlier - no later - if ($DBD::Oracle::VERSION eq '1.23') { - $self->throw_exception( - "BLOB/CLOB support in DBD::Oracle == 1.23 is broken, use an earlier or later ". - "version (https://rt.cpan.org/Public/Bug/Display.html?id=46016)" - ); - } - - $DBD::Oracle::__DBIC_DBD_VERSION_CHECK_OK__ = 1; - } + # no earlier - no later + $self->throw_exception( + "BLOB/CLOB support in DBD::Oracle == 1.23 is broken, use an earlier or later " + . "version (https://rt.cpan.org/Public/Bug/Display.html?id=46016)" + ) if modver_gt_or_eq_and_lt( 'DBD::Oracle', '1.23', '1.24' ); return { ora_type => $self->_is_text_lob_type($dt) @@ -633,7 +637,7 @@ Unfortunately, Oracle doesn't support identifiers over 30 chars in length, so the L name is shortened and appended with half of an MD5 hash. -See L. +See L. =cut @@ -644,7 +648,7 @@ sub relname_to_table_alias { my $alias = $self->next::method(@_); # we need to shorten here in addition to the shortening in SQLA itself, - # since the final relnames are a crucial for the join optimizer + # since the final relnames are crucial for the join optimizer return $self->sql_maker->_shorten_identifier($alias); } @@ -761,13 +765,16 @@ It uses the same syntax as L # ORDER SIBLINGS BY # firstname ASC -=head1 AUTHOR +=head1 FURTHER QUESTIONS? -See L and L. +Check the list of L. -=head1 LICENSE +=head1 COPYRIGHT AND LICENSE -You may distribute this code under the same terms as Perl itself. +This module is free software L +by the L. You can +redistribute it and/or modify it under the same terms as the +L. =cut