-4

I'm trying to use Perl Dancer quick_select to quickly fetch rows from the database. I'm using a list of items from the user that I got like this: my @arr=split(/,/, $inline);

I keep getting this error when using the items from the user:

DBD::mysql::db selectall_arrayref failed: Unknown column 'val2' in 'where clause'

This does not work:

my @rows = $connect->quick_select('table', { column => @arr});

But this does work:

my @rows = $connect->quick_select('table', { column => ['val1', 'val2']});`

Apparently [] denotes a list but @arr is an array in Perl? So I've tried converting it to a list but this also does not work:

my @rows = $connect->quick_select('table', { column => @arr[0..$#arr]});

The table and column names have been changed to protect the data. How can I fix this so quick_select will work with dynamic data from the user?

Sinan Ünür
  • 116,958
  • 15
  • 196
  • 339
Chip Dean
  • 4,222
  • 3
  • 24
  • 36
  • Dancer doesn't have a `quick_select` function. I assume you're using a Dancer plugin to add that to your program. It would be helpful if you could tell us where it comes from. – Dave Cross Jul 20 '17 at 08:34

1 Answers1

3

Apparently [] denotes a list but @arr is an array in Perl? So I've tried converting it to a list but this also does not work.

That's not correct. [] denotes an array reference in Perl. An array is an ordered list of scalars indexed by number, and an array reference is a scalar that "points to" an array.

You can take the array you scoop up from $input, take a reference to it with the \@array syntax, and send it in that way:

my @rows = $connect->quick_select('table', { column => \@arr});

You can take that one step further (at possibly some cost to clarity) by forcing the call to split into an array reference inline:

my @rows = $connect->quick_select('table', { column => [split(/,/, $inline)] });
stevieb
  • 9,065
  • 3
  • 26
  • 36