Skip to content

Commit

Permalink
Allow scalar- and arrayrefrefs in select list
Browse files Browse the repository at this point in the history
TODO: docs
  • Loading branch information
ilmari committed Feb 2, 2018
1 parent daa4ccd commit caa82ff
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
17 changes: 15 additions & 2 deletions lib/SQL/Abstract.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
});
}

#======================================================================
Expand Down
16 changes: 15 additions & 1 deletion t/01generate.t
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down

0 comments on commit caa82ff

Please sign in to comment.