You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by gsoap <gs...@yahoo.com> on 2007/06/08 14:51:55 UTC

How to escape double quote in SQL term?

Hi,

How can I escape double quote in my following query, following attempt gives
error?

SELECT * FROM nt:base WHERE CONTAINS(., '"This term contains \" double
quote."')

Thanks for help.
-- 
View this message in context: http://www.nabble.com/How-to-escape-double-quote-in-SQL-term--tf3889614.html#a11025910
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.


Re: How to escape double quote in SQL term?

Posted by Jukka Zitting <ju...@gmail.com>.
Hi,

On 6/11/07, gsoap <gs...@yahoo.com> wrote:
> This does not work in case if we search only " see following query:
>
> SELECT * FROM nt:base WHERE CONTAINS(., '""""')
>
> In the above query we have a single term and we are searching only " which
> you say should be replaced by "" but it results in parser exception.

I don't think the full text index will contain a term with just the "
character. I think the full text query parser may also get confused by
such a query string, which would explain the exception you are seeing.

BR,

Jukka Zitting

Re: How to escape double quote in SQL term?

Posted by Marcel Reutegger <ma...@gmx.net>.
Alexandru Popescu ☀ wrote:
> As far as I know, the JCR XPath is far from supporting all XPath
> features, so I guess we must stick with the description in the spec.

I was referring to the xpath spec for questions like, 'how do I escape a single 
quote in a string literal?'

> Then what does it come from? Is this a Jackrabbit internal detail?

I'm sorry, I was wrong. searching with a phrase *is* specified in the jsr 170 spec:

<jsr-170>
A term may be either a single word or a phrase delimited by double quotes (").
</jsr-170>

but e.g. using wildcards are jackrabbit specific.

regards
  marcel

Re: How to escape double quote in SQL term?

Posted by Alexandru Popescu ☀ <th...@gmail.com>.
On 6/20/07, Marcel Reutegger <ma...@gmx.net> wrote:
> Alexandru Popescu ☀ wrote:
> > Thanks for the insights. I am wondering where are these bits documented?
>
> for the plain XPath syntax, here:
>
> http://www.w3.org/TR/xpath20/
>

As far as I know, the JCR XPath is far from supporting all XPath
features, so I guess we must stick with the description in the spec.

> as for the syntax within the jcr:contains function, some of it is in the jsr 170
> spec, but not the phrase part.
>

Then what does it come from? Is this a Jackrabbit internal detail?

tia,

./alex
--
.w( the_mindstorm )p.

> anyone volunteering to create a wiki page under
> http://wiki.apache.org/jackrabbit/Search in the proprietary section?
>
> regards
>   marcel
>

Re: How to escape double quote in SQL term?

Posted by Marcel Reutegger <ma...@gmx.net>.
Alexandru Popescu ☀ wrote:
> Thanks for the insights. I am wondering where are these bits documented?

for the plain XPath syntax, here:

http://www.w3.org/TR/xpath20/

as for the syntax within the jcr:contains function, some of it is in the jsr 170 
spec, but not the phrase part.

anyone volunteering to create a wiki page under 
http://wiki.apache.org/jackrabbit/Search in the proprietary section?

regards
  marcel

Re: How to escape double quote in SQL term?

Posted by Alexandru Popescu ☀ <th...@gmail.com>.
On 6/18/07, Marcel Reutegger <ma...@gmx.net> wrote:
> gsoap wrote:
> > This does not work in case if we search only " see following query:
>
> you cannot search for the double quote character using the contains function.
> the default tokenizer recognizes the character as noise and ignores it.
>
> > SELECT * FROM nt:base WHERE CONTAINS(., '""""')
> >
> > In the above query we have a single term and we are searching only " which
> > you say should be replaced by "" but it results in parser exception.
>
> please note that you don't have to escape the the double quote in a SQL string
> literal. you only have to escape the single quote:
>
> e.g. if you have the following String literal in your java code:
>
> String s = "this string contains ' a single quote";
>
> when you use this string in a SQL contains function you must encode it like this:
>
> ... where contains(., 'this string contains '' a single quote')
>
> but here's the important part: double quotes in the string literal of a contains
> function have a special semantic. they mark phrases. e.g. you can search for
> nodes that contain the words apache and jackrabbit as consecutive terms:
>
> ... where contains(., '"apache jackrabbit"')
>
> if you have just one double quote or nothing between two double quotes the
> parser will complain that the contains statement is malformed.
>
> regards
>   marcel
>

Hi Marcel!

Thanks for the insights. I am wondering where are these bits documented?

tia,

./alex
--
.w( the_mindstorm )p.

Re: How to escape double quote in SQL term?

Posted by Marcel Reutegger <ma...@gmx.net>.
gsoap wrote:
> This does not work in case if we search only " see following query:

you cannot search for the double quote character using the contains function. 
the default tokenizer recognizes the character as noise and ignores it.

> SELECT * FROM nt:base WHERE CONTAINS(., '""""')
> 
> In the above query we have a single term and we are searching only " which
> you say should be replaced by "" but it results in parser exception.

please note that you don't have to escape the the double quote in a SQL string 
literal. you only have to escape the single quote:

e.g. if you have the following String literal in your java code:

String s = "this string contains ' a single quote";

when you use this string in a SQL contains function you must encode it like this:

... where contains(., 'this string contains '' a single quote')

but here's the important part: double quotes in the string literal of a contains 
function have a special semantic. they mark phrases. e.g. you can search for 
nodes that contain the words apache and jackrabbit as consecutive terms:

... where contains(., '"apache jackrabbit"')

if you have just one double quote or nothing between two double quotes the 
parser will complain that the contains statement is malformed.

regards
  marcel

Re: How to escape double quote in SQL term?

Posted by gsoap <gs...@yahoo.com>.
Hi,

This does not work in case if we search only " see following query:

SELECT * FROM nt:base WHERE CONTAINS(., '""""')

In the above query we have a single term and we are searching only " which
you say should be replaced by "" but it results in parser exception.

Kindly suggest something.

Thanks.


Jukka Zitting wrote:
> 
> Hi,
> 
> On 6/8/07, gsoap <gs...@yahoo.com> wrote:
>> How can I escape double quote in my following query, following attempt
>> gives
>> error?
>>
>> SELECT * FROM nt:base WHERE CONTAINS(., '"This term contains \" double
>> quote."')
> 
> You can use "" for that. Like this:
> 
> SELECT * FROM nt:base WHERE CONTAINS(., '"This term contains "" double
> quote."')
> 
> BR,
> 
> Jukka Zitting
> 
> 

-- 
View this message in context: http://www.nabble.com/How-to-escape-double-quote-in-SQL-term--tf3889614.html#a11056250
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.


Re: How to escape double quote in SQL term?

Posted by Jukka Zitting <ju...@gmail.com>.
Hi,

On 6/8/07, gsoap <gs...@yahoo.com> wrote:
> How can I escape double quote in my following query, following attempt gives
> error?
>
> SELECT * FROM nt:base WHERE CONTAINS(., '"This term contains \" double
> quote."')

You can use "" for that. Like this:

SELECT * FROM nt:base WHERE CONTAINS(., '"This term contains "" double quote."')

BR,

Jukka Zitting