jackrabbit-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Marcel Reutegger <marcel.reuteg...@gmx.net>
Subject Re: Escaping in SQL CONTAINS clause
Date Fri, 06 Jan 2006 15:16:56 GMT
Daniel Hagen wrote:
> I am struggeling with a SQL Query containing ' characters.
> As I understand the spec (section, the query 
> SELECT <field-list> FROM <nodetype> WHERE CONTAINS(*, 'O\'Hara') ORDER BY
> <field-list>
> should return all nodes having properties containing the word O'Hara .

section only talks about escaping of the search expression 
itself, but not about escaping a string literal in general when used in 
SQL. the backslash is used to compensate the otherwise semantic meaning 
of the characters: " (double quote), - (hyphen) and ' (single quote)
though IMO the single quote does not actually need escaping because the 
contains function does not define a semantic for a single quote in the 
search expression.

so, your contains literal is basically correct, but it does not respect 
the SQL syntax. a single quote in a string literal needs to be escaped 
with an additional single quote. the correct expression is:

CONTAINS(*, 'O\''Hara')

as I mentioned already, because there is no semantic meaning to a single 
quote jackrabbit also accepts and treats the following expression 

CONTAINS(*, 'O''Hara')


View raw message