in reply to Trying to build a where clause to insert into a DBIx::Class Query

Hi, try this:

use strict; use warnings; use feature 'say'; use SQL::Abstract; my $input = 'Orlando Miguel Jose Fernando'; my @match = map { +{ 'like' => qq{'%$_%'} } } split ' ', $input; my %where = ( Name => [ -and => @match ] ); my $sqla = SQL::Abstract->new; my ($sql, @bind) = $sqla->select('People', undef, \%where); say $sql; say for @bind; __END__
Output:
$ perl 1208017.pl SELECT * FROM People WHERE ( ( Name LIKE ? AND Name LIKE ? AND Name LI +KE ? AND Name LIKE ? ) ) '%Orlando%' '%Miguel%' '%Jose%' '%Fernando%'

Hope this helps!


The way forward always starts with a minimal test.

Replies are listed 'Best First'.
Re^2: Trying to build a where clause to insert into a DBIx::Class Query
by phildeman (Scribe) on Jan 29, 2018 at 14:39 UTC

    Thanks 1nickt,

    That work. The only thing I had to do was to modify the mapping. You had qq{'%$_&'}.
    For whatever reason, DBIx::Class produced ''%Orlando%'', ''%Miguel%'', ''%Jose%'', ''%Fernandez%''.
    So, I removed the single quote from the mapping, qq{%$_%}, then it work perfectly.

    Thanks again for your help.

    -Phil-