[Dbix-class] Using 'like' query with data containing wildcard characters requiring ESCAPE?
Kenneth Ölwing
kenneth at olwing.se
Fri Jul 18 18:24:31 GMT 2014
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
More information about the DBIx-Class
mailing list