[Dbix-class] Using 'like' query with data containing wildcard characters requiring ESCAPE?

Bob MacCallum uncoolbob at gmail.com
Mon Jul 21 11:22:59 GMT 2014


Hi Ken,

This works for me - did you try the obvious?

$resultset->search({ name => { 'like' => '%\_%' } } )

cheers,
Bob





On Fri, Jul 18, 2014 at 7:24 PM, Kenneth Ölwing <kenneth at olwing.se> wrote:

> Hi,
>
> I happen to have text data in my table that has the '_' (underscore)
> character, and I wanted to do a like search.
>
> So to find all rows with '_' I did:
>
>     my @rows = $rs->search( { data => { like => '%_%' } } );
>
> and running with DBIC_TRACE=1, I see:
>
>     SELECT me.data FROM test me WHERE ( data LIKE ? ): '%_%'
>
> I didn't get the result I was expecting. And duh, it dawned on me that '_'
> is itself a wildcard char...
>
> After realising that, I researched and found out that I could write
> something like this (a direct query):
>
>     SELECT * FROM test WHERE (data LIKE '%\_%' ESCAPE '\');
>
> Being a beginner with DBIx::Class, I may not have found the right place to
> look, but so far no luck...can I achieve this effect with the Perl code,
> and if so how? I'm using SQLite for the moment and Perl 5.16 and latest
> DBIx::Class.
>
> TIA, any help appreciated.
>
> ken1
>
>
> -----
> No virus found in this message.
> Checked by AVG - www.avg.com
> Version: 2014.0.4716 / Virus Database: 3986/7876 - Release Date: 07/18/14
>
>
> _______________________________________________
> List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
> IRC: irc.perl.org#dbix-class
> SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
> Searchable Archive: http://www.grokbase.com/group/
> dbix-class at lists.scsys.co.uk
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20140721/352d4f67/attachment.htm>


More information about the DBIx-Class mailing list