@{$on->{-and}} == 1
);
- # sadly SQLA treats where($scalar) as literal, so we need to jump some hoops
- push @where, map { \sprintf ('%s%s = %s%s',
- ref $_ ? $self->_recurse_where($_) : $self->_quote($_),
- $left_join,
- ref $on->{$_} ? $self->_recurse_where($on->{$_}) : $self->_quote($on->{$_}),
- $right_join,
- )} keys %$on;
+
+ push @where, map { \do {
+ my ($sql) = $self->_recurse_where({
+ # FIXME - more borkage, more or less a copy of the kludge in ::SQLMaker::_join_condition()
+ $_ => ( length ref $on->{$_}
+ ? $on->{$_}
+ : { -ident => $on->{$_} }
+ )
+ });
+
+ $sql =~ s/\s*\=/$left_join =/
+ if $left_join;
+
+ "$sql$right_join";
+ }
+ } sort keys %$on;
}
return { -and => \@where };
if (ref $rhs eq 'HASH' and ! keys %$rhs) {
# FIXME - SQLA seems to be doing... nothing...?
}
+ # normalize top level -ident, for saner extract_fixed_condition_columns code
elsif (ref $rhs eq 'HASH' and keys %$rhs == 1 and exists $rhs->{-ident}) {
push @conds, { $lhs => { '=', $rhs } };
}
push @conds, { $lhs => $rhs->{-value} };
}
elsif (ref $rhs eq 'HASH' and keys %$rhs == 1 and exists $rhs->{'='}) {
- if( is_literal_value $rhs->{'='}) {
+ if ( length ref $rhs->{'='} and is_literal_value $rhs->{'='} ) {
push @conds, { $lhs => $rhs };
}
else {
my ($l, $r) = %$p;
- push @conds, ( ! length ref $r or is_plain_value($r) )
+ push @conds, (
+ ! length ref $r
+ or
+ # the unroller recursion may return a '=' prepended value already
+ ref $r eq 'HASH' and keys %$rhs == 1 and exists $rhs->{'='}
+ or
+ is_plain_value($r)
+ )
? { $l => $r }
: { $l => { '=' => $r } }
;
}
}
# do not need to check for plain values - _collapse_cond did it for us
- elsif(length ref $v->{'='} and is_literal_value($v->{'='}) ) {
+ elsif(
+ length ref $v->{'='}
+ and
+ (
+ ( ref $v->{'='} eq 'HASH' and keys %{$v->{'='}} == 1 and exists $v->{'='}{-ident} )
+ or
+ is_literal_value($v->{'='})
+ )
+ ) {
$vals->{ 'SER_' . serialize $v->{'='} } = $v->{'='};
}
}
my $sa = DBIx::Class::SQLMaker::OracleJoins->new;
+for my $rhs ( "me.artist", { -ident => "me.artist" } ) {
+
# my ($self, $table, $fields, $where, $order, @rest) = @_;
my ($sql, @bind) = $sa->select(
[
{ me => "cd" },
[
{ "-join_type" => "LEFT", artist => "artist" },
- { "artist.artistid" => "me.artist" },
+ { "artist.artistid" => $rhs },
],
],
[ 'cd.cdid', 'cd.artist', 'cd.title', 'cd.year', 'artist.artistid', 'artist.name' ],
{ me => "cd" },
[
{ "-join_type" => "", artist => "artist" },
- { "artist.artistid" => "me.artist" },
+ { "artist.artistid" => $rhs },
],
],
[ 'cd.cdid', 'cd.artist', 'cd.title', 'cd.year', 'artist.artistid', 'artist.name' ],
[
{ me => "cd" },
[
+ { "-join_type" => "right", artist => "artist" },
+ { "artist.artistid" => $rhs },
+ ],
+ ],
+ [ 'cd.cdid', 'cd.artist', 'cd.title', 'cd.year', 'artist.artistid', 'artist.name' ],
+ { 'artist.artistid' => 3 },
+ undef
+);
+is_same_sql_bind(
+ $sql, \@bind,
+ 'SELECT cd.cdid, cd.artist, cd.title, cd.year, artist.artistid, artist.name FROM cd me, artist artist WHERE ( ( ( artist.artistid = me.artist(+) ) AND ( artist.artistid = ? ) ) )', [3],
+ 'WhereJoins search with where clause'
+);
+
+($sql, @bind) = $sa->select(
+ [
+ { me => "cd" },
+ [
{ "-join_type" => "LEFT", artist => "artist" },
- { "artist.artistid" => "me.artist" },
+ { "artist.artistid" => $rhs },
],
],
[ 'cd.cdid', 'cd.artist', 'cd.title', 'cd.year', 'artist.artistid', 'artist.name' ],
'WhereJoins search with or in where clause'
);
+}
+
done_testing;