From: Matt S Trout Date: Fri, 19 Apr 2019 21:42:30 +0000 (+0000) Subject: handle convert where using expander wrapping X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=67e082b8fc8fad7ebeaf57b75eca4f5ef3d46360;p=scpubgit%2FQ-Branch.git handle convert where using expander wrapping --- diff --git a/lib/SQL/Abstract.pm b/lib/SQL/Abstract.pm index aca0188..efa1e8a 100644 --- a/lib/SQL/Abstract.pm +++ b/lib/SQL/Abstract.pm @@ -402,7 +402,7 @@ sub _expand_update_set_values { map { my ($k, $set) = @$_; $set = { -bind => $_ } unless defined $set; - +{ -op => [ '=', $self->_expand_ident(-ident => $k), $set ] }; + +{ -op => [ '=', { -ident => $k }, $set ] }; } map { my $k = $_; @@ -755,7 +755,7 @@ sub _expand_hashpair_cmp { sub _expand_hashtriple { my ($self, $k, $vk, $vv) = @_; - my $ik = $self->_expand_ident(-ident => $k); + my $ik = $self->_expand_expr({ -ident => $k }); my $op = $self->_normalize_op($vk); $self->_assert_pass_injection_guard($op); @@ -851,7 +851,7 @@ sub _dwim_op_to_is { sub _expand_func { my ($self, undef, $args) = @_; my ($func, @args) = @$args; - return { -func => [ $func, map $self->expand_expr($_), @args ] }; + return +{ -func => [ $func, map $self->expand_expr($_), @args ] }; } sub _expand_ident { @@ -902,7 +902,7 @@ sub _expand_bool { return $self->_expand_expr($v); } puke "-bool => undef not supported" unless defined($v); - return $self->_expand_ident(-ident => $v); + return $self->_expand_expr({ -ident => $v }); } sub _expand_op_andor { diff --git a/lib/SQL/Abstract/Clauses.pm b/lib/SQL/Abstract/Clauses.pm index 25462b4..b859342 100644 --- a/lib/SQL/Abstract/Clauses.pm +++ b/lib/SQL/Abstract/Clauses.pm @@ -63,11 +63,6 @@ sub register_defaults { $self->{expand}{exists} = sub { $_[0]->_expand_op(undef, [ exists => $_[2] ]); }; - $self->{render}{convert_where} = sub { - my $self = shift; - local $self->{convert_where} = $self->{convert}; - $self->render_aqt($_[1]); - }; return $self; } @@ -83,8 +78,41 @@ sub _expand_select_clause_from { sub _expand_select_clause_where { my ($self, undef, $where) = @_; + + local (@{$self->{expand}}{qw(ident value)}, + @{$self->{expand_op}}{qw(ident value)}, + $self->{expand_op}{bind}) + = (map { + my $orig = $self->{expand}{$_}; + sub { + my $self = shift; + +{ -func => [ + $self->{convert}, + $self->$orig(@_) + ] }; + } + } qw(ident value ident value bind) + ) if $self->{convert}; + + local $self->{expand}{func} = do { + my $orig = $self->{expand}{func}; + sub { + my ($self, $type, $thing) = @_; + if (ref($thing) eq 'ARRAY' and $thing->[0] eq $self->{convert} + and @$thing == 2 and ref($thing->[1]) eq 'HASH' + and ( + $thing->[1]{-ident} + or $thing->[1]{-value} + or $thing->[1]{-bind}) + ) { + return { -func => $thing }; # already went through our expander + } + return $self->$orig($type, $thing); + } + } if $self->{convert}; + my $exp = $self->expand_expr($where); - +(where => ($self->{convert} ? +{ -convert_where => $exp } : $exp)); + +(where => $exp); } sub _expand_select_clause_order_by { @@ -269,7 +297,10 @@ sub _expand_insert_clause_from { } return $data if ref($data) eq 'HASH' and $data->{-row}; my ($f_aqt, $v_aqt) = $self->_expand_insert_values($data); - return (from => { -values => $v_aqt }, ($f_aqt ? (fields => $f_aqt) : ())); + return ( + from => { -values => [ $v_aqt ] }, + ($f_aqt ? (fields => $f_aqt) : ()), + ); } sub _expand_insert_clause_returning { diff --git a/lib/SQL/Abstract/Test.pm b/lib/SQL/Abstract/Test.pm index 71fba6c..c642f42 100644 --- a/lib/SQL/Abstract/Test.pm +++ b/lib/SQL/Abstract/Test.pm @@ -24,9 +24,9 @@ use SQL::Abstract::Tree; my $e1 = $self->$orig(@args); my $e2 = $self->$orig($e1); (our $tb)->is_eq( - (map Data::Dumper::Concise::Dumper($_), $e1, $e2), + (map Data::Dumper::Concise::Dumper($_), $e2, $e1), 'expand_expr stability ok' - ); + );# or die; return $e1; }; no strict 'refs'; no warnings 'redefine';