my $sub = "is_${name}";
*$sub = sub {
my $dq = $_[0]||$_;
- $dq->{type} eq $name
+ $dq->{type} and $dq->{type} eq $name
};
push @EXPORT, $sub;
if ($map{$name}) {
}
}
+sub is_Having { is_Where($_[0]) and is_Group($_[0]->{from}) }
+
+push @EXPORT, 'is_Having';
+
sub compose (&@) {
my $code = shift;
require Scalar::Util;
sub _maybe_parenthesise {
my ($self, $dq) = @_;
for ($dq) {
- return is_Select() || is_Group() || is_Slice()
+ return is_Select() || is_Group() || is_Slice() || is_Having()
? [ '(', $self->_render($dq), ')' ]
: $self->_render($dq);
}
unless is_Select my $orig_select = $dq->{from};
my %remapped = $self->_subquery_remap($orig_select);
my $first_from = $remapped{inner_body};
+ # Should we simply strip until we reach a join/alias/etc. here?
+ $first_from = $first_from->{from}{from} if is_Having($first_from);
$first_from = $first_from->{from} if is_Where($first_from);
while (is_Join $first_from) {
$first_from = $first_from->{left};