From: Daniel Ruoso Date: Mon, 13 Dec 2010 13:13:36 +0000 (-0300) Subject: use $self->{from_bind} for extra binds transport X-Git-Tag: v0.08190~1^2~5 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a697fa319ce0072206b76f64fed38d92d5f59644;p=dbsrgits%2FDBIx-Class.git use $self->{from_bind} for extra binds transport The __overriden_select method was used to build extra binds that should be transported in the $self->{from_bind} array instead. --- diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index e2059e5..a12095f 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -2343,10 +2343,14 @@ sub _merge_with_rscond { while ( my($col, $value) = each %implied ) { my $vref = ref $value; - if ($vref eq 'HASH') { - if (keys(%$value) && (keys %$value)[0] eq '=') { - $new_data{$col} = $value->{'='}; - } + if ( + $vref eq 'HASH' + and + keys(%$value) == 1 + and + (keys %$value)[0] eq '=' + ) { + $new_data{$col} = $value->{'='}; } elsif( !$vref or $vref eq 'SCALAR' or blessed($value) ) { $new_data{$col} = $value; diff --git a/lib/DBIx/Class/ResultSource.pm b/lib/DBIx/Class/ResultSource.pm index 834555a..71653e0 100644 --- a/lib/DBIx/Class/ResultSource.pm +++ b/lib/DBIx/Class/ResultSource.pm @@ -1601,7 +1601,7 @@ sub _resolve_condition { } elsif (!defined $as) { # undef, i.e. "no reverse object" $ret{$v} = undef; } else { - $ret{"${as}.${k}"} = "${for}.${v}"; + $ret{"${as}.${k}"} = { -ident => "${for}.${v}" }; } } return \%ret; diff --git a/lib/DBIx/Class/SQLMaker.pm b/lib/DBIx/Class/SQLMaker.pm index 3cd017d..570af4d 100644 --- a/lib/DBIx/Class/SQLMaker.pm +++ b/lib/DBIx/Class/SQLMaker.pm @@ -1,5 +1,8 @@ package DBIx::Class::SQLMaker; +use strict; +use warnings; + =head1 NAME DBIx::Class::SQLMaker - An SQL::Abstract-based SQL maker class @@ -38,8 +41,7 @@ use base qw/ Class::Accessor::Grouped /; use mro 'c3'; -use strict; -use warnings; + use Sub::Name 'subname'; use Carp::Clan qw/^DBIx::Class|^SQL::Abstract|^Try::Tiny/; use namespace::clean; @@ -183,7 +185,7 @@ sub select { if ($limit) { # this is legacy code-flow from SQLA::Limit, it is not set in stone - ($sql, @bind) = $self->__overriden_select($table, $fields, $where); + ($sql, @bind) = $self->next::method ($table, $fields, $where); my $limiter = $self->can ('emulate_limit') # also backcompat hook from SQLA::Limit @@ -199,7 +201,7 @@ sub select { $sql = $self->$limiter ($sql, $rs_attrs, $limit, $offset); } else { - ($sql, @bind) = $self->__overriden_select($table, $fields, $where, $rs_attrs); + ($sql, @bind) = $self->next::method ($table, $fields, $where, $rs_attrs); } push @{$self->{where_bind}}, @bind; @@ -213,25 +215,6 @@ sub select { return wantarray ? ($sql, @all_bind) : $sql; } -sub __overriden_select { - my $self = shift; - my ($table, @bind) = $self->_table(shift); - my $fields = shift || '*'; - my $where = shift; - my $order = shift; - - my($where_sql, @morebind) = $self->where($where, $order); - push @bind, @morebind; - - my $f = (ref $fields eq 'ARRAY') ? join ', ', map { $self->_quote($_) } @$fields - : $fields; - my $sql = join(' ', $self->_sqlcase('select'), $f, - $self->_sqlcase('from'), $table) - . $where_sql; - - return wantarray ? ($sql, @bind) : $sql; -} - sub _assemble_binds { my $self = shift; return map { @{ (delete $self->{"${_}_bind"}) || [] } } (qw/select from where group having order/); @@ -397,7 +380,7 @@ sub _generate_join_clause { sub _recurse_from { my ($self, $from, @join) = @_; - my (@sqlf, @binds); + my @sqlf; push @sqlf, $self->_from_chunk_to_sql($from); for (@join) { @@ -416,17 +399,17 @@ sub _recurse_from { push @sqlf, $self->_generate_join_clause( $join_type ); if (ref $to eq 'ARRAY') { - my ($sql, @local_bind) = $self->_recurse_from(@$to); - push(@sqlf, '(', $sql , ')'); - push @binds, @local_bind; + push(@sqlf, '(', $self->_recurse_from(@$to), ')'); } else { push(@sqlf, $self->_from_chunk_to_sql($to)); } - my ($sql, @local_bind) = $self->_join_condition($on); + + my ($sql, @bind) = $self->_join_condition($on); push(@sqlf, ' ON ', $sql); - push @binds, @local_bind; + push @{$self->{from_bind}}, @bind; } - return join('', @sqlf), @binds; + + return join('', @sqlf); } sub _from_chunk_to_sql { @@ -460,21 +443,23 @@ sub _from_chunk_to_sql { sub _join_condition { my ($self, $cond) = @_; - if (ref $cond eq 'HASH') { - my %j; - for (keys %$cond) { - my $v = $cond->{$_}; - if (ref $v) { - #croak (ref($v) . qq{ reference arguments are not supported in JOINS - try using \"..." instead'}) - # if ref($v) ne 'SCALAR'; - $j{$_} = $v; - } - else { - my $x = '= '.$self->_quote($v); $j{$_} = \$x; - } - }; - return $self->_recurse_where(\%j); - } elsif (ref $cond eq 'ARRAY') { + # Backcompat for the old days when a plain hashref + # { 't1.col1' => 't2.col2' } meant ON t1.col1 = t2.col2 + # Once things settle we should start warning here so that + # folks unroll their hacks + if ( + ref $cond eq 'HASH' + and + keys %$cond == 1 + and + (keys %$cond)[0] =~ /\./ + and + ! ref ( (values %$cond)[0] ) + ) { + $cond = { keys %$cond => { -ident => values %$cond } } + } + elsif ( ref $cond eq 'ARRAY' ) { + # do our own ORing so that the hashref-shim above is invoked my @parts; my @binds; foreach my $c (@$cond) { @@ -483,9 +468,9 @@ sub _join_condition { push @parts, $sql; } return join(' OR ', @parts), @binds; - } else { - croak "Can't handle this yet!"; } + + return $self->_recurse_where($cond); } 1;