jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bilobag <bilo...@hotmail.com>
Subject Re: escape characters in search/query expression
Date Tue, 28 Aug 2007 19:12:16 GMT

I am still slightly confused by your response.  Do I correctly understand the
rules that {', ", -, \} must be escaped by a "\"?  It also seems like other
characters like a single quote need to be escaped differently.  Do you know
which characters and how i need to escape them?  It looks like you fixed my
query by escaping my single quote with a backslash and another single quote. 
Is the single quote the only special exception?  Can I just escape the other
characters with just a backslash? Please clarify.  Thanks for your help.

-David 


Marcel Reutegger wrote:
> 
> bilobag wrote:
>> I see in the JCR spec 6.6.5.2 - it states that {', ", -, \} must be
>> escaped
>> by a "\".  However when I try to escape a single quote with a backslash,
>> the
>> query throws an xpath query syntax error.  Is the JCR spec correct or is
>> there other documentation about what characters need to be escaped?  I am
>> already using the ISO9075 class to encode any node paths in my query.  It
>> would be even better if there is already a method that escapes search
>> strings.  The following is the query that fails.  I am trying to pass the
>> string "test's" into the contains(), but when i escape the single quote
>> with
>> a backslash, the query throws a sytax error.  
>> 
>> /jcr:root/app_x0020_root//*[@jcr:primaryType = 'cwe:file' and 
>> jcr:contains(jcr:content, 'test\'s')]/(rep:excerpt()) order by @jcr:score
>> descending
> 
> there are alway to escape mechanisms you have to keep in mind.
> 
> 1) escaping a character within the contains statement. e.g. the spec says
> you 
> can search for a phrase using double quotes: "foo bar". that means if you
> want 
> to use a double quote as literal an not a delimiter for a phrase you have
> to 
> escape it.
> 
> 2) escaping any string literal appropriately in XPath or SQL. E.g. in
> XPath the 
> string literal test's must be written as: 'test''s'
> 
> for your query that means you have to write:
> 
> /jcr:root/app_x0020_root//*[@jcr:primaryType = 'cwe:file' and
>   jcr:contains(jcr:content, 'test\''s')]/(rep:excerpt()) order by
> @jcr:score
>   descending
> 
> regards
>   marcel
> 
> 

-- 
View this message in context: http://www.nabble.com/escape-characters-in-search-query-expression-tf4337638.html#a12374130
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.


Mime
View raw message