From: Matt S Trout Date: Fri, 5 Apr 2019 18:33:42 +0000 (+0000) Subject: add select method to ::Clauses and fix bugs X-Git-Tag: v1.90_01~251 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=81b270e78d4ccf8d84093ba0b35d405140e0f9d7;p=dbsrgits%2FSQL-Abstract.git add select method to ::Clauses and fix bugs --- diff --git a/lib/SQL/Abstract/Clauses.pm b/lib/SQL/Abstract/Clauses.pm index 3b8409e..86b468f 100644 --- a/lib/SQL/Abstract/Clauses.pm +++ b/lib/SQL/Abstract/Clauses.pm @@ -45,7 +45,8 @@ sub _render_statement { my @parts; foreach my $clause (@{$self->{clauses_of}{$type}}) { next unless my $clause_expr = $args->{$clause}; - my ($sql, @bind) = $self->render_expr($clause_expr); + local $self->{convert_where} = $self->{convert} if $clause eq 'where'; + my ($sql, @bind) = $self->render_aqt($clause_expr); next unless defined($sql) and length($sql); push @parts, [ $self->_sqlcase(join ' ', split '_', $clause).' '.$sql, @@ -55,4 +56,17 @@ sub _render_statement { return $self->_join_parts(' ', @parts); } +sub select { + my ($self, @args) = @_; + my %clauses; + @clauses{qw(from select where order_by)} = @args; + # This oddity is to literalify since historically SQLA doesn't quote + # a single identifier argument, and the .'' is to copy $clauses{select} + # before taking a reference to it to avoid making a reference loop + $clauses{select}= \(($clauses{select}||'*').'') + unless ref($clauses{select}); + my ($sql, @bind) = $self->render_expr({ -select => \%clauses }); + return wantarray ? ($sql, @bind) : $sql; +} + 1;