[xwiki-devs] query implying 2 XObjects
Hi! I'm trying to understand the Query Guide available at http://xpescaderias.environmentalchange.net/xwiki/bin/view/Species/SpeciesCl... but still failing to get an answer to a problem. I navigate to a document with this query... #set($query = ", BaseObject as obj, LargeStringProperty as prop where doc.fullName = obj.name and obj.className='Users.PdrUserClass' and obj.id=prop.id.id and prop.id.name='Species' and prop.value like '" + $species + "' order by doc.fullName asc") I would like to set the value of $species to the value of the property GalicianName of the class Species.SpeciesClass instantiated in this document. Please, could anybody help me to solve this doubt? Thanks! Ricardo -- Ricardo Rodríguez CTO eBioTIC. Life Sciences, Data Modeling and Information Management Systems
[Ricardo Rodriguez] eBioTIC. wrote:
Hi!
I'm trying to understand the Query Guide available at http://xpescaderias.environmentalchange.net/xwiki/bin/view/Species/SpeciesCl... but still failing to get an answer to a problem.
I navigate to a document with this query...
#set($species = $doc.getObject('Species.SpeciesClass').getProperty('GalicianName').getValue())
#set($query = ", BaseObject as obj, LargeStringProperty as prop where doc.fullName = obj.name and obj.className='Users.PdrUserClass' and obj.id=prop.id.id and prop.id.name='Species' and prop.value like '" + $species + "' order by doc.fullName asc")
That should do it. Note: For better security the query should be: #set($query = ", BaseObject as obj, LargeStringProperty as prop where doc.fullName = obj.name and obj.className='Users.PdrUserClass' and obj.id=prop.id.id and prop.id.name='Species' and prop.value like ? order by doc.fullName asc") then #set($results = $xwiki.searchDocuments($query, [$species]) This makes sure $species is escaped preventing sql injection. Caleb
I would like to set the value of $species to the value of the property GalicianName of the class Species.SpeciesClass instantiated in this document.
Please, could anybody help me to solve this doubt? Thanks!
Ricardo
Thanks! Caleb James DeLisle wrote:
#set($species = $doc.getObject('Species.SpeciesClass').getProperty('GalicianName').getValue()) That should do it.
Yeah! The hierarchy is pretty clear now... that you have wrote it down! :-) Thanks!
Note: For better security the query should be: #set($query = ", BaseObject as obj, LargeStringProperty as prop where doc.fullName = obj.name and obj.className='Users.PdrUserClass' and obj.id=prop.id.id and prop.id.name='Species' and prop.value like ? order by doc.fullName asc") then #set($results = $xwiki.searchDocuments($query, [$species])
This makes sure $species is escaped preventing sql injection.
Thanks! Security matters! Just to avoid some lost of time to others: a closing right parenthesis here... #set($results = $xwiki.searchDocuments($query, [$species]) It must read... #set($results = $xwiki.searchDocuments($query, [$species])) What I get here with the #set directive above is, let's say, choco. But I do need '%choco%'. Please, how could I get this? I've tried a number of concatenation options, but I'm not able to get the right string. Thanks once again. Cheers, -- Ricardo Rodríguez CTO eBioTIC. Life Sciences, Data Modeling and Information Management Systems
[Ricardo Rodriguez] eBioTIC. wrote:
Thanks!
Caleb James DeLisle wrote:
#set($species = $doc.getObject('Species.SpeciesClass').getProperty('GalicianName').getValue()) That should do it.
Yeah! The hierarchy is pretty clear now... that you have wrote it down! :-) Thanks!
Note: For better security the query should be: #set($query = ", BaseObject as obj, LargeStringProperty as prop where doc.fullName = obj.name and obj.className='Users.PdrUserClass' and obj.id=prop.id.id and prop.id.name='Species' and prop.value like ? order by doc.fullName asc") then #set($results = $xwiki.searchDocuments($query, [$species])
This makes sure $species is escaped preventing sql injection.
Thanks! Security matters!
Just to avoid some lost of time to others: a closing right parenthesis here...
#set($results = $xwiki.searchDocuments($query, [$species])
It must read...
#set($results = $xwiki.searchDocuments($query, [$species]))
haha yup they get me all the time.
What I get here with the #set directive above is, let's say, choco. But I do need '%choco%'. Please, how could I get this? I've tried a number of concatenation options, but I'm not able to get the right string.
Thanks once again. Cheers,
#set($species = '%' "$doc.getObject('Species.SpeciesClass').getProperty('GalicianName').getValue()" + '%') ^- that should work. if not try this: #set($species = "%${doc.getObject('Species.SpeciesClass').getProperty('GalicianName').getValue()}%") Hint about velocity, "this" gets interpreted as syntax, then pasted as a string 'this' is just non parsed content. Caleb
Thanks! Caleb James DeLisle wrote:
#set($species = '%' "$doc.getObject('Species.SpeciesClass').getProperty('GalicianName').getValue()" + '%')
It does! My cents... #set($species = '%' + "$doc.getObject('Species.SpeciesClass').getProperty('GalicianName').getValue()" + '%')
if not try this: #set($species = "%${doc.getObject('Species.SpeciesClass').getProperty('GalicianName').getValue()}%")
It works as well.
Hint about velocity, "this" gets interpreted as syntax, then pasted as a string 'this' is just non parsed content.
Oooooh! Thanks! This was making me nuts. Page 21 of *Velocity Users Guide *reads: "when the string literal is enclosed in single quote characters, it will not be parsed"... :-( I must read more, and ask less... but without asking the meaning of what I read is poorer! Thanks for answering! As a "pure" Velocity concatenation example... #set($species = "${doc.getObject('Species.SpeciesClass').getProperty('GalicianName').getValue()}") #set($wc = "%") #set($speciesq = "$wc$species$wc") #set($query = ", BaseObject as obj, LargeStringProperty as prop where doc.fullName = obj.name and obj.className='Users.PdrUserClass' and obj.id=prop.id.id and prop.id.name='Species' and prop.value like ? order by doc.fullName asc") #set($results = $xwiki.searchDocuments($query, [$speciesq])) But what I don't understand yet is where $species, or "$speciesq" in this last example get quoted. ? in $query needs '%whatever%', and not %whatever% that is what I get if I read $speciesq. Thanks for your help! Ricardo -- Ricardo Rodríguez CTO eBioTIC. Life Sciences, Data Modeling and Information Management Systems
participants (2)
-
[Ricardo Rodriguez] eBioTIC. -
Caleb James DeLisle