SQL equality predicate escaping single quotes

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

SQL equality predicate escaping single quotes

Kyle Lilly
Hi,

When using the SQL handler is there any way to escape single quotes in
boolean predicates? A query like:

SELECT title FROM books WHERE author_lastname = 'O''Reilly'

Will return no results for authors with the last name "O'Reilly" but will
return hits for books with a last name of "OReilly". I can perform a
standard Solr term search using "lastname:O'Reilly" and get back the
expected results. Looking through the code it appears all single quotes are
stripped from term values in the SQL handler -
https://github.com/apache/lucene-solr/blame/1d85cd783863f75cea133fb9c452302214165a4d/solr/core/src/java/org/apache/solr/handler/sql/SolrFilter.java#L136.
If this is by design is there any way to use single quotes in a term
predicate with SQL?

Thanks.

- Kyle
Reply | Threaded
Open this post in threaded view
|

Re: SQL equality predicate escaping single quotes

Joel Bernstein
It does appear that single quotes are being removed. If you want to provide
a patch that allows single quotes to get passed through, I can help with
testing and committing.


On Thu, Aug 8, 2019 at 11:28 AM Kyle Lilly <[hidden email]> wrote:

> Hi,
>
> When using the SQL handler is there any way to escape single quotes in
> boolean predicates? A query like:
>
> SELECT title FROM books WHERE author_lastname = 'O''Reilly'
>
> Will return no results for authors with the last name "O'Reilly" but will
> return hits for books with a last name of "OReilly". I can perform a
> standard Solr term search using "lastname:O'Reilly" and get back the
> expected results. Looking through the code it appears all single quotes are
> stripped from term values in the SQL handler -
>
> https://github.com/apache/lucene-solr/blame/1d85cd783863f75cea133fb9c452302214165a4d/solr/core/src/java/org/apache/solr/handler/sql/SolrFilter.java#L136
> .
> If this is by design is there any way to use single quotes in a term
> predicate with SQL?
>
> Thanks.
>
> - Kyle
>