Hi,
I recently upgraded to BaseX 6.1. I now receive an error when running a query that run without complications in BaseX 6.0
The offending query has this prolog:
declare namespace libx='http://libx.org/xml/libx2'; declare namespace atom='http://www.w3.org/2005/Atom'; declare variable $metadata as xs:anyAtomicType := doc('libx2_meta')/metadata; declare variable $feed as xs:anyAtomicType := doc('libx2_feed')/feed;
which results in
*declare variable $metadata as xs:anyAtomicType := doc('libx2_meta')/metadata;* ^ javax.xml.xquery.XQQueryException: Stopped at line 3, column 48: [XQST0049] Duplicate definition of $metadata as xs:anyAtomicType. at org.basex.api.xqj.BXQDynamicContext.execute(BXQDynamicContext.java:251) at org.basex.api.xqj.BXQPreparedExpression.executeQuery(BXQPreparedExpression.java:54) at org.libx.libappdatabase.Query.main(Query.java:100)
Simply exchanging BaseX61.jar with BaseX6.jar makes this query work as expected. I note that if I switch lines 3 and 4 (so that the 'declare variable $feed' appears first), the error is flagged on this line.
The query runs fine using the command-client in both BaseX 6 and 6.1
I'm using org.basex.api.xqj.BXQDataSource, following by prepareExpression, followed by executeQuery. This query has no external variables.
Another point of information: out of curiosity, I printed information about the prepared expression after prepareExpression like so:
System.out.println("external vars: " + Arrays.asList(pe.getAllExternalVariables())); System.out.println("unbound vars: " + Arrays.asList(pe.getAllUnboundExternalVariables()));
this shows 'metadata' and 'feed' as external variables:
external vars: [metadata, feed] unbound vars: []
Why are 'metadata' listed as external, even though they are not declared as such?
I would appreciate any insight. If the problem is mysterious, I can prepare a self-contained test case or aid in debugging.
Thanks.
- Godmar
Godmar,
I recently upgraded to BaseX 6.1. I now receive an error when running a query that run without complications in BaseX 6.0 The offending query has this prolog: ...
Thanks for your detailed feedback. It would be great if you could provide us with a small Java snippet that demonstrates the problem and runs out-of-the-box; this might speed up debugging. Next, you could try your luck with the latest minor version of BaseX (the next official release is about to come soon):
http://www.inf.uni-konstanz.de/dbis/basex/maven/org/basex/basex/
Another point of information: out of curiosity, I printed information about the prepared expression after prepareExpression like so: System.out.println("external vars: " + Arrays.asList(pe.getAllExternalVariables()));
If I remember right, there is no clear distinction between external and global variables in BaseX. If the variables have not been assigned, however, they should be listed as unbound variables.
Feel free to ask for more, Christian
The problem persists in 6.1.9.
Here's a minimal test case:
http://top.cs.vt.edu/~gback/bx/Test.java
http://top.cs.vt.edu/~gback/bx/Test.java
import javax.xml.xquery.*;
public class Test { public static void main(String av[]) throws Exception { XQConnection conn = ((XQDataSource)Class.forName("org.basex.api.xqj.BXQDataSource"). newInstance()).getConnection();
XQPreparedExpression xqp = null; String q = "declare variable $x := 1; $x"; try { xqp = conn.prepareExpression(q); xqp.executeQuery(); } catch (XQQueryException xqex) { printXQException(xqex, q); } }
public static void printXQException (XQQueryException xquery, String query) { String [] lines = query.split("\n"); System.out.println(lines[Math.min(xquery.getLineNumber() - 1, lines.length - 1)]); System.out.println(" " .substring(0, xquery.getColumnNumber()) + "^"); System.out.println(xquery); } }
Hello all,
I could track the problem down to QueryProcessor.reset() not resetting the underlying Context instance. Demo:
//-------------------------------------------------------------------- import org.basex.core.Context; import org.basex.query.QueryProcessor;
public class Test2 {
public static void main(String[] args) throws Exception { final QueryProcessor qp = new QueryProcessor( "declare variable $x := 1; $x", new Context()); qp.parse(); // registers the variable $x with the Context qp.reset(); // sets 'parsed = false;' but doesn't reset the Context qp.parse(); // old definition is found, resulting in an exception }
} //--------------------------------------------------------------------
The problem appears in XQPreparedExpression because executeQuery() resets the internal QueryProcessor after the query has been parsed in the constructor.
Since I found no quick fix for this, I hope Christian or someone else with more BaseX-Fu than me can make use of my observations.
Cheers, Leo
Am 10.07.2010 23:43, schrieb Godmar Back:
The problem persists in 6.1.9.
Here's a minimal test case:
http://top.cs.vt.edu/~gback/bx/Test.java
http://top.cs.vt.edu/~gback/bx/Test.java
import javax.xml.xquery.*;
public class Test { public static void main(String av[]) throws Exception { XQConnection conn = ((XQDataSource)Class.forName("org.basex.api.xqj.BXQDataSource"). newInstance()).getConnection();
XQPreparedExpression xqp = null; String q = "declare variable $x := 1; $x"; try { xqp = conn.prepareExpression(q); xqp.executeQuery(); } catch (XQQueryException xqex) { printXQException(xqex, q); } } public static void printXQException (XQQueryException xquery, String query) { String [] lines = query.split("\n"); System.out.println(lines[Math.min(xquery.getLineNumber() - 1, lines.length - 1)]); System.out.println(" " .substring(0, xquery.getColumnNumber()) + "^"); System.out.println(xquery); }
}
BaseX-Talk mailing list BaseX-Talk@mailman.uni-konstanz.de https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk
Godmar,
thanks again for tracing the bug and isolating it in your Java code. As Leo annnounced, the query parsing process was reset, so that the query was parsed twice – an issue which resulted from an earlier XQJ bug fix.
It's even more surprising that the bug went unnoticed. It's not covered by the XQJ test suite either. We've fixed the bug and added some test cases; please have a look at the latest sources or the latest versions from the Maven repository:
http://www.inf.uni-konstanz.de/dbis/basex/maven/org/basex/basex/6.2/basex-6.... http://www.inf.uni-konstanz.de/dbis/basex/maven/org/basex/basex-api/6.2/base...
Best, Christian
On Sat, Jul 10, 2010 at 11:43 PM, Godmar Back godmar@gmail.com wrote:
The problem persists in 6.1.9. Here's a minimal test case: http://top.cs.vt.edu/~gback/bx/Test.java
import javax.xml.xquery.*;
public class Test { public static void main(String av[]) throws Exception { XQConnection conn = ((XQDataSource)Class.forName("org.basex.api.xqj.BXQDataSource"). newInstance()).getConnection();
XQPreparedExpression xqp = null; String q = "declare variable $x := 1; $x"; try { xqp = conn.prepareExpression(q); xqp.executeQuery(); } catch (XQQueryException xqex) { printXQException(xqex, q); } } public static void printXQException (XQQueryException xquery, String
query) { String [] lines = query.split("\n"); System.out.println(lines[Math.min(xquery.getLineNumber() - 1, lines.length - 1)]); System.out.println(" " .substring(0, xquery.getColumnNumber()) + "^"); System.out.println(xquery); } }
On Sun, Jul 11, 2010 at 7:53 AM, Christian Grün christian.gruen@gmail.comwrote:
It's even more surprising that the bug went unnoticed. It's not covered by the XQJ test suite either. We've fixed the bug and added some test cases; please have a look at the latest sources or the latest versions from the Maven repository:
http://www.inf.uni-konstanz.de/dbis/basex/maven/org/basex/basex/6.2/basex-6....
http://www.inf.uni-konstanz.de/dbis/basex/maven/org/basex/basex-api/6.2/base...
You appear to have changed the design of the jar files in a way that breaks my setup.
Notably, BaseX61-xqj.jar contains the javax.xml.xquery.* classes and the org/basex/api/xqj/BXQ* classes.
basex-api-6.2.jar contains a new version of the org.basex.api.xqj.BXQ* classes, but doesn't have the javax.xml.xquery.* classes.
Do I need to remove the BXQ* classes from BaseX61-xqj myself or is there an updated version of the *-xqj.jar file?
Thanks.
- Godmar
True, the XMLDB and XQJ interfaces are not included in our Maven repositories; instead, they are dynamically located by Maven itself. You'll find the interfaces e.g. at the following locations:
http://www.inf.uni-konstanz.de/dbis/basex/maven/javax/xml/xquery/xqj-api/1.0... http://www.inf.uni-konstanz.de/dbis/basex/maven/org/xmldb/xmldb-api/1.0/
Future versions of BaseX will as well use separated JAR files for the interfaces and implementations, as has already been done for the REST/JaxRx API.
Christian
You appear to have changed the design of the jar files in a way that breaks my setup. Notably, BaseX61-xqj.jar contains the javax.xml.xquery.* classes and the org/basex/api/xqj/BXQ* classes. basex-api-6.2.jar contains a new version of the org.basex.api.xqj.BXQ* classes, but doesn't have the javax.xml.xquery.* classes. Do I need to remove the BXQ* classes from BaseX61-xqj myself or is there an updated version of the *-xqj.jar file? Thanks. - Godmar
On Sun, Jul 11, 2010 at 11:28 AM, Christian Grün christian.gruen@gmail.comwrote:
True, the XMLDB and XQJ interfaces are not included in our Maven repositories; instead, they are dynamically located by Maven itself. You'll find the interfaces e.g. at the following locations:
http://www.inf.uni-konstanz.de/dbis/basex/maven/javax/xml/xquery/xqj-api/1.0... http://www.inf.uni-konstanz.de/dbis/basex/maven/org/xmldb/xmldb-api/1.0/
Confirmed working when I include basex-6.2, basex-api-6.2 and the xqj-api-1.0.jar file from above.
Thanks.
- Godmar
basex-talk@mailman.uni-konstanz.de