in reply to DBI, quoting, and LIKE searches

Try something like this for your select and bind the user entered string to the parameter

Select * from mytable where myfield like '%' || ? || '%'
--- print map { my ($m)=1<<hex($_)&11?' ':''; $m.=substr('AHJPacehklnorstu',hex($_),1) } split //,'2fde0abe76c36c914586c';

Replies are listed 'Best First'.
Re: Re: DBI, quoting, and LIKE searches
by Anonymous Monk on Dec 26, 2002 at 17:21 UTC
    Aha! It works. But, will this have the performance problems associated with using place holders and saying $sth->execute->("foo%")? It mentioned here that it didn't use the Index like it should. I'm not a database expert, so I don't know how to test this.

      Since these LIKE strings start with a '%', the database can't use an index at all. So that should not be a concern here.

              - tye
        I see... That solution will work great for my current problem then. But, for future reference, will it use the index like it should if the LIKE string does not start with a '%'?