Having trouble inserting elements using XQJ
Saturday, 22 May 2010 · 5 messages · last reply 26 May 2010
S
stefano22 May 2010 00:05 #
Hi,
I am attempting to execute an XQJ prepared expression that uses an external bind variable that accepts an xml element, and inserts it into the database document:
declare variable $inserto as element(*,xs:untyped) external;
let $root := basex:db('Annotations')/Annotations
return (insert node $inserto into $root)I prepare the above statement and I bind DOM element as follows (groovy syntax):
eltype = conn.createElementType(null, XQItemType.XQBASETYPE_ANYTYPE);
ixpr.bindNode(new QName("inserto"), irel, eltype);irel is dom element that serializes as follows:
<inserto id="6">
<testo>six</testo>
</inserto>unfortunately I get an NPE when I try to execute the Query:
groovy:000> rs = ixpr.executeQuery()
ERROR java.lang.NullPointerException:
null
at org.basex.query.item.FElem.copy (FElem.java:214)
at org.basex.query.item.FElem.copy (FElem.java:1)
at org.basex.query.item.FElem.copy (FElem.java:210)
at org.basex.query.item.FElem.copy (FElem.java:1)
at org.basex.query.expr.Constr.add (Constr.java:107) at org.basex.query.expr.Constr.<init> (Constr.java:53) at org.basex.query.up.Insert.atomic (Insert.java:60) at org.basex.query.up.Insert.atomic (Insert.java:1)
at org.basex.query.expr.Expr.iter (Expr.java:53)
at org.basex.query.QueryContext.iter (QueryContext.java:322) at org.basex.query.QueryContext.iter (QueryContext.java:290) at org.basex.api.xqj.BXQDynamicContext.execute (BXQDynamicContext.java:247) at org.basex.api.xqj.BXQPreparedExpression.executeQuery (BXQPreparedExpression.java:54) at groovysh_evaluate.run (groovysh_evaluate:10)
...
I am using BaseX 6.1
Am I doing anything wrong?
Stefano
CG
Christian Grün24 May 2010 14:56 #
Stefano,
sorry for the delay. Yes, this looks like a bug. To speed this up, could you provide us with a code snippet that's running out of the box? (I didn't manage to quickly reproduce the problem).
Thanks,
Christian
Quoted text · stefano · 46 lines
On Sat, May 22, 2010 at 12:05 AM, <stefano at santoro.org> wrote: > Hi, > > I am attempting to execute an XQJ prepared expression that uses an external bind variable that accepts an xml element, and inserts it into the database document: > > declare variable $inserto as element(*,xs:untyped) external; > let $root := basex:db('Annotations')/Annotations > return (insert node $inserto into $root) > > I prepare the above statement and I bind DOM element as follows (groovy syntax): > > eltype = conn.createElementType(null, XQItemType.XQBASETYPE_ANYTYPE); > ixpr.bindNode(new QName("inserto"), irel, eltype); > > irel is dom element that serializes as follows: > > <inserto id="6"> > <testo>six</testo> > </inserto> > > unfortunately I get an NPE when I try to execute the Query: > > groovy:000> rs = ixpr.executeQuery() > ERROR java.lang.NullPointerException: > null > at org.basex.query.item.FElem.copy (FElem.java:214) > at org.basex.query.item.FElem.copy (FElem.java:1) > at org.basex.query.item.FElem.copy (FElem.java:210) > at org.basex.query.item.FElem.copy (FElem.java:1) > at org.basex.query.expr.Constr.add (Constr.java:107) > at org.basex.query.expr.Constr.<init> (Constr.java:53) > at org.basex.query.up.Insert.atomic (Insert.java:60) > at org.basex.query.up.Insert.atomic (Insert.java:1) > at org.basex.query.expr.Expr.iter (Expr.java:53) > at org.basex.query.QueryContext.iter (QueryContext.java:322) > at org.basex.query.QueryContext.iter (QueryContext.java:290) > at org.basex.api.xqj.BXQDynamicContext.execute (BXQDynamicContext.java:247) > at org.basex.api.xqj.BXQPreparedExpression.executeQuery (BXQPreparedExpression.java:54) > at groovysh_evaluate.run (groovysh_evaluate:10) > ... > > I am using BaseX 6.1 > > Am I doing anything wrong? > > Stefano
___________________________
Christian Gruen
Universitaet Konstanz
Department of Computer & Information Science
D-78457 Konstanz, Germany
Tel: +49 (0)7531/88-4449, Fax: +49 (0)7531/88-3577
http://www.inf.uni-konstanz.de/~gruen
CG
Stefano,
thanks for your Java class. I hope the problem is now fixed; please have a look at our sources, or check out the latest versions from the Maven repository:
http://basex.org/maven/org/basex/basex/6.1.3/basex-6.1.3.jar http://basex.org/maven/org/basex/basex-api/6.1.3/basex-api-6.1.3.jar
Christian
Quoted text · Stefano Santoro · 72 lines
On Tue, May 25, 2010 at 10:21 PM, Stefano Santoro <stefano at santoro.org> wrote: > Hi Christian, > > thank you so very much for looking into this! I am enclosing a java > class that reproduces the NPE using the 6.1 base libraries. This code > assumes that you have created an 'Annotations' database with one > <Annotations/> root element. > > Ciao > Stefano > > > On Mon, May 24, 2010 at 8:56 AM, Christian Grün > <christian.gruen at gmail.com> wrote: >> Stefano, >> >> sorry for the delay. Yes, this looks like a bug. To speed this up, >> could you provide us with a code snippet that's running out of the >> box? (I didn't manage to quickly reproduce the problem). >> >> Thanks, >> Christian >> >> >> On Sat, May 22, 2010 at 12:05 AM, <stefano at santoro.org> wrote: >>> Hi, >>> >>> I am attempting to execute an XQJ prepared expression that uses an external bind variable that accepts an xml element, and inserts it into the database document: >>> >>> declare variable $inserto as element(*,xs:untyped) external; >>> let $root := basex:db('Annotations')/Annotations >>> return (insert node $inserto into $root) >>> >>> I prepare the above statement and I bind DOM element as follows (groovy syntax): >>> >>> eltype = conn.createElementType(null, XQItemType.XQBASETYPE_ANYTYPE); >>> ixpr.bindNode(new QName("inserto"), irel, eltype); >>> >>> irel is dom element that serializes as follows: >>> >>> <inserto id="6"> >>> <testo>six</testo> >>> </inserto> >>> >>> unfortunately I get an NPE when I try to execute the Query: >>> >>> groovy:000> rs = ixpr.executeQuery() >>> ERROR java.lang.NullPointerException: >>> null >>> at org.basex.query.item.FElem.copy (FElem.java:214) >>> at org.basex.query.item.FElem.copy (FElem.java:1) >>> at org.basex.query.item.FElem.copy (FElem.java:210) >>> at org.basex.query.item.FElem.copy (FElem.java:1) >>> at org.basex.query.expr.Constr.add (Constr.java:107) >>> at org.basex.query.expr.Constr.<init> (Constr.java:53) >>> at org.basex.query.up.Insert.atomic (Insert.java:60) >>> at org.basex.query.up.Insert.atomic (Insert.java:1) >>> at org.basex.query.expr.Expr.iter (Expr.java:53) >>> at org.basex.query.QueryContext.iter (QueryContext.java:322) >>> at org.basex.query.QueryContext.iter (QueryContext.java:290) >>> at org.basex.api.xqj.BXQDynamicContext.execute (BXQDynamicContext.java:247) >>> at org.basex.api.xqj.BXQPreparedExpression.executeQuery (BXQPreparedExpression.java:54) >>> at groovysh_evaluate.run (groovysh_evaluate:10) >>> ... >>> >>> I am using BaseX 6.1 >>> >>> Am I doing anything wrong? >>> >>> Stefano >> ___________________________ >
SS
Hi Christian,
thank you so very much for looking into this! I am enclosing a java class that reproduces the NPE using the 6.1 base libraries. This code assumes that you have created an 'Annotations' database with one <Annotations/> root element.
Ciao
Stefano
Quoted text · Christian Grün · 59 lines
On Mon, May 24, 2010 at 8:56 AM, Christian Grün <christian.gruen at gmail.com> wrote: > Stefano, > > sorry for the delay. Yes, this looks like a bug. To speed this up, > could you provide us with a code snippet that's running out of the > box? (I didn't manage to quickly reproduce the problem). > > Thanks, > Christian > > > On Sat, May 22, 2010 at 12:05 AM, <stefano at santoro.org> wrote: >> Hi, >> >> I am attempting to execute an XQJ prepared expression that uses an external bind variable that accepts an xml element, and inserts it into the database document: >> >> declare variable $inserto as element(*,xs:untyped) external; >> let $root := basex:db('Annotations')/Annotations >> return (insert node $inserto into $root) >> >> I prepare the above statement and I bind DOM element as follows (groovy syntax): >> >> eltype = conn.createElementType(null, XQItemType.XQBASETYPE_ANYTYPE); >> ixpr.bindNode(new QName("inserto"), irel, eltype); >> >> irel is dom element that serializes as follows: >> >> <inserto id="6"> >> <testo>six</testo> >> </inserto> >> >> unfortunately I get an NPE when I try to execute the Query: >> >> groovy:000> rs = ixpr.executeQuery() >> ERROR java.lang.NullPointerException: >> null >> at org.basex.query.item.FElem.copy (FElem.java:214) >> at org.basex.query.item.FElem.copy (FElem.java:1) >> at org.basex.query.item.FElem.copy (FElem.java:210) >> at org.basex.query.item.FElem.copy (FElem.java:1) >> at org.basex.query.expr.Constr.add (Constr.java:107) >> at org.basex.query.expr.Constr.<init> (Constr.java:53) >> at org.basex.query.up.Insert.atomic (Insert.java:60) >> at org.basex.query.up.Insert.atomic (Insert.java:1) >> at org.basex.query.expr.Expr.iter (Expr.java:53) >> at org.basex.query.QueryContext.iter (QueryContext.java:322) >> at org.basex.query.QueryContext.iter (QueryContext.java:290) >> at org.basex.api.xqj.BXQDynamicContext.execute (BXQDynamicContext.java:247) >> at org.basex.api.xqj.BXQPreparedExpression.executeQuery (BXQPreparedExpression.java:54) >> at groovysh_evaluate.run (groovysh_evaluate:10) >> ... >> >> I am using BaseX 6.1 >> >> Am I doing anything wrong? >> >> Stefano > ___________________________
SS
Thank you Christian it works well now.
Ciao
Stefano
Quoted text · Christian Grün · 14 lines
On Tue, May 25, 2010 at 5:22 PM, Christian Grün <christian.gruen at gmail.com> wrote: > Stefano, > > thanks for your Java class. I hope the problem is now fixed; please > have a look at our sources, or check out the latest versions from the > Maven repository: > > http://basex.org/maven/org/basex/basex/6.1.3/basex-6.1.3.jar > http://basex.org/maven/org/basex/basex-api/6.1.3/basex-api-6.1.3.jar > > Christian > >
Written for BaseX 6. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery