From: Dagfinn Ilmari Mannsåker Date: Sun, 28 Jan 2018 21:46:31 +0000 (+0000) Subject: Allow scalar- and arrayrefrefs in select list X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=refs%2Fheads%2Fselect-list-reffery;p=dbsrgits%2FSQL-Abstract.git Allow scalar- and arrayrefrefs in select list TODO: docs --- diff --git a/lib/SQL/Abstract.pm b/lib/SQL/Abstract.pm index bd512ca..b09ead0 100644 --- a/lib/SQL/Abstract.pm +++ b/lib/SQL/Abstract.pm @@ -478,8 +478,21 @@ sub select { sub _select_fields { my ($self, $fields) = @_; - return ref $fields eq 'ARRAY' ? join ', ', map { $self->_quote($_) } @$fields - : $fields; + + $self->_SWITCH_refkind($fields, { + ARRAYREF => sub { join ', ', map { $self->_quote($_) } @$fields }, + + ARRAYREFREF => sub { + my ($s, @b) = @$$fields; + $self->_assert_bindval_matches_bindtype(@b); + ($s, @b); + }, + + SCALARREF => sub { $$fields }, + + # For back-compat + SCALAR => sub { $fields }, + }); } #====================================================================== diff --git a/t/01generate.t b/t/01generate.t index ebe3aad..3f4ab8b 100644 --- a/t/01generate.t +++ b/t/01generate.t @@ -616,7 +616,21 @@ my @tests = ( stmt_q => 'DELETE FROM `test` WHERE ( `requestor` IS NULL ) RETURNING `id`, `created_at`', bind => [] }, -); + { + func => 'select', + args => ['wibble', \['func(?)', 42]], + stmt => 'select func(?) from wibble', + stmt_q => 'select func(?) from `wibble`', + bind => [42], + }, + { + func => 'select', + args => ['wibble', \'"wobble"'], + stmt => 'select "wobble" from wibble', + stmt_q => 'select "wobble" from `wibble`', + bind => [], + }, + ); # check is( not) => undef for my $op (qw(not is is_not), 'is not') {