Can't search contain underscore (string)

Can't search contain underscore (string)

dheirodheiro Posts: 2Questions: 0Answers: 0
edited April 2017 in Free community support

Hi, i use server side using ajax, when i search with underscore keyword (_) it result no record fount.
but i'm run manual query is work fine in mysql with LIKE

and use IgnitedDatatables for codeigniter

Best regard,
Thanks

Replies

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    If you are using server-side processing, this is a server-side issue, since the filtering is done there. Specifically in this case an underscore in an SQL wildcard means "any character". The server-side script (IgnitedDatatables in this case) would need to escape the underscore.

    Allan

  • dheirodheiro Posts: 2Questions: 0Answers: 0

    Thanks for the answer, im solving this issue by remove escape_like_str in codeigniter library, but result not accurate.

  • tangerinetangerine Posts: 3,342Questions: 35Answers: 394

    Are you asking the author of IgnitedDatatables about this?

  • bsulzbsulz Posts: 1Questions: 0Answers: 0

    2 years later, but this may be helpful to anyone with the same issue. Using Ignited Tables v 2.0.1 <beta>, you will need to edit the LIKE lines in the get_filtering() method from :

    $sWhere .= $this->select[$mColArray[$i]['data']] . " LIKE '%" . $sSearch . "%' OR ";
    

    to:

    $sWhere .= $this->select[$mColArray[$i]['data']] . " LIKE '%" . $sSearch . "%' ESCAPE '!' OR ";
    

    https://www.codeigniter.com/userguide3/database/queries.html explains the reason:

    "The escape_like_str() method uses ‘!’ (exclamation mark) to escape special characters for LIKE conditions. Because this method escapes partial strings that you would wrap in quotes yourself, it cannot automatically add the ESCAPE '!' condition for you, and so you’ll have to manually do that."

This discussion has been closed.