I have a problem with apostrophe in xwql queries in velocity.
This query works just fine #set($ls1=$services.query.xwql(“from doc.object(‘Gestion de risques .Plan de gestion des risques.Risques et enjeux.Code.Risques et enjeuxClass’) as risques order by risques.name”).execute())
This one doesn’t #set($ls1=$services.query.xwql(‘from doc.object(“Gestion de risques .Plan de gestion des risques.Mesures d’atténuation.Code.Mesures d’atténuationClass”) as mesures order by mesures.name’).execute())
In the first case, double quotes wrap the entire query string and inside them you can use as many single quotes you want without breaking the syntax.
In the second case single quotes are wrongly paired: (‘from with d’atténuation and d’atténuationClass with name’) so the syntax is broken by them.
In fact, pasting this in a text editor, I can see that at the beginning of the query string is used a single quote, while the enclosing one is an apostrophe.
Thanks, but I tried every permutations of quotes. Nothing worked.
I know that in JPQL double single quotes escapes single quotes, but this also didn’t work.
Normally you just need to double the quote to escape it in Velocity. For example:
#set ($xwql = "from doc.object('Pilotage.Pilotage SST.Règles d''affaires SST.Code.Règles d''affaires SSTClass') as processus where doc.title <> ''")
$services.query.xwql($xwql).execute())
However that won’t work in this case. If you check the stacktrace you get you’ll see:
Caused by: org.xwiki.query.jpql.parser.ParserException: [1,87] expecting: ')'
at org.xwiki.query.jpql.parser.Parser.parse(Parser.java:1385)
at org.xwiki.query.jpql.internal.JPQLParser.parse(JPQLParser.java:46)
at org.xwiki.query.xwql.internal.hql.XWQLtoHQLTranslator.translate(XWQLtoHQLTranslator.java:55)
#set($hql=", BaseObject as obj and obj.className='Pilotage.Pilotage SST.Règles d''affaires SST.Code.Règles d''affaires SSTClass'") $services.query.hql($hql).execute()
is the right way to do it?
It gives me :
Failed to execute the [velocity] macro. Cause: [unexpected token: and near line 1, column 104 [select doc.fullName from com.xpn.xwiki.doc.XWikiDocument doc , com.xpn.xwiki.objects.BaseObject as obj and obj.className=‘Pilotage.Pilotage SST.Règles d’‘affaires SST.Code.Règles d’‘affaires SSTClass’]]. Click on this message for details.