Error while storing "<" and "<=" in DB

Wednesday, 15 May 2013 · 5 messages
JB
John Best15 May 2013 10:57 #
Hi there, I am trying to save the generated queries in database, to have a Search History. Some of my queries have "where" conditions with < (less than) and <= (less than equal to operators. This is the insert query -
for $x in doc('SHIST')/Searches return
insert node <SH><Id>0</Id><Date>20130515 14:05:44</Date><Query>
for $x in doc('Docs')/Docs/Doc where$x/Title[Desc/@name='IT' and Year >=
'2010' and Year <= '2013']
</Query></SH> as last into $x
I am getting error "Expecting tag name, '<=' found Any workaround for the same...??
-- Have a nice day JBest
CG
Christian Grün15 May 2013 12:03 #
Hi John, your query contained several syntactical bugs; this one is probably what you were looking for:
for $x in doc('SHIST')/Searches
return insert node
  <SH><Id>0</Id><Date>20130515 14:05:44</Date><Query>{
       for $x in doc('Docs')/Docs/Doc
     where $x/Title[Desc/@name='IT'
       and Year >= '2010'
       and Year <= '2013']
    return $x
  }</Query></SH>
  as last into $x
Best, Christian
FG
Florent Georgesin reply to John Best, 15 May 2013, 10:5715 May 2013 12:05 #
Quoted text · John Best · 1 line
On 15 May 2013 10:57, John Best wrote:
Hi,
Quoted text · John Best · 1 line
> <Query>... Year <= '2013']</Query>
So you don't evaluate the content of the element Query, but you rather store the lexical representation of an XQuery query as its content. I guess this is not a bug and really what you want. Because this is XML content as any XML content, you need to escape the '<' characters, like that:
    <Query>... Year &lt;= '2013']</Query>
Regards,
JE
Jens Erat15 May 2013 12:06 #
missed sending to list...
-- Jens Erat [phone]: tel:+49-151-56961126 [mail]: mailto:email at jenserat.de [jabber]: xmpp:jabber at jenserat.de [web]: http://www.jenserat.de PGP: 350E D9B6 9ADC 2DED F5F2 8549 CBC2 613C D745 722B Anfang der weitergeleiteten Nachricht:
Quoted text · Florent Georges · 64 lines
> Von: Jens Erat <jens.erat at uni-konstanz.de> > Betreff: Aw: [basex-talk] Error while storing "<" and "<=" in DB > Datum: 15. Mai 2013 11:40:29 MESZ > An: John Best <johnbest5673 at gmail.com> > > Hi John, > > as I understand your query you want to store the XQuery code in line three as text content in an XML database. > > In Text nodes, the characters `<`, `>` and `&` must be escaped as entities. Either you write > > for $x in /Docs/Doc where $x/Title[Desc/@name='IT' and Year &gt;= '2010' and Year &lt;= '2013'] > > or you mark the whole Query as CDATA (probably to be preferred): > > for $x in Searches return > insert node <SH><Id>0</Id><Date>20130515 14:05:44</Date><Query><![CDATA[ > for $x in /Docs/Doc where $x/Title[Desc/@name='IT' and Year >= '2010' and Year <= '2013'] > ]]></Query></SH> as last into $x > > Regards from Lake Constance, Germany > Jens > > -- > Jens Erat > > [phone]: tel:+49-151-56961126 > [mail]: mailto:email at jenserat.de > [jabber]: xmpp:jabber at jenserat.de > [web]: http://www.jenserat.de > > PGP: 350E D9B6 9ADC 2DED F5F2 8549 CBC2 613C D745 722B > > > > Am 15.05.2013 um 10:57 schrieb John Best <johnbest5673 at gmail.com>: > >> Hi there, >> >> I am trying to save the generated queries in database, to have a Search History. >> >> Some of my queries have "where" conditions with < (less than) and <= (less than equal to operators. >> >> This is the insert query - >> >> for $x in doc('SHIST')/Searches return >> insert node <SH><Id>0</Id><Date>20130515 14:05:44</Date><Query> >> for $x in doc('Docs')/Docs/Doc where$x/Title[Desc/@name='IT' and Year >= '2010' and Year <= '2013'] >> </Query></SH> as last into $x >> >> I am getting error "Expecting tag name, '<=' found >> >> Any workaround for the same...?? >> >> -- >> Have a nice day >> JBest >> >> >> _______________________________________________ >> BaseX-Talk mailing list >> BaseX-Talk at mailman.uni-konstanz.de >> https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >
CG
Christian Grünin reply to Florent Georges, 15 May 2013, 12:0515 May 2013 12:19 #
…thanks for the corrections.
Quoted text · John Best · 26 lines
On Wed, May 15, 2013 at 12:05 PM, Florent Georges <fgeorges at fgeorges.org> wrote: > On 15 May 2013 10:57, John Best wrote: > > Hi, > >> <Query>... Year <= '2013']</Query> > > So you don't evaluate the content of the element Query, but you > rather store the lexical representation of an XQuery query as its > content. I guess this is not a bug and really what you want. > > Because this is XML content as any XML content, you need to escape > the '<' characters, like that: > > <Query>... Year &lt;= '2013']</Query> > > Regards, > > -- > Florent Georges > http://fgeorges.org/ > http://h2oconsulting.be/ > _______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk

⚡Generated with XQuery